forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow_mapping.shader
55 lines (49 loc) · 1.32 KB
/
flow_mapping.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
53
54
55
//references:
//http://graphicsrunner.blogspot.com/2010/08/water-using-flow-maps.html
//https://mtnphil.wordpress.com/2012/08/25/water-flow-shader/
Shader "Flow mapping"
{
Properties
{
_MainTex ("Color Map", 2D) = "black" {}
_FlowMap ("Flow Map", 2D) = "black" {}
}
Subshader
{
Pass
{
CGPROGRAM
#pragma vertex vertex_shader
#pragma fragment pixel_shader
#pragma target 3.0
sampler2D _MainTex, _FlowMap;
uniform float FlowMapOffset0;
uniform float FlowMapOffset1;
struct structure
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
structure vertex_shader (float4 vertex:POSITION,float2 uv:TEXCOORD0)
{
structure vs;
vs.vertex = UnityObjectToClipPos (vertex);
vs.uv = uv;
return vs;
}
float4 pixel_shader (structure ps ) : SV_TARGET
{
float HalfCycle = 0.075;
float2 flowmap = tex2D( _FlowMap, ps.uv ).rg * 2.0f - 1.0f;
float phase0 = FlowMapOffset0;
float phase1 = FlowMapOffset1;
float3 A = tex2D(_MainTex, ps.uv + flowmap * phase0 );
float3 B = tex2D(_MainTex, ps.uv + flowmap * phase1 );
float flowLerp = ( abs( HalfCycle - FlowMapOffset0 ) / HalfCycle );
float3 offset = lerp( A, B, flowLerp );
return float4(offset,1.0);
}
ENDCG
}
}
}