Firstborn/Library/PackageCache/com.unity.render-pipelines..../Documentation~/rendering-to-a-render-textu...
Schaken-Mods 9092858a58 updated to the latest editor
I updated everything to the latest Unity Editor. Also realized I had the wrong shaders on my hairs, those are fixed and the hairs look MUCH better!
2023-05-07 17:43:11 -05:00

2.2 KiB
Raw Blame History

Rendering to a Render Texture

In the Universal Render Pipeline (URP), a Camera can render to the screen or to a Render Texture. Rendering to a screen is the default and is the most common use case, but rendering to a Render Texture allows you to create effects such as CCTV camera monitors.

If you have a Camera that is rendering to a Render Texture, you must have a second Camera that then renders that Render Texture to the screen. In URP, all Cameras that render to Render Textures perform their render loops before all Cameras that render to the screen. This ensures that the Render Textures are ready to render to the screen. For more information on Camera rendering order in URP, see Rendering order and overdraw.

Rendering to a Render Texture, and then rendering that Render Texture to the screen

Rendering to a Render Texture in URP

Create a Render Texture Asset in your Project using Assets > Create > Render Texture. Create a Quad in your Scene. Create a Material in your Project, and select it. In the Inspector, drag the Render Texture to the Material's Base Map field. In the Scene view, drag the Material on to the Quad. Create a Camera in your Scene. Its Render Mode defaults to Base, making it a Base Camera. Select the Base Camera. In the Inspector, scroll to the Output section. Set the Cameras Output Target to Texture, and drag the Render Texture on to the Texture field. Create another Camera in your Scene. Its Render Mode defaults to Base, making it a Base Camera. Place the Quad within the view of the new Base Camera.

The first Camera renders its view to the Render Texture. The second Camera renders the Scene including the Render Texture to the screen.

You can set the Output Target for a Camera in a script by setting the cameraOutput property of the Camera's Universal Additional Camera Data component, like this:

myUniversalAdditionalCameraData.cameraOutput = CameraOutput.Texture;
myCamera.targetTexture = myRenderTexture;