Skip to content

Commit d2ee8cf

Browse files
authored
Create Diffuse (2 Sided Light).shader
1 parent 91370d1 commit d2ee8cf

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
2+
// lights up sprites from both sides
3+
4+
Shader "Sprites/Diffuse (2 Sided Light)"
5+
{
6+
Properties
7+
{
8+
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
9+
_Color("Tint", Color) = (1,1,1,1)
10+
[MaterialToggle] PixelSnap("Pixel snap", Float) = 0
11+
[HideInInspector] _RendererColor("RendererColor", Color) = (1,1,1,1)
12+
[HideInInspector] _Flip("Flip", Vector) = (1,1,1,1)
13+
[PerRendererData] _AlphaTex("External Alpha", 2D) = "white" {}
14+
[PerRendererData] _EnableExternalAlpha("Enable External Alpha", Float) = 0
15+
}
16+
17+
SubShader
18+
{
19+
Tags
20+
{
21+
"Queue" = "Transparent"
22+
"IgnoreProjector" = "True"
23+
"RenderType" = "Transparent"
24+
"PreviewType" = "Plane"
25+
"CanUseSpriteAtlas" = "True"
26+
}
27+
28+
Cull Off
29+
Lighting Off
30+
ZWrite Off
31+
Blend One OneMinusSrcAlpha
32+
33+
CGPROGRAM
34+
//#pragma surface surf Lambert vertex:vert nofog nolightmap nodynlightmap keepalpha noinstancing
35+
#pragma surface surf TwoSidedLambert vertex:vert nofog nolightmap nodynlightmap keepalpha noinstancing
36+
#pragma multi_compile_local _ PIXELSNAP_ON
37+
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
38+
#include "UnitySprites.cginc"
39+
40+
struct Input
41+
{
42+
float2 uv_MainTex;
43+
fixed4 color;
44+
};
45+
46+
// added "abs" 2 sided lighting
47+
half4 LightingTwoSidedLambert(SurfaceOutput s, half3 lightDir, half atten) {
48+
half NdotL = abs(dot(s.Normal, lightDir));
49+
half4 c;
50+
c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten);
51+
c.a = s.Alpha;
52+
return c;
53+
}
54+
55+
void vert(inout appdata_full v, out Input o)
56+
{
57+
v.vertex = UnityFlipSprite(v.vertex, _Flip);
58+
59+
#if defined(PIXELSNAP_ON)
60+
v.vertex = UnityPixelSnap(v.vertex);
61+
#endif
62+
63+
//v.normal.z *= -1;
64+
65+
UNITY_INITIALIZE_OUTPUT(Input, o);
66+
o.color = v.color * _Color * _RendererColor;
67+
}
68+
69+
void surf(Input IN, inout SurfaceOutput o)
70+
{
71+
fixed4 c = SampleSpriteTexture(IN.uv_MainTex) * IN.color;
72+
o.Albedo = c.rgb * c.a;
73+
o.Alpha = c.a;
74+
}
75+
ENDCG
76+
}
77+
78+
Fallback "Transparent/VertexLit"
79+
}

0 commit comments

Comments
 (0)