/
DiffuseWorldUV.shader
58 lines (51 loc) · 1.06 KB
/
DiffuseWorldUV.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
Shader "Debug/DiffuseWorldUV"
{
Properties
{
_Wall ("Wall", 2D) = "white" {}
_Floor ("Floor", 2D) = "white" {}
_Frequency ("Frequency", float) = 1
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _Wall;
sampler2D _Floor;
float _Frequency;
struct Input
{
float2 uv_Wall;
float3 worldPos;
float3 worldNormal;
};
void surf (Input IN, inout SurfaceOutput o)
{
// Use abs() for bottom facing polygons
float2 UV;
if (IN.worldNormal.y > 0.5 || IN.worldNormal.y < -0.5)
{
UV = IN.worldPos.xz; // top
}
else if (abs(IN.worldNormal.x) > 0.5)
{
UV = IN.worldPos.yz; // side
}
else
{
UV = IN.worldPos.xy; // front
}
half4 c = float4(1, 1, 1, 1);
half4 wall = tex2D(_Wall, UV * _Frequency);
half4 floor = tex2D(_Floor, UV * _Frequency);
float s = step(IN.worldNormal.y, 0.5);
c = (wall * (s)) + (floor * 0.5 * (1 - s));
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}