Quantcast
Channel: Questions in topic: "shader programming"
Viewing all articles
Browse latest Browse all 169

Receiving Shadows On a Tranparent Shader

$
0
0
**In Unity 2020.1.3f1** I'm currently working on a small shader which takes the alpha component of a mesh's vertex colours and uses it for transparency, the result is a fade out along the edge of the shape: ![alt text][1] Fairly simple stuff, and works generally okay. The only noticable bug is that it doesn't receive shadows. ---------- Through a bit of reading, I know that it's possible to receive shadows on transparent shaders such as these and have seen working visual examples, but there's a lot of dubious information on the exact reason and resolution to this problem. The shader is as follows: Shader "Custom/StandardVertexAlpha" { Properties { _Color("Color", Color) = (1,1,1,1) _MainTex("Texture", 2D) = "white" {} _Emission("Emission", Color) = (0,0,0,0) } SubShader { Tags { "RenderType" = "Transparent" "Queue" = "AlphaTest"} Cull Off Lighting Off CGPROGRAM #pragma surface surf Lambert alpha:blend struct Input { float2 uv_MainTex; half4 color : COLOR; }; sampler2D _MainTex; fixed4 _Color; fixed4 _Emission; void surf(Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb * IN.color.rgb; o.Alpha = IN.color.a; o.Emission = _Emission; } float ShadowAttenuation(int index, float3 worldPos) { return 1.0; } float CascadedShadowAttenuation(float3 worldPos) { return 1.0; } ENDCG } Fallback "Diffuse" } The two methods "ShadowAttenuation" and "CascadedShadowAttenuation" are taken from an old Unity tutorial, but don't seem to function anymore. [1]: /storage/temp/186142-abtpxlg.jpeg

Viewing all articles
Browse latest Browse all 169

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>