-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathparallaxMap.shader
69 lines (60 loc) · 2.11 KB
/
parallaxMap.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Shader "LX/parallaxMap"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_NormalMap("Normal Map", 2D) = "bump" {}
_NormalScale("Normal Scale", Range( -8 , 8)) = 1
_ParallaxMap("Parallax Map", 2D) = "black" {}
_ParallaxScale("Parallax Scale", float) = 1
}
SubShader
{
Tags
{
"RenderType"="Opaque"
}
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
sampler2D _NormalMap;
float _NormalScale;
sampler2D _ParallaxMap;
float _ParallaxScale;
struct Input
{
float2 uv_MainTex;
float2 uv_NormalMap;
float3 viewDir;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
_ParallaxScale /= 100.0f;
//viewDir是切线空间的
float2 offset = (tex2D(_ParallaxMap, IN.uv_MainTex).r - 1) * IN.viewDir.xy * _ParallaxScale + IN.uv_MainTex;
float2 Offset1 = (tex2D(_ParallaxMap, offset).r - 1) * IN.viewDir.xy * _ParallaxScale + offset;
float2 Offset2 = (tex2D(_ParallaxMap, Offset1).r - 1) * IN.viewDir.xy * _ParallaxScale + Offset1;
float2 Offset3 = (tex2D(_ParallaxMap, Offset2).r - 1) * IN.viewDir.xy * _ParallaxScale + Offset2;
float2 uv = Offset3;
fixed4 c = tex2D(_MainTex, uv) * _Color;
fixed3 normal = UnpackNormal(tex2D(_NormalMap, uv));
normal.xy *= _NormalScale;
normal = normalize(normal);
o.Normal = normal;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}