- Home /
Having an Invisible Object that Casts Realtime Shadows.
In a scene, i need an invisible plane (or a box) to cast a realtime shadow. The best way to achieve that would probably be a shader. However, i have little to no experience with shaders, so i was wondering whether there already was a shader that can do this or alternatively what other approaches can have such an effect.
u can try Render Is False Then If u Have The Pro Unity $$anonymous$$ake The Shadow True In the Inspector of the direction Light i hope that helped
Certainly not, the shadow casting/receiving are inside the renderer. Turning the renderer off obviously makes the object unable to be rendered meaning it isn't included in the shadow calculations. I am also talking about realtime shadows, of course i am using Unity Pro.
Answer by manutoo · Sep 24, 2012 at 09:15 AM
EDIT for Unity 5: Now, you just have to change the Cast Shadows Mode to "Shadows Only" in the Mesh Renderer property of your gameobject.
...
Legacy solution for Unity 4:
I've seen this question asked many times, but no one gave any easy answer, although it exists..! I have been able to find it after reading a lot of forum posts and some experimentations, and here it goes :
1- add this shader in your project : (ie: copy/paste in a file named "InvisibleShadowCaster.shader" )
Shader "Transparent/InvisibleShadowCaster"
{
Subshader
{
UsePass "VertexLit/SHADOWCOLLECTOR"
UsePass "VertexLit/SHADOWCASTER"
}
Fallback off
}
2- create a new material, and set its shader to "Transparent/InvisibleShadowCaster"
3- assign that new material to your Invisible shadow caster object
4- Done
As there's only the shadow casting pass supported (1 for forward rendering & 1 for deferred rendering), you can be sure it doesn't take any extra resource, and it's easy to set it all up.
Here the result :
You can notice the shadow on the box under the plan, and on the bottom part of the sphere.
VertexLit/SHADOWCOLLECTOR doesn't seem to work anymore, turning my plane fuchsia. Once that was removed, it casted shadows, but it also blocked shadows. But a bit of tinkering and this works well with Unity 5:
Shader "Custom/InvisibleShadowCaster" { SubShader { Tags { "Queue"="Transparent" "RenderType"="Transparent" "IgnoreProjector"="True"} UsePass "VertexLit/SHADOWCASTER" } FallBack off }
Answer by DaveA · Jun 18, 2012 at 07:36 PM
One way is to have your invisible object not truly invisible, but with reversed normals. That is, normals that always point away from the camera. Try this to prove to yourself: Create two default Plane objects and a directional light. Rotate the light slightly and set to cast shadows. Pull one of the planes up a bit and you will see that it is casting shadow on the one below. Now rotate that plane around X axis so it's upside down. It's still casting a shadow, but you can't see it.
The word "normals" might be a bit confusing here, since in Unity, normals are used exclusively for lighting. The thing deter$$anonymous$$ing whether a face is front- or backfacing is exclusively the point order of the triangles in the mesh, and it can't even be changed with negatice scaling of the transform.
I seem to have solved my current issue with something similar, i would still like to know if there is a shader based solution to it however.
Answer by DeadBug · Jun 18, 2012 at 07:39 PM
make a new material go into the shader and select particle/additive and then tint the color of the material to black and it should make your game object (that you apply this material to) invisible and it should cast shadow since it doesnt affect your renderer :)
Particle/Additive as well as any Trnasparent shaders don't cast realtime shadows (at least not with Directional Lights and Forward Rendering).
I am pretty sure Particle/Additive does not cast realtime shadows in deferred rendering either.
Answer by gamer2300 · Jun 11, 2013 at 09:37 PM
ok i see a circle shadow under my camera..but i don't know where is invisible object that cast this image. I use ngui for a little gui, camra is the camera associated to ngui..and i see this enormous shadow under it. another prolem is that seems there is a sort f shadow poyected near object, so this modify the texture applied on object but this i see in part out of the circle shadow..