Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    6
    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:
    211
    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:
    6
    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:
    211
    Hmm... Did you use SetViewProjectionMatrices, or a virtual camera?
     
  5. Mariusz-Born7

    Mariusz-Born7

    Joined:
    Sep 4, 2015
    Posts:
    6
    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.
     
unityunity