Legacy Documentation: Version 2017.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Graphics.SetRenderTarget

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function SetRenderTarget(rt: RenderTexture): void;
public static void SetRenderTarget(RenderTexture rt);
public static function SetRenderTarget(rt: RenderTexture, mipLevel: int): void;
public static void SetRenderTarget(RenderTexture rt, int mipLevel);
public static function SetRenderTarget(rt: RenderTexture, mipLevel: int, face: CubemapFace): void;
public static void SetRenderTarget(RenderTexture rt, int mipLevel, CubemapFace face);
public static function SetRenderTarget(rt: RenderTexture, mipLevel: int, face: CubemapFace, depthSlice: int): void;
public static void SetRenderTarget(RenderTexture rt, int mipLevel, CubemapFace face, int depthSlice);
public static function SetRenderTarget(colorBuffer: RenderBuffer, depthBuffer: RenderBuffer): void;
public static void SetRenderTarget(RenderBuffer colorBuffer, RenderBuffer depthBuffer);
public static function SetRenderTarget(colorBuffers: RenderBuffer[], depthBuffer: RenderBuffer): void;
public static void SetRenderTarget(RenderBuffer[] colorBuffers, RenderBuffer depthBuffer);
public static function SetRenderTarget(colorBuffer: RenderBuffer, depthBuffer: RenderBuffer, mipLevel: int): void;
public static void SetRenderTarget(RenderBuffer colorBuffer, RenderBuffer depthBuffer, int mipLevel);
public static function SetRenderTarget(colorBuffer: RenderBuffer, depthBuffer: RenderBuffer, mipLevel: int, face: CubemapFace): void;
public static void SetRenderTarget(RenderBuffer colorBuffer, RenderBuffer depthBuffer, int mipLevel, CubemapFace face);
public static function SetRenderTarget(colorBuffer: RenderBuffer, depthBuffer: RenderBuffer, mipLevel: int, face: CubemapFace, depthSlice: int): void;
public static void SetRenderTarget(RenderBuffer colorBuffer, RenderBuffer depthBuffer, int mipLevel, CubemapFace face, int depthSlice);
public static function SetRenderTarget(setup: RenderTargetSetup): void;
public static void SetRenderTarget(RenderTargetSetup setup);

Parameters

rt RenderTexture to set as active render target.
mipLevel Mipmap level to render into (use 0 if not mipmapped).
face Cubemap face to render into (use Unknown if not a cubemap).
depthSlice Depth slice to render into (use 0 if not a 3D or 2DArray render target).
colorBuffer Color buffer to render into.
depthBuffer Depth buffer to render into.
colorBuffers Color buffers to render into (for multiple render target effects).
setup Full render target setup information.

Description

Sets current render target.

This function sets which RenderTexture 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 texture manually.

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

The function call with colorBuffers array enables techniques that use Multiple Render Targets (MRT), where fragment shader can output more than one final color.

Calling SetRenderTarget with just a RenderTexture argument is the same as setting RenderTexture.active property.

Note that in Linear color space, it is important to have the correct sRGB<->Linear color conversion state set. Depending on what was rendered previously, the current state might not be the one you expect. You should consider setting GL.sRGBWrite as you need it before doing SetRenderTarget or any other manual rendering.

See Also: RenderTexture, Graphics.activeColorBuffer, Graphics.activeDepthBuffer, SystemInfo.supportedRenderTargetCount.

Did you find this page useful? Please give it a rating: