luminance
Calculates the perceptually correct luminance (brightness) of an RGB color, automatically adapting to the project's current color space.
Core Advantages
Automatically uses the correct luminance coefficients for the project's configured color space, eliminating the need for manual weighted-average calculations or hard-coding, which greatly enhances physical accuracy and portability across color spaces.
Common Uses
Performing high-quality color-to-grayscale conversions.
Creating brightness masks for post-processing effects like Bloom to extract bright areas of the screen.
Calculating the Lightness (L) component in HSL/HSV color transformations for advanced color grading.
Driving other effects based on texture brightness, such as controlling the intensity of a displacement map.
How to adjust
Its output is primarily controlled by the input `color`. For advanced or artistic effects, you can override the default behavior by providing a custom `luminanceCoefficients` vector. For instance, passing `vec3(1, 0, 0)` will isolate the red channel, effectively creating a red filter effect on the resulting luminance value.
Code Examples
1// Create a mask for a bloom effect
2const luma = luminance( viewportTexture( uv ) );
3const bloomMask = step( threshold, luma ); // Isolate pixels brighter than the threshold