Hello, I am working on a project that uses clipping to create holes in geometry. I had some shadow artefacts (kind of faded geometry) using real time lighting but solved them by adding addshadow directive in the shader. The issue is that addshadow is removing artefacts but lighting is changing according to clipping. As an example, if there is a wall clipped, the wall shadow is not projected on the ground that is not clipped (It should). I want the lighting to stay the same even if the clipping region is changing. (It works pretty well with baked lights!) So, is it possible to clip shadows without using addshadow ? to clip the shadowmap ? Thanks in advance for your answers !
Could you include some screenshots of the problem? It might make it easier for us to understand the issue. Also, it would help to know which pipeline you're using (URP, HDRP, Built-In) - it sounds like you're using Built-In with surface shaders? Any sample code would also help.
Sure! Yes, I'm using surface shader with Built In pipeline. Here an example without addshadow : So, a lot of artefacts due to overlapped geometry. I tried dealing with layers but it did not fixed anything. Baked lights is the only solution for now. With addshadow : No artefacts anymore but lighting is affected by clipping. (that's an issue) For the shader code, it's a basic standard surface shader with clipping test (clip function), triplanar mapping, 1 color and 1 diffuse texture. Here the part with the "addshadow" : ... Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Standard fullforwardshadows addshadow ...
You want addshadow, but you'll want to try to detect in the shader if you're rendering a shadow map or the camera depth texture. The problem is in the built in rendering path the same "shadow pass" is used for both. Code (CSharp): Shader "Custom/NonClippedShadow" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Standard fullforwardshadows addshadow #pragma target 3.0 sampler2D _MainTex; struct Input { float2 uv_MainTex; }; fixed4 _Color; void surf (Input IN, inout SurfaceOutputStandard o) { // Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; #ifdef UNITY_PASS_SHADOWCASTER #ifdef SHADOWS_DEPTH if (unity_LightShadowBias.z != 0.0) return; // is shadow caster #endif #endif clip(IN.uv_MainTex.y * 2.0 - 1.0 + sin(_Time.y)); } ENDCG } FallBack "Diffuse" }
Hello bgolus It seems to work pretty well ! It is not perfect right now, but hope it will with some tweaking. Thanks a lot for your answer ! ( and all your other interesting posts on this forum )