Search Unity

Reusing shadowmaps

Discussion in 'General Graphics' started by kelloh, Nov 28, 2018.

  1. kelloh

    kelloh

    Joined:
    Mar 2, 2015
    Posts:
    29
    upload_2018-11-28_17-32-37.png

    I have a use case where I render a Camera multiple times (30+) to get many angles on an object, per frame.

    As my scene grew more complex, I'm needing to optimize*. One angle: it's wasteful to rerender shadowmaps for each Camera.Render() call.

    What I'd like to be able to do is reuse shadowmaps where it makes sense.

    I setup a Component attached to shadow casting lights that uses AddCommandBuffer(LightEvent.AfterShadowMap, cb) to grab the shadowmap after it's rendered and blit it into a RenderTexture. Great!

    The problem comes here, in what to do next before the second and subsequent Camera.Render() calls. My first approach was to set each light's light.shadows property to LightShadows.None, and then use AddCommandBuffer(LightEvent.AfterShadowMap, cb) to blit the texture back. But it looks like in the frame debugger that for the second and subsequent Camera.Render()s, the shadow collection pass isn't being run at all, so my blit-back command buffer doesn't get a chance to provide the already-baked shadowmap. This makes sense in any other context! A non-shadow-casting light shouldn't collect shadows.

    But in this particular case, I'd like it to run the shadow collection pass and hit my command buffer.

    Anyone have any ideas on how to accomplish what I'm after here?

    *More generally, this is part of a broader problem that Unity addressed for VR with single pass rendering--how to not get killed on draw calls when rendering multiple views of the same stuff. They solved it for 2 views. I just wish they had solved it for N :(
     
    Last edited: Nov 28, 2018
    grenappels likes this.
  2. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    Hi, did you ever figure this out? :)
     
  3. phil_lira

    phil_lira

    Unity Technologies

    Joined:
    Dec 17, 2014
    Posts:
    584
    You can do this with ScriptableRenderPipelines.