RENDERTARGETS
/* RENDERTARGETS: X,Y,Z */
Location: any fragment stage (.fsh) of any program
This directive is used to configure which color attachments a fragment program outputs to. Replace X,Y,Z
with the comma separated list of indices of color attachments. For example, putting /* RENDERTARGETS: 0,3,7,13 */
in composite.fsh
would configure that program to write to colortex0
, colortex3
, colortex7
, and colortex13
. The comment can be placed anywhere in the .fsh
file. If the directive (or the DRAWBUFFERS
directive) is not found in the file, the first 8 buffers will be bound in order.
Note: This directive must include the multi-line comments and should be on its own line.
The directive creates a map between the color attachment index used in the glsl code and the colortex or shadowcolor buffer. For example, if the line /* RENDERTARGETS: 0,3,7,13 */
is used, colortex0
would be at index 0 and colortex13
at index 3. There are three methods to access this output depending on the glsl version in use:
- Legacy versions and compatibility profiles have access to
gl_FragData[<index>]
, an array that can be written to with the attachment index like a standardvec4
array. In the above example writing togl_FragData[2]
would write tocolortex7
. - Modern versions (130+) can use the
out vec4 outColorN;
variable, whereN
is replaced with the array index. In the above example writing tooutColor2
would write tocolortex7
. - Newer modern versions (330+) can use layout qualifiers to specify the index, allowing the varible name to be changed. In the above example
layout(location = 2) out vec4 anArbitraryOutputName;
would write tocolortex7
.