is it possible to have a plane that can receive shadow, but everything else to be transparent
so only thing that would be visible is the shadow?
thanks!
is it possible to have a plane that can receive shadow, but everything else to be transparent
so only thing that would be visible is the shadow?
thanks!
any ideas?
are you saying the plane is invisible? like glass?
yes the plane should be transparent, just shadow to be visible (texture with alpha)
so are you having problems with the the transparent plane, or are you having problems with the shadow?
i know how to apply texture to the plane, and i know about how to make texture with alpha channel so i know how to fake the shadow.
what i was trying to figure out is how to get the real shadow from the light, and i know how to do that, the shadow shows on the plane, but
what i do not know is how to get only shadow on the plane, everything else to be transparent. only the portion of the plane that has shadow to show…
so i was thinking to have a camera that will render only shadow and then apply that texture to the plane…but how to do it?
am i thinking in the right direction?
any ideas?
probably use layers, set waht you want to show on one layer, and tell the camera not to see any of the other layers
I wrote a basic shader to accomplish this recently. Its not fully tested for all applications, pretty sure it wont work with Unity 3 deferred rendering, might not work with Unity 3 at all, essentially it works for my purposes in 2.6.
Copy and paste this code into a new text file and name it Transparent_ShadowSupport.shader then apply the shader to a material and apply the material to your plane.
Only ‘shadow’ cast from a directional light will be rendered on the plane, anywhere that is not shadowed will be transparent showing through anything behind it.
Oh and obviously the plane should be set to receive but not cast shadows.
// Transparent_ShadowSupport.shader
// Author: Noisecrime
// Date: 14.10.10
// Version 0.3
// Based on the Normal-Diffuse.shader
// INFO:
// Special FX shader that will only render a shadow onto the polygons, outside of the shadow area will be completely transparent.
// Shadow can be given a specific colour and alpha partly controls intensity, though mainly still controlled via light>shadow property.
// This is useful if you want to have a shadow on a ground plane, but not display the actual plane.
// Currently only works for Directional Lights.
// USAGE:
// Just apply the shader to a material.
// NOTES:
// Not tested with fog and may require tweaking to work with specific projects.
Shader "ncp/FX/Transparent_ShadowSupport" {
Properties
{
_Color ("Shadow Color", Color) = (1,1,1,1)
}
Category {
//Tags { "RenderType"="Opaque" }
// Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Tags { "RenderType"="Transparent" }
LOD 200
Zwrite Off
Blend SrcAlpha OneMinusSrcAlpha
Fog { Color [_AddFog] } // or Fog { Color (0,0,0,0) }
Lighting Off
// ------------------------------------------------------------------
// ARB fragment program
SubShader
{
// Pixel lights
Pass
{
Name "PPL"
Tags { "LightMode" = "Pixel" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_builtin
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct v2f {
V2F_POS_FOG;
LIGHTING_COORDS
};
uniform float4 _Color;
v2f vert (appdata_base v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
float4 frag (v2f i) : COLOR
{
half4 texcol = _Color*(1.0f-SHADOW_ATTENUATION(i));
return texcol;
}
ENDCG
}
}
}
Fallback "VertexLit", 2
}
works great! that is what i was searching for! i am using 2.6
Glad to hear it works for you.
Unfortunatelly it doesn’t work in Unity 3.1 pro.
I hope you also develop a Unity 3 compatipble version.
-Kaya
Yeah I developed this before I installed Unity 3, just after getting to grips with Unity 2.6 shaders. Haven’t had time to dig into the new shader stuff yet, though the basic concept should still work.
This is compatible with Unity 3.1, but only supports Forward Rendering.
Shader "TransparentShadowSupport" {
Properties
{
_ShadowColor ("Shadow Color", Color) = (0,0,0,1)
}
Category {
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off
Zwrite Off
LOD 200
SubShader
{
Tags { "RenderType"="Transparent" }
CGPROGRAM
#pragma surface surf Custom
struct Input {
float2 pos : POSITION;
};
uniform float4 _ShadowColor;
void surf(Input IN, inout SurfaceOutput o)
{
//Pass through shadow colour to lighting model
o.Albedo = _ShadowColor.rgb;
o.Alpha = _ShadowColor.a;
}
half4 LightingCustom(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half4 c;
//Inverse illumination - atten accounts for shadowing
c.rgb = s.Albedo.rgb * 1.0f-atten;
c.a = s.Alpha * 1.0f-atten;
return c;
}
ENDCG
}
}
Fallback "VertexLit", 2
}
The above shader doesn’t seem to work in Unity 3.5.
It appears to work in the editor, but when I switch to game view, it doesn’t display the shadow.
Is your game view using forward rendering?
Yes, changed it in the player settings, and even tried setting the camera directly to forward rendering, same result.
I’m going to try installing 3.4 to see if that helps.
Small bump. I was looking for the same thing, and found:
Which does exactly what I wanted, the specific shader that worked for me:
http://www.klakos.com/downloads/TransparentShadowReceiver/Transparent-Advanced-FullShadows.shader
I removed the texture/normal map code in the shader, as I just want shadows being placed on a transparent plane, to see how well it works in my outdoor AR demo ![]()
Thats exactly what I am looking for. I need a 100% transparent plane. Only the shadows of the objects that are placed on it shall be visible.
I just tried to use klakos shader, but I just receive a grey plane. I dont know how to turn it transparent.
Would you mind posting the shader you used?
That would be awesome!
I keep seeing this same site posted everywhere. Let me warn everyone who thinks this is the solution for shadows cast onto transparent objects – it does not work the way it appears. When using a plane with this shader on it, it appears to work as long as there’s another solid plane directly behind the transparent plane. The shadow is really being cast on the background plane and the shadows are showing THROUGH the transparent object. So as long as your transparent object is essentially a decal plane above another solid plane, it may work. But try the case below with a convex object:
See how you can see the shadows THROUGH the transparent plane? You’re actually seeing the shadows on the white background plane. No shadows are drawn on the contours of the mound of sand. You can even see the shadows that fall on the object sticking out of the mound through the sand.

Another angle shows there’s nothing being cast on the mound itself. You’re only seeing every shadow in the scene through it.
