Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can I find the target texture size in RenderPipeline.Render()?

Discussion in 'General Graphics' started by GoKman, Feb 26, 2023.

  1. GoKman

    GoKman

    Joined:
    Sep 25, 2017
    Posts:
    5
    Hi! As far as I understand (and I might be wrong) all cameras passed to "RenderPipeline.Render()" draws to the same texture identified by "BuiltinRenderTextureType.CameraTarget". How can I get it's size in pixels?
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    651
    The way I understand it (don't have a lot of experience with SRP), you can have multiple cameras in the scene that have different render target sizes. Those cameras are passed to Render as a parameter:

    protected override void Render(ScriptableRenderContext context, List<Camera> cameras)

    You can loop over those cameras and check Camera.targetTexture.width/height. If targetTexture is null, take Screen.width/height instead.

    So BuiltinRenderTextureType.CameraTarget is not always the same target. It is the target of the camera that is currently being rendered.
     
    GoKman likes this.