Garry's Mod Wiki

render.SetRenderTargetEx

  render.SetRenderTargetEx( number rtIndex, ITexture texture = nil )

Description

Sets the render target with the specified index of COLOR[n] to the specified rt, allowing you to work with Multiple Render Targets (MRT). Since standard shaders don't use MRT, you might find this useful at Shaders/screenspace_general.

MRT doesn't work with 2D render functions like render.DrawScreenQuad. Instead, you can render a render.DrawQuad using cam.Start2D.
If you try to render with MSAA and set the main RenderTarget with another RenderTarget, nothing will be rendered.

Link to Direct3D 9 documentation on MRT

Multiple render targets have the following restrictions:

  • No antialiasing is supported.

Arguments

1 number rtIndex
The index of output COLOR[n] semantics from pixel-shader. Min: 0, max: 3.
2 ITexture texture = nil
The new render target to be used.

Example

Multiple Render Targets in a 2D context:

local w, h = ScrW(), ScrH() local tex0 = GetRenderTarget( "ExampleRT0", w, h ) local tex1 = GetRenderTarget( "ExampleRT1", w, h ) local mat = Material("pp/ssao") -- your material with custom shader and COLOR0, COLOR1 output -- See https://github.com/meetric1/gmod_shader_guide/tree/main?tab=readme-ov-file#example-8---multi-render-targets for details local quad = { vector_origin, Vector(w, 0), Vector(w, h), Vector(0, h), } local function DrawScreenQuadMRT() cam.Start2D() cam.IgnoreZ( true ) render.DrawQuad( quad[1], quad[2], quad[3], quad[4] ) cam.IgnoreZ( false ) cam.End2D() end hook.Add( "RenderScreenspaceEffects", "2DMRT", function() render.SetRenderTargetEx(0, tex0) render.SetRenderTargetEx(1, tex1) render.SetMaterial(mat) DrawScreenQuadMRT() render.SetRenderTargetEx(1) render.SetRenderTargetEx(0) end )