hi guys... I am pretty new to shader writng but i am seting up a shader in which i have alpha blending with decal and a normal map But the problem is that i am not able to cast or recive any shadows from it this is where i dnt knw what to do nd how to do it i am stuck here plz help me out with this shader code given below Shader "AdditiveAlphaMask_decal_bump" { Properties { _MainColor ("Main Color", Color) = (1,1,1,1) _MainTex ("Main Alpha Texture", 2D) = "white" {} _AlphaMap ("Additional Alpha Map (Greyscale)", 2D) = "white" {} _DecalTex ("Decal (RGBA)", 2D) = "black" {} _BumpMap ("Normalmap", 2D) = "bump" {} } SubShader { Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} Blend SrcAlpha OneMinusSrcAlpha AlphaTest Greater .01 ColorMask RGB Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) } BindChannels { Bind "Color", color Bind "Vertex", vertex Bind "TexCoord", texcoord } LOD 200 CGPROGRAM #pragma surface surf Lambert sampler2D _MainTex; sampler2D _AlphaMap; sampler2D _DecalTex; sampler2D _BumpMap; half _Shininess; fixed4 _MainColor; struct Input { float2 uv_MainTex; float2 uv_AlphaMap; float2 uv_DecalTex; float2 uv_BumpMap; }; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_MainTex, IN.uv_MainTex) * _MainColor; half4 decal = tex2D(_DecalTex, IN.uv_DecalTex); c.rgb = lerp (c.rgb, decal.rgb, decal.a); o.Albedo = c.rgb* _MainColor.rgb; o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_AlphaMap).r; o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); } ENDCG } FallBack "Diffuse" } any help would b much appreciated thanks....!
In forawrd renderering path ,only direction light have shadow, In deferred rendering path,you can have varies shadows, but as afr as i know, transparent obj will be renderered after deferred rendering, in forward path, So....maybe that's the porblem
Are u saying that transparent obj cant cast shadows because i have checked it in Both Deferred and Forward rendering path but no success Plz suggest me what else i can do Or may b thier is a problem with the shader that i am missng
Yes, transparent objects do not cast shadows. They do not write to the ZBuffer and so cannot cast shadows. Only opaque and alpha test (rather than alpha blend - transparent - objects) objects can cast shadows.
thanks so much i m trying things buts its going no where what can i do to make my objects receive and cast shadows what should i add in my shader to achieve what i want and also tell me that how can i use a cutout in this shader with my decal property plz help..... i am really confuse
as far as i knw fallback is used when the shader didnt work properly and it falls back to the specified shader may b im wrong... so how can it help me with shadows
The eventual fallback of the fallback will contain the shadow caster/collector passes for the mesh. So it's helpful for shadows.
thank you fr ur suggestions i tested them but i am going no where with what i want nthing much happend can u guys plz show me what i can add or where i can add to make my object cast and recive shadows i tested fall backs but nothings happening i dnt understand what is the matter it dsnt work at all
Unfortunately, as far as I know, semi-transparent objects cannot cast or receive shadows properly. You can cast a shadow that is cutout or opaque, but not translucent. Receiving shadows requires writing to z buffer which breaks among other things rendering of overlapping semitransparent objects. Built-in transparent shaders don't cast or receive shadows as well. While not 100% Unity specific it would be nice if it was written somewhere in the docs so newcomers don't get biten by the fact (like I did). The fallback directive other than the fallback itself makes your shader inherit shadow caster and collector passes from the fallback one. Other ways than the fallback are addshadow directive, defining the passes manually or referencing passes from other shaders with UsePass. If you're OK with cutout shadows you can add this: Code (csharp): _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 and this inside the SubShader block: Code (csharp): UsePass "Transparent/Cutout/VertexLit/SHADOWCASTER" Hope that helps.
thank you cician but i want to blend in 2 alphas with a decal texture as shader state so when i m using the cout out property i have to use #pragma surface surf Lambert alphatest:_Cutoff insted of #pragma surface surf Lambert alpha so after doing it i can not blend the two alphas together because they tend to cutoff as stated in #pragma i can do that nd can make it recive/cast shadows but i want to do it in this perticular shader i understand that taranspernt object dsnt support shadows and that usepass trick dsnt work at all may b i m putting it in a wrong place but as u said i put it in a subshader block of my above given shader and it dsnt work so thank you for your ideas guys cheers