Log in or register to post comments

Using a Ground Plane with lights and shadows

April 10, 2018 - 11:29am #1

Greetings,

     I am trying to set up a scene using a ground plane, however, I would like to include lights and shadows to project onto the plane that I set my model on.  Has anyone successfully done this, or is it even possible using the ground plane?  I have seen examples with image targets, so any help would be appreciated. 

Some things that I have tried is setting up multiple cameras, depth masks, shaders on the plane object.  

Using a Ground Plane with lights and shadows

February 9, 2019 - 2:51am #4

@Mustavel how did you solve it? Does this work with Directional Light?

Using a Ground Plane with lights and shadows

April 10, 2018 - 8:18pm #3

Worked perfectly! Thanks for the shader.

Using a Ground Plane with lights and shadows

April 10, 2018 - 12:47pm #2

I assume you are using Unity and you want your plane to be transparent except the shadows and lights.  Here's a transparent shadow plane.  (set the color to black and alpha to zero for the material).  I don't have one off hand for lighting, but I've done it before so it is possible.  You'll have to do some hunting around for one.

 

Shader "Custom/TransparentShadowCollector"
{
    Properties
    {
        _Color ("Main Color", Color) = (1,1,1,.5)
        _ShadowIntensity ("Shadow Intensity", Range (0, 1)) = 0.6
    }

    SubShader
    {

        Tags {"Queue"="Geometry" }

        Pass
        {
            Tags {"LightMode" = "ForwardBase" }
            Cull Back
            Blend SrcAlpha OneMinusSrcAlpha
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fwdbase

            #include "UnityCG.cginc"
            #include "AutoLight.cginc"
            uniform fixed4  _Color;
            uniform float _ShadowIntensity;

            struct v2f
            {
                float4 pos : SV_POSITION;
                LIGHTING_COORDS(0,1)
            };
            v2f vert(appdata_base v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos (v.vertex);
                TRANSFER_VERTEX_TO_FRAGMENT(o);
            
                return o;
            }
            fixed4 frag(v2f i) : COLOR
            {
                float attenuation = LIGHT_ATTENUATION(i);

                return fixed4(0,0,0,(1-attenuation)*_ShadowIntensity) + _Color;
            }
            ENDCG
        }

    }
    Fallback "VertexLit"
}
Log in or register to post comments