Skip to content

ColorTex

uniform sampler2D colortexN;

layout (<format>) uniform image2D colorimgN;

There are 16 color attachments available through the colortex0 through colortex15 samplers. These samplers can be read from any program, and can be written to from the fragment stage of any begin, prepare, gbuffers, deferred, or composite program.

Writing

Any begin, prepare, gbuffers, deferred, or composite program can write to a colortex buffer, the buffers to write to can be selected with the RENDERTARGETS or DRAWBUFFERS directive.

Additionally, you can read and write to the first 6 colortex buffer in OptiFine or any colortex buffer in Iris using colorimgN where N is replaced with the colortex index. This is the only way to write to colortex buffers from compute shaders, but also works in any program. For more information on image load/store, see the Khronos Wiki.

Size

These buffers default to the display resolution, although this can be configured with the size.buffer define in shaders.properties. However, changing the buffer size will prevent any gbuffer program from writing to the texture.

Format / precision

These buffers all default to RGBA format (which is RGBA8 on most systems), but this can be configured as described in the Texture Formats section.

Clearing

By default, these buffers have each value cleared to vec4(0.0) after every frame. There are two execptions:

  • colortex0 clears to the fogColor with 1.0 alpha
  • colortex1 clears to vec4(1.0).

Each buffer can have its clearing disabled with the colortexNClear directive. Additionally, the clear color can be configured with the colortexNClearColor directive.

Flipping

Each colortex sampler actually contains two buffers, which allows you to read from and write to the same buffer in the same pass. The buffer flipping behavior can be controlled with the flip.<program>.<buffer> directive.

Aliases Legacy

The first 8 colortex buffers have legacy aliases, although their names are often confusing and their use is not recommended. Except as noted below, either name can be used interchangably. The names are as follows:

ColorTex nameLegacy name
colortex0gcolor
colortex1gdepth
colortex2gnormal
colortex3composite
colortex4gaux1
colortex5gaux2
colortex6gaux3
colortex7gaux4