티스토리 뷰

 유니티에서 기본적으로 제공하는 sprite diffuse 셰이더는 sprite 뒷면의 빛 계산을 하지 않습니다. 밑의 셰이더는 앞 뒤 어느 각도에도 같은 빛을 받는 셰이더 입니다.


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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Shader "Custom/BackLightDiffuse"
 {
     Properties
     {
         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
         _Color ("Tint", Color) = (1,1,1,1)
         _CutTex ("Cutout (A)", 2D) = "white" {}
         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
     }
 
     SubShader
     {
         Tags
         { 
             "Queue"="Transparent" 
             "IgnoreProjector"="True" 
             "RenderType"="Transparent" 
             "PreviewType"="Plane"
             "CanUseSpriteAtlas"="True"
         }
 
         Cull Off
         Lighting Off
         ZWrite Off
         Blend One OneMinusSrcAlpha
 
         CGPROGRAM
         #pragma surface surf PointLambert vertex:vert nofog keepalpha
         #pragma multi_compile _ PIXELSNAP_ON
         #pragma shader_feature ETC1_EXTERNAL_ALPHA
 
         sampler2D _MainTex;
         fixed4 _Color;
         sampler2D _AlphaTex;
         sampler2D _CutTex;
         float _Cutoff;
 
         half4 LightingPointLambert(SurfaceOutput s, half3 lightDir, half atten) {
             half4 c;
             c.rgb = s.Albedo * _LightColor0.rgb * atten;
             c.a = s.Alpha;
             return c;
         }
 
         struct Input
         {
             float2 uv_MainTex;
             fixed4 color;
         };
         
         void vert (inout appdata_full v, out Input o)
         {
             #if defined(PIXELSNAP_ON)
             v.vertex = UnityPixelSnap (v.vertex);
             #endif
             
             UNITY_INITIALIZE_OUTPUT(Input, o);
             o.color = v.color * _Color;
         }
 
         fixed4 SampleSpriteTexture (float2 uv)
         {
             fixed4 color = tex2D (_MainTex, uv);
 
 #if ETC1_EXTERNAL_ALPHA
             color.a = tex2D (_AlphaTex, uv).r;
 #endif //ETC1_EXTERNAL_ALPHA
 
             return color;
         }
 
         void surf (Input IN, inout SurfaceOutput o)
         {
             fixed4 c = tex2D(_MainTex, IN.uv_MainTex)  * IN.color;
             float ca = tex2D(_CutTex, IN.uv_MainTex).a;
             o.Albedo = c.rgb * c.a;
             if (ca > _Cutoff)
               o.Alpha = c.a;
             else
               o.Alpha = 0;
         }
         ENDCG
     }
 
 Fallback "Transparent/VertexLit"
 }
cs


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/02   »
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
글 보관함