View Full Version : How does blending (color vs alpha) work for single-channel render target?

11-08-2017, 09:37 AM
I'm porting some code from a technical paper, and they use a render target with only one channel - it's a 16-bit float buffer. But then they set blending operations on it like this:

How does blending work with regard to color and alpha if the target is only one components? With only one channel, does that mean that it defaults to only being an alpha channel?


11-08-2017, 10:33 AM
How is the render target texture created? And is this core or compatibility OpenGL? That will give you your answer.

To be more specific, typically a single-channel anything may be treated as if it were using the red channel. Legacy versions of the OpenGL specification do contain rules for conversion from the old GL_LUMINANCE and GL_LUMINANCE_ALPHA formats, whereas newer core GL versions require you to explicitly use e.g. GL_RED (i.e. GL_LUMINANCE and GL_LUMINANCE_ALPHA no longer exist). See e.g. page 128/table 3.15 of the OpenGL 1.5 specification: https://www.khronos.org/registry/OpenGL/specs/gl/glspec15.pdf, or for a core context check your glTexImage/glTexStorage call to determine which format is used.

Alfonse Reinheart
11-08-2017, 01:22 PM
LUMINANCE formats are not color-renderable, so you can't render to them. Even in compatibility OpenGL.

11-08-2017, 01:41 PM
Actually this is for Metal -- so maybe it is different from OpenGL? With Metal my fragment function does not return a full 4-component color but rather a single float value. And it seems like Metal interprets that as a color value, which means there would be no SRC_ALPHA for that blend function...?