renderRequest | All the necessary information to render a request, for example render destination, mipmap level, slice index, and so on. This information varies based on the RequestData type. |
Submits a render request to the camera outside of Unity render loop.
Call this method or RenderPipeline.SubmitRenderRequest to render outside of Unity render loop and output the render pipeline to the render destination specified in the RequestData
parameter. Before submitting the request, use RenderPipeline.SupportsRenderRequest to verify that the render pipeline supports the RequestData
type you have selected. The request is processed sequentially within your script, and no callback mechanism is involved.
The Universal Render Pipeline (URP) supports the following RequestData
types:
The High Definition Render Pipeline (HDRP) supports the following RequestData
types:
The Built-In Render Pipeline only supports the ObjectIdRequest request type.
For more information about how to render a render request in URP, refer to Create a Render Request in URP.
// This example sends render requests when the GUI button "Render Request" is selected. // To use it, attach the script to a camera and select Enter Play Mode.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering;
[RequireComponent(typeof(Camera))] public class StandardRenderRequest : MonoBehaviour { [SerializeField] RenderTexture texture2D, texture2DArray, cubeMap, texture3D;
// Create a button you can use to send a render request private void OnGUI() { GUILayout.BeginVertical(); if (GUILayout.Button("Render Request")) { SendRenderRequests(); } GUILayout.EndVertical(); }
// Send render requests outside of Unity render loop void SendRenderRequests() { Camera camera = GetComponent<Camera>();
// Create a standard request. This is supported only in HDRP and URP. RenderPipeline.StandardRequest request = new RenderPipeline.StandardRequest();
// Check if the request is supported by the render pipeline if (RenderPipeline.SupportsRenderRequest(camera, request)) { // Submit the render request to the render pipeline with different destination textures
// Render to a 2D texture request.destination = texture2D;
// Render the camera, and fill the 2D texture with its view camera.SubmitRenderRequest(request);
// Render to a 2D texture array request.destination = texture2DArray; for (int i = 0; i < texture2DArray.volumeDepth; i++) { request.slice = i; // Render the camera and fill slice i of the 2D texture array with its view camera.SubmitRenderRequest(request); }
// Render to a cubemap texture var faces = new[] { CubemapFace.NegativeX, CubemapFace.PositiveX, CubemapFace.NegativeY, CubemapFace.PositiveY, CubemapFace.NegativeZ, CubemapFace.PositiveZ }; request.destination = cubeMap; foreach (var face in faces) { request.face = face; // Render the camera and fill each face of the cubemap texture with its view camera.SubmitRenderRequest(request); }
// Render to a 3D texture request.destination = texture3D; for (int i = 0; i < texture3D.volumeDepth; i++) { request.slice = i; // Render the camera and fill slice i of the 3D texture with its view camera.SubmitRenderRequest(request); } } } }