Source browser
examples/shaders/luminance.cpp
Read the complete file below or download its original bytes. Line numbers provide stable links to a declaration or processing step.
File fingerprint
1// Linear RGB to Rec.709 luminance. Transfer-function decoding belongs upstream.
2#ifdef __cplusplus // Expose host declarations only when a C++ compiler reads this shader.
3#include "shdr.h" // Include shdr.h declarations.
4#endif // Finish this conditional compilation branch.
5layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; // Group 64 independent invocations along x.
6layout(std430, binding = 0) readonly buffer Colors { // Read normalized linear RGBA colors through buffer binding 0.
7 vec4 colors[]; // Store normalized linear RGBA colors.
8}; // Finish this declaration.
9layout(std430, binding = 1) writeonly buffer Gray { // Write one Rec.709 luminance value per pixel through buffer binding 1.
10 float gray[]; // Store one Rec.709 luminance value per pixel.
11}; // Finish this declaration.
12uniform uint count; // Limit work to the valid element count, including a partial final workgroup.
13void main() { // Convert one linear RGB color to Rec.709 luminance.
14 uint i = gl_GlobalInvocationID.x; // Select this invocation's global x coordinate.
15 if (i < count) // Ignore padding invocations in the final workgroup.
16 gray[i] = dot(colors[i].rgb, vec3(0.2126, 0.7152, 0.0722)); // Weight linear red, green and blue using the Rec.709 luminance coefficients.
17} // End this block.