Search Unity

Shadows Rendering Order in SRP

Discussion in 'Universal Render Pipeline' started by Mariusz-Born7, May 26, 2020.

  1. Mariusz-Born7

    Mariusz-Born7

    Joined:
    Sep 4, 2015
    Posts:
    40
    Hi, I am working on my custom render pipeline in SRP and I faced a problem with shadows rendering order. While calling SriptableRenderContext.DrawShadows() there is only one shader pass used with tag "LightMode"="ShadowCaster" but it ignores any kind of sorting including "Queue" tag. I have three different shaders which should be drawn in specific order while rendering shadows but I can't see a way to do it. While calling ScriptableRenderContext.DrawRenderers() there are SortingSettings and DrawingSettings but while rendering shadows there are no setting. Any help?
     
  2. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Use DrawRenderers() :). DrawShadows() is hugely restrictive, and sooner you go to drawrenderers then less problems later you get.
     
  3. Mariusz-Born7

    Mariusz-Born7

    Joined:
    Sep 4, 2015
    Posts:
    40
    I tried that. In general it works but it renders too many objects. I want to render only objects visible to the light being rendered from. Frame Debugger shows that way too many objects are rendered, because the clipping was performed from the camera view not from light view, so number of batches is insane. Do you know how to limit it?
     
  4. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    Hmm... Did you use SetViewProjectionMatrices, or a virtual camera?
     
  5. Mariusz-Born7

    Mariusz-Born7

    Joined:
    Sep 4, 2015
    Posts:
    40
    I am using standard cameras - scene camera in editor and other camera in game mode.

    What I do is:
    1. Render (ScriptableRenderContext context, Camera[] cameras)
    2. camera.TryGetCullingParameters()
    3. context.Cull()
    4. for each visible light SetViewProjectionMatrices and context.DrawShadows(). This works fine but there are no shadow drawing setting.
    5. finally context.DrawRenderers with shadows rendered in step 4

    If I replace DrawShadows with DrawRenderers in step 4, I can see that there are too many objects rendered (frame debug). Final image is fine so I know that all matrices are set correctly. What is more, this way Renderer.shadowCastingMode is ignored what is not acceptable. I have many mesh renderers set to Lighting->CastShadows->ShadowsOnly. It is messed up. So it looks that DrawRenderers is not designed to draw shadows.

    Am I doing something wrong? What do you mean by virtual camera? I was thinking about attaching cameras to lights but it sounds like a hack.
     
    unity_IpxdANggCs1roQ likes this.
  6. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    So, I actually tried this and while this worked (even with cascade rendering), the culling for DrawRenderers are very different from DrawShadows.

    Are you doing culling twice? How are you supposed to use ShadowSplitData or Bounds returned by CullResults API with DrawRenderers?
     
  7. Mariusz-Born7

    Mariusz-Born7

    Joined:
    Sep 4, 2015
    Posts:
    40
    Don't use DrawRenderers for shadow rendering. You fight against engine.