forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangles3.shader
42 lines (38 loc) · 1.09 KB
/
rectangles3.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//based on tutorial from http://theorangeduck.com/page/avoiding-shader-conditionals
Shader "Rectangles3"
{
Subshader
{
Pass
{
CGPROGRAM
#pragma vertex vertex_shader
#pragma fragment pixel_shader
#pragma target 2.0
struct custom_type
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
custom_type vertex_shader (float4 vertex : POSITION, float2 uv : TEXCOORD0)
{
custom_type vs;
vs.vertex = mul (UNITY_MATRIX_MVP,vertex);
vs.uv=uv;
return vs;
}
float4 pixel_shader (custom_type ps) : SV_TARGET
{
float x = ps.uv.x;
float y = ps.uv.y;
float2 center1 = float2(0.2,0.8);
float2 center2 = float2(0.5,0.8);
float2 center3 = float2(0.8,0.8);
return float4(1.0,0.0,0.0,1.0)*max(sign(0.1-abs(center1.x-x)),0.0)*max(sign(0.1-abs(center1.y-y)),0.0)
+float4(1.0,0.0,0.0,1.0)*max(sign(0.1-abs(center2.x-x)),0.0)*max(sign(0.1-abs(center2.y-y)),0.0)
+float4(1.0,0.0,0.0,1.0)*max(sign(0.1-abs(center3.x-x)),0.0)*max(sign(0.1-abs(center3.y-y)),0.0);
}
ENDCG
}
}
}