forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiagonal_transition.shader
52 lines (48 loc) · 1.19 KB
/
diagonal_transition.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
43
44
45
46
47
48
49
50
51
52
Shader "Diagonal transition"
{
Properties
{
[HideInInspector]
_MainTex ("Texture", 2D) = "black" {}
_Background ("Background", 2D) = "black" {}
}
Subshader
{
Pass
{
CGPROGRAM
#pragma vertex vertex_shader
#pragma fragment pixel_shader
#pragma target 2.0
sampler2D _MainTex,_Background;
float remap (float x, float a, float b, float c, float d)
{
return (x-a)/(b-a)*(d-c) + c;
}
float4 vertex_shader (float4 vertex:POSITION):SV_POSITION
{
return mul(UNITY_MATRIX_MVP,vertex);
}
float4 pixel_shader (float4 vertex:SV_POSITION):COLOR
{
vector <float,2> uv = vertex.xy/_ScreenParams.xy;
vector <float,2> uv2 = vertex.xy/_ScreenParams.xy;
uv2.y=1.0-uv2.y;
vector <float,4> a = tex2D(_MainTex,uv);
vector <float,4> b = tex2D(_Background,uv2);
float time = fmod(_Time.g,12.0);
if (fmod(floor((uv.y+(uv.x)*remap(cos(time),-1.0,1.0,0.0,2.0))*10.0),2.0)==0.0)
{
if (time<=6.0) return (uv.x<time*0.3) ? a:b;
else return (uv.x<(time-6.0)*0.3) ? b:a;
}
else
{
if (time<=6.0) return (1.0-uv.x<time*0.3) ? a:b;
else return (1.0-uv.x<(time-6.0)*0.3) ? b:a;
}
}
ENDCG
}
}
}