- Home /
Dynamic viewport for a camera rendering to a target texture?
I need to render a camera into a sub section of a target texture (the project I'm working on has multiple panels like a comic book and render using dynamically sized view ports). It used to be the cameras rect was relative to whatever it was rendering into, including target textures so this was easy. However in a recent version of unity this functionality was removed meaning now the camera rect is ignored when rendering to a target texture.
How come this was changed? And how can I get this working again? I'm pretty sure one call to GL.Viewport before rendering with the camera would achieve this but alas the viewport seems to get overwritten inside camera.Render(). Anybody had any luck with this?
Thanks!
Answer by LostInActon · Nov 09, 2016 at 08:28 AM
Giving this a poke.
Is there any way of rendering a camera into only part of a render target? When rendering to screen the camera rect allows you to draw to only a section of the screen but that functionaliy doesn't work for texture targets anymore.
Ok found a way of working around this if someone needs to. Camera.rect is ignored when rendering a camera with a targetTexture HOWEVER if you ins$$anonymous$$d call SetTargetBuffers() on the camera passing through the targetTexture's color and depth buffers just before calling camera.Render(), then the rect is used.
This feels very odd behaviour, I still dont know why Unity choose to change the functionality but at least there's a way round it.