forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clockwise_triangles.shader
39 lines (36 loc) · 1.14 KB
/
clockwise_triangles.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
Shader "Clockwise triangles"
{
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
{
float2 uv = ps.uv.xy;
float4 a =lerp(float4(1.0,1.0,1.0,1.0),float4(0.0,0.0,0.0,1.0),(step(step(uv.y,1.0-uv.x),step(uv.x,uv.y))));
float4 b =lerp(float4(1.0,1.0,1.0,1.0),float4(0.0,0.0,0.0,1.0),(step(step(uv.y,1.0-uv.x),step(uv.y,uv.x))));
float4 c =lerp(float4(1.0,1.0,1.0,1.0),float4(0.0,0.0,0.0,1.0),(step(step(1.0-uv.y,uv.x),step(uv.y,uv.x))));
float4 d =lerp(float4(1.0,1.0,1.0,1.0),float4(0.0,0.0,0.0,1.0),(step(step(1.0-uv.y,uv.x),step(uv.x,uv.y))));
float t = fmod(floor(_Time.g),4.0);
return float4 (a *(1.0-abs(sign(t-0.0)))+ b*(1.0-abs(sign(t-1.0)))+c*(1.0-abs(sign(t-2.0)))+d*(1.0-abs(sign(t-3.0))));
}
ENDCG
}
}
}