Skip to content

Commit

Permalink
Support for extracting bloom highlights with luminance >1 (#12636)
Browse files Browse the repository at this point in the history
  • Loading branch information
kircher1 committed Jun 7, 2022
1 parent 205ee04 commit e2b48da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Expand Up @@ -3,6 +3,8 @@ const float HALF_MIN = 5.96046448e-08; // Smallest positive half.

const float LinearEncodePowerApprox = 2.2;
const float GammaEncodePowerApprox = 1.0 / LinearEncodePowerApprox;

// The luminance weights used below are for a linear encoded color, not a gamma-corrected color.
const vec3 LuminanceEncodeApprox = vec3(0.2126, 0.7152, 0.0722);

const float Epsilon = 0.0000001;
Expand Down Expand Up @@ -88,6 +90,7 @@ float pow5(float value) {
return sq * sq * value;
}

// Returns the saturated luminance. Assumes input color is linear encoded, not gamma-corrected.
float getLuminance(vec3 color)
{
return clamp(dot(color, LuminanceEncodeApprox), 0., 1.);
Expand Down
Expand Up @@ -12,6 +12,6 @@ uniform float exposure;
void main(void)
{
gl_FragColor = texture2D(textureSampler, vUV);
float luma = getLuminance(gl_FragColor.rgb * exposure);
float luma = dot(LuminanceEncodeApprox, gl_FragColor.rgb * exposure);
gl_FragColor.rgb = step(threshold, luma) * gl_FragColor.rgb;
}

0 comments on commit e2b48da

Please sign in to comment.