- Home /
how to make a shader that only shows the shadow while the rest becomes completly transparent?
Hi Everyone,
I would like to build a material that only catch shadows, for 3dsmax users this refers to the matte/shadow material.
Basically, the material is plain transparent and simply catch shadows. It might be already feasible, but I lack of experience with writing shaders...
Also, if that could work with projectors, that would be great :)
Thanks for your help,
Jean
Extra brownie points to you for revealing finally how to do something in $$anonymous$$ax that I've often needed, always thought possible, but never figured out how to do. I only wish I could answer this in return, but I don't know enough about shaders to be much help.
:) I am sure it is possible, but requires I think some real shader scripting knowledge.
Ok, Started a bounty, I am sure this one is a no brainer for some shader guru, just needs that extra rewards I guess :) thanks in advance!
Could you confirm what sort of shadows you want it to catch? I have a solution for this that works with shadows created with a projector.
Answer by Peter G · Feb 21, 2011 at 04:02 PM
I think this is what you want?
http://forum.unity3d.com/threads/14438-Matte-Shadow?highlight=matte+shadow
haven't found yet a shader that works in these threads. $$anonymous$$atteShadowCust$$anonymous$$odel just show or cut everything, and $$anonymous$$atteShadowCust$$anonymous$$odel2 just don't show any shadow anymore. the matte shadow one seemed working, but for unity 2.x only. matShadow doesn't work neither. sigh...
hi...None of the shaders in this thread worked for me. Did u get a solution? if yes, your help would be much appreciated
Answer by taoa · Feb 21, 2011 at 09:27 AM
After (properly this time) reading your answer, I can tell you this:
What is a shadow in Unity? It's an area on an object where light don't shine because it's hidden from it by another object (that's true in real life as well actually).
In other words: a shadow, on a rendered 3D object, is a bunch of pixels where the influence (lighting calculation) of a light is removed, leaving only the ambient lighting (that colour you set in Render Settings).
OK.
Wait. What does that mean for an object that is invisible? There's no light calculation in the first place! Hey, there's not even any ambient lighting at all! How could an invisible object possibly receive and display any kind of shadow at all?
Impossible. Apparently.
It's technically possible though, as one would only have to consider 'OK so, this object's shader doesn't render anything, but where shadows would be if it was visible, I'm gonna use it's base colour/texture and multiply that with the ambient lighting colour and it's gonna be the shadow. I'll also add a transparency factor 'cause it'll be fun to play with that.'
That's how one would do it... if it was possible. Unfortunately shadows calculations are done behind-the-scenes in Unity and an End-User like you or me can't access these in order to play a bit with them.
So, I'd say this is impossible. I'd like to be wrong though.
hi, thanks for the explanations. $$anonymous$$atte composition is a very important feature of 3d rendering. I remain persuaded ( also feel the same about how theoritically it would work) that it is possible, hopefully someone from Unity or from "planet shader guru" will read this post and know the answer, I will open a forum question as well, cause it seems to be moving into a discussion more than a question/answer type of thing.
Answer by genedegsg · Jul 12, 2017 at 04:41 PM
I know this is a necro thread and people may well flame me for replying, but I was never able to find an answer to this question anywhere else in the forum. My guess is that I'm not alone. So I wanted to link to an article that gives the full listing for a shader that will do exactly this. It also supports bump, specular, and gloss maps, opacity maps and thresholds for hair, or any other purposes that require tapering toward transparency: http://www.dawnofthefel.com/blogs/game-coding/its-all-hollywoods-fault . To make something fully transparent but still cast shadows, just set _Color's Alpha channel value to 0.
A good portion of the reason I wanted to post this is because one of the prior answers was fairly snarky in its assertion that this couldn't be done. It was also incorrect. (FWIW, being snarky when someone asks an honest question never seems warranted to me.)
I don't $$anonymous$$d necros (obviously) but that wasn't the question. OP was looking for a shader that is visible only where it receives shadow-- not a transparent object that casts shadows. That functionality is already built in to Unity.
So, still looking for a solution.
Answer by MahrCheen · Mar 29, 2018 at 08:24 AM
This thing works in the viewport for me- it lacks something like clearing in game mode. I don't know how to fix it.
Shader "UnlitShadows/ShadowCatcher" {
Properties{ _Color("Main Color", Color) = (1,1,1,1) _MainTex("Base (RGB)", 2D) = "white" {} _Cutoff("Cutout", Range(0,1)) = 0.5 }
SubShader{ Pass{ Alphatest Greater[_Cutoff] SetTexture[_MainTex] } Pass{ Blend DstColor Zero Tags{ "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#include "AutoLight.cginc"
struct v2f {
float4 pos : SV_POSITION; LIGHTING_COORDS(0,1) };
v2f vert(appdata_base v) {
v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); TRANSFER_VERTEX_TO_FRAGMENT(o);
return o; }
fixed4 frag(v2f i) : COLOR{
float attenuation = LIGHT_ATTENUATION(i);
return attenuation;
} ENDCG } } Fallback "Transparent/Cutout/VertexLit" }
Your answer
Follow this Question
Related Questions
Transparent objects and shadow 0 Answers
Shadows with Transparent Standard Shader? 2 Answers
Semitransparent object that cast shadow 0 Answers
blob shadow z-fighting on iphone 3 Answers
Need help with projector shader 0 Answers