Version: 2023.2

Graphics.SetRenderTarget

切换到手册
public static void SetRenderTarget (RenderTexture rt, int mipLevel= 0, CubemapFace face= CubemapFace.Unknown, int depthSlice= 0);
public static void SetRenderTarget (Rendering.GraphicsTexture rt, int mipLevel= 0, CubemapFace face= CubemapFace.Unknown, int depthSlice= 0);
public static void SetRenderTarget (RenderBuffer[] colorBuffers, RenderBuffer depthBuffer);
public static void SetRenderTarget (RenderBuffer colorBuffer, RenderBuffer depthBuffer, int mipLevel= 0, CubemapFace face= CubemapFace.Unknown, int depthSlice= 0);
public static void SetRenderTarget (RenderTargetSetup setup);

参数

rt RenderTexture or GraphicsTexture to set as active render target.
mipLevel 要渲染到的 Mipmap 级别(如果不是 Mipmap,则使用 0)。
face 要渲染到的立方体贴图面(如果不是立方体贴图,则使用 Unknown)。
depthSlice 要渲染到的深度切片(如果不是 3D 或 2DArray 渲染目标,则使用 0)。
colorBuffer 要渲染到的颜色缓冲区。
depthBuffer 要渲染到的深度缓冲区。
colorBuffers 要渲染到的颜色缓冲区(用于多个渲染目标效果)。
setup 完整渲染目标设置信息。

描述

设置当前渲染目标。

This function sets which RenderTexture, GraphicsTexture, or a RenderBuffer combination will be rendered into next. Use it when implementing custom rendering algorithms, where you need to render something into a render target texture manually.

Variants with mipLevel and face arguments enable rendering into a specific mipmap level of a texture, or specific cubemap face of a cubemap RenderTexture/GraphicsTexture. Variants with depthSlice allow rendering into a specific slice of a 3D or 2DArray render texture.

使用 colorBuffers 数组的函数调用启用了使用 多渲染目标 (MRT) 的技术,其中片元着色器可以输出多种 最终颜色。

Calling SetRenderTarget with just a RenderTexture or GraphicsTexture argument is the same as setting the RenderTexture.active and GraphicsTexture.active property. To set a GraphicsTexture as the render target, it must have GraphicsTextureDescFlags.RenderTarget enabled in GraphicsTexture.descriptor.flags.

请注意,在线性颜色空间中,设置正确的 sRGB<-> 线性颜色转换 状态非常重要。受之前渲染的内容的影响,当前状态可能不是您预期的状态。 您应考虑在执行 SetRenderTarget 或任何其他手动渲染之前,将 GL.sRGBWrite 设置为 需要的值。

Additional resources: RenderTexture, GraphicsTexture, Graphics.activeColorBuffer, Graphics.activeDepthBuffer, SystemInfo.supportedRenderTargetCount.