Search Unity

I have the strangest clipped-off-shadows cast from out-of-frustum objects right now..

Discussion in 'Shaders' started by metaleap, May 29, 2014.

  1. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    I'm posting this in the ShaderLab forum because everything rendered in my scene is done so with handmade shaders written from scatch :D So everything is Cg vert/frag (no SS) lit via a custom-coded Deferred pipeline.

    So overall shadow casting and collecting and sampling works super neatly! No probs. Except just now after more than a week I'm actually noticing weird clipping-off of shadows cast by objects as they just-about-drop-out-of-frustum. And now I'm wondering if any of you fellow ShaderLab hacks have ever run into this before. Not even suspecting my shaders to be at fault, but hey one can ask around.

    So first off, here's a normal shadow cast-and-collected correctly by a big sphere intersecting a bigger box:



    All very nice. Now I turn left just a little so the big sphere is leaving the frustum to the right. As it does, I'm now seeing the following weird clipped-off shadow:



    This is happening with all my various test geometry (only primitives for now) as soon as they have just left the frustum. They all have static-batching applied, but the same happens without any batching.

    OK so the shaders used for 3D geometry materials all have the bog-standard shadow passes, no custom stuff going on, all plain-jane stuff:

    Code (csharp):
    1.  
    2. #ifdef UNITY_PASS_SHADOWCOLLECTOR
    3. struct v2f_surf {
    4.     V2F_SHADOW_COLLECTOR;
    5. };
    6.  
    7. inline v2f_surf vert_surf(const in appdata_img v) {
    8.     v2f_surf o;
    9.     TRANSFER_SHADOW_COLLECTOR(o)
    10.     return o;
    11. }
    12.  
    13. inline half4 frag_surf(v2f_surf IN) : COLOR {
    14.     SHADOW_COLLECTOR_FRAGMENT(IN)
    15. }
    16. #endif
    17.  
    18. #ifdef UNITY_PASS_SHADOWCASTER
    19. struct v2f_surf {
    20.     V2F_SHADOW_CASTER;
    21. };
    22.  
    23. inline v2f_surf vert_surf(const in appdata_img v) {
    24.     v2f_surf o;
    25.     TRANSFER_SHADOW_CASTER(o)
    26.     return o;
    27. }
    28.  
    29. inline half4 frag_surf(const in v2f_surf IN) : COLOR {
    30.     SHADOW_CASTER_FRAGMENT(IN)
    31. }
    32. #endif
    33.  
    In post-process, I can super easily sample the shadow-map in screenspace, as you see in the first shot it basically works as expected too:

    Code (csharp):
    1.  
    2. #define SHADOWS_SCREEN 1
    3.  
    4. // unityCG etc. includes and other code goes here, then at some point sample the shadow-map:
    5.  
    6. myDirLight.a = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, half3(i.uv, myFragDepthIguessOrWhateverThisArgumentSeemsToBeIgnored));
    7.  
    8. // this above resulting value is later used like atten in typical lighting functions
    9.  
    What could cause the shadow clipping?

    Bias is 0.1 so nothing very extreme, Quality settings are all upped to the max (soft shadows, distance=256, very high res, stable fit, 4 cascades), main camera has near-plane 0.48, field-of-view 45, far-plane 1544.

    It truly boggles the mind!
     
    Last edited: May 29, 2014