Search Unity

Choosing when to update render textures

Discussion in 'General Graphics' started by perholmes, Jul 5, 2022.

  1. perholmes

    perholmes

    Joined:
    Dec 29, 2017
    Posts:
    296
    Hi,

    I'm using render textures to capture things like height maps from an orthographic camera high above the scene. The render texture rarely needs to be updated, and it doesn't make sense to render it on every frame. It only needs to run when certain objects have been moved.

    What is the best way to programmatically decide when these render textures are captured?

    It works to disable the cameras and then enable them for one frame. It doesn't work to unlink the render textures from the cameras and only briefly link them.

    Is this the most kosher way? Or is there a way to tell a camera to capture now? Or is "now" not a thing anyway, since it's the GPU doing the capturing?
     
  2. georgerh

    georgerh

    Joined:
    Feb 28, 2020
    Posts:
    72
    I'm using a command buffer and Graphics.ExecuteCommandBuffer to do the same thing (top-down view for snow coverage). But enabling/disabling a camera for a single frame should work too.
     
  3. perholmes

    perholmes

    Joined:
    Dec 29, 2017
    Posts:
    296
    Those are great ideas, thanks! Especially with the snow coverage. For everything I'm doing with filming overridden versions of the scene from above to extract information shaders can access, I completely missed using this for snow coverage, that's a terrific idea that I can have in 5 lines of shader code. Super thanks!
     
    georgerh likes this.