Skip to content

Commit 9039d6f

Browse files
Useful for materials such as cloth or vegetation.
1 parent 8504a00 commit 9039d6f

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Diff for: transmission.shader

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//Shader controls how much light is passed through object when the light source is behind the surface currently being rendered.
2+
//This can be useful for materials such as cloth or vegetation.
3+
4+
Shader "Transmission"
5+
{
6+
Properties
7+
{
8+
_MainTex ("Diffuse map", 2D) = "white" {}
9+
_Range ("Range", Range(0, 3)) = 1
10+
}
11+
SubShader
12+
{
13+
Cull Off
14+
Tags {"RenderType"="Opaque"}
15+
Pass
16+
{
17+
Tags {"LightMode"="ForwardBase"}
18+
CGPROGRAM
19+
#pragma vertex vertex_shader
20+
#pragma fragment pixel_shader
21+
#pragma target 3.0
22+
23+
float4 _LightColor0, _MainTex_ST;
24+
sampler2D _MainTex;
25+
float _Range;
26+
27+
struct structure
28+
{
29+
float4 vertex : SV_POSITION;
30+
float2 uv : TEXCOORD0;
31+
float3 normal : TEXCOORD1;
32+
};
33+
34+
structure vertex_shader (float4 vertex:POSITION,float3 normal:NORMAL,float2 uv:TEXCOORD0)
35+
{
36+
structure vs;
37+
vs.vertex = UnityObjectToClipPos( vertex );
38+
vs.normal = normalize(mul(unity_ObjectToWorld,normal));
39+
vs.uv = uv;
40+
return vs;
41+
}
42+
43+
float4 pixel_shader(structure ps) : COLOR
44+
{
45+
float3 AmbientLight = UNITY_LIGHTMODEL_AMBIENT.rgb;
46+
float3 NormalDirection = ps.normal;
47+
float3 LightDirection = normalize(_WorldSpaceLightPos0.xyz);
48+
float3 LightColor = _LightColor0.rgb;
49+
float NdotL = dot( NormalDirection, LightDirection );
50+
float3 ForwardLight = max(0.0, NdotL);
51+
float3 BackLight = max(0.0, -NdotL ) * float3(_Range,_Range,_Range);
52+
float3 DiffuseColor = (ForwardLight+BackLight) * LightColor + AmbientLight;
53+
float3 DiffuseMap = tex2D(_MainTex,ps.uv*_MainTex_ST.xy+_MainTex_ST.zw).rgb;
54+
return float4(DiffuseColor*DiffuseMap,1.0);
55+
}
56+
ENDCG
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)