-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexNormalAtlas.shader
67 lines (56 loc) · 1.42 KB
/
TexNormalAtlas.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
Shader "Custom/TexNormalAtlas"
{
Properties{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Texture", 2D) = "white" {}
_BumpMap("Bumpmap", 2D) = "bump" {}
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf WrapLambert
#pragma vertex vert
#pragma target 3.0
sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
half4 LightingWrapLambert(SurfaceOutput s, half3 lightDir, half atten)
{
half NdotL = dot(s.Normal, lightDir);
half diff = NdotL * 0.5 + 0.5;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten);
c.a = s.Alpha;
return c;
}
struct Input
{
float3 position;
float4 custom_uv;
};
int _AtlasX;
int _AtlasY;
fixed4 _AtlasRec;
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
o.custom_uv = v.texcoord;
o.position = v.vertex;
}
void surf(Input IN, inout SurfaceOutput o) {
fixed2 atlasOffset = IN.custom_uv.zw;
fixed2 scaledUV = IN.custom_uv.xy;
fixed2 atlasUV = scaledUV;
atlasUV.x = (atlasOffset.x * _AtlasRec.x) + frac(atlasUV.x) * _AtlasRec.x;
atlasUV.y = (((_AtlasY - 1) - atlasOffset.y) * _AtlasRec.y) + frac(atlasUV.y) * _AtlasRec.y;
fixed4 c = tex2D(_MainTex, atlasUV) * _Color;
o.Normal = UnpackNormal(tex2D(_BumpMap, atlasUV));
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Diffuse"
}