Browse Source

renamed luminance function (#24347)

WestLangley 3 years ago
parent
commit
3ef8abb9da

+ 1 - 1
examples/jsm/shaders/LuminosityShader.js

@@ -35,7 +35,7 @@ const LuminosityShader = {
 
 			vec4 texel = texture2D( tDiffuse, vUv );
 
-			float l = linearToRelativeLuminance( texel.rgb );
+			float l = luminance( texel.rgb );
 
 			gl_FragColor = vec4( l, l, l, texel.w );
 

+ 1 - 1
examples/jsm/shaders/ToneMapShader.js

@@ -51,7 +51,7 @@ const ToneMapShader = {
 			#endif
 
 			// Calculate the luminance of the current pixel
-			float fLumPixel = linearToRelativeLuminance( vColor );
+			float fLumPixel = luminance( vColor );
 
 			// Apply the modified operator (Eq. 4)
 			float fLumScaled = (fLumPixel * middleGrey) / max( minLuminance, fLumAvg );

+ 6 - 5
src/renderers/shaders/ShaderChunk/common.glsl.js

@@ -17,7 +17,7 @@ vec3 pow2( const in vec3 x ) { return x*x; }
 float pow3( const in float x ) { return x*x*x; }
 float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
 float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
-float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
+float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
 
 // expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.
 // do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
@@ -88,12 +88,13 @@ mat3 transposeMat3( const in mat3 m ) {
 
 }
 
-// https://en.wikipedia.org/wiki/Relative_luminance
-float linearToRelativeLuminance( const in vec3 color ) {
+float luminance( const in vec3 rgb ) {
 
-	vec3 weights = vec3( 0.2126, 0.7152, 0.0722 );
+	// assumes rgb is in linear color space with sRGB primaries and D65 white point
 
-	return dot( weights, color.rgb );
+	const vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 );
+
+	return dot( weights, rgb );
 
 }