Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Directional Planar Overhead Shadow" {
- Properties {
- _Color ("Color", Color) = (0,0,0,0)
- _GroundHeight ("Ground Height", Float) = 0
- }
- SubShader {
- Tags { "RenderType" = "Opaque" }
- Offset -1.0, -2.0
- CGPROGRAM
- #pragma surface surf Lambert vertex:vert noambient nolightmap noforwardadd approxview halfasview exclude_path:prepass
- struct Input {
- float2 uv_MainTex;
- };
- float4 _Color;
- float _GroundHeight;
- float4 _LightDirection;
- float4x4 _WorldToReceiver;
- void vert (inout appdata_full v) {
- // transform into worldspace
- float4 world_space_vertex = mul( _Object2World, v.vertex );
- float4 lightDirection = _LightDirection;
- float4 world2ReceiverRow1 = float4(_WorldToReceiver[0][1], _WorldToReceiver[1][1], _WorldToReceiver[2][1], _WorldToReceiver[3][1]);
- float distanceOfVertex = dot(world2ReceiverRow1, world_space_vertex);
- float lengthOfLightDirectionInY = dot(world2ReceiverRow1, lightDirection);
- if (distanceOfVertex > 0.0 && lengthOfLightDirectionInY < 0.0)
- {
- lightDirection = lightDirection * (distanceOfVertex / (-lengthOfLightDirectionInY));
- }
- else
- {
- // we don't move vertex if below plane, or if light is directed upwards
- lightDirection = float4(0.0, 0.0, 0.0, 0.0);
- }
- world_space_vertex += lightDirection;
- // transform back into local space
- v.vertex = mul( _World2Object, world_space_vertex );
- }
- void surf (Input IN, inout SurfaceOutput o) {
- o.Albedo = _Color;
- }
- ENDCG
- }
- Fallback "Diffuse"
- }
Add Comment
Please, Sign In to add comment