Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLRenderer: Remove gammaFactor and GammaEncoding. #23080

Merged
merged 1 commit into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/api/en/constants/Textures.html
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ <h2>Encoding</h2>
<code>
THREE.LinearEncoding
THREE.sRGBEncoding
THREE.GammaEncoding
THREE.BasicDepthPacking
THREE.RGBADepthPacking
</code>
Expand Down
3 changes: 0 additions & 3 deletions docs/api/en/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ <h3>[property:Object extensions]</h3>
various WebGL extensions are supported.
</p>

<h3>[property:Float gammaFactor]</h3>
<p>Default is *2*. </p>

<h3>[property:number outputEncoding]</h3>
<p>Defines the output encoding of the renderer. Default is [page:Textures THREE.LinearEncoding].</p>
<p>If a render target has been set using [page:WebGLRenderer.setRenderTarget .setRenderTarget] then renderTarget.texture.encoding will be used instead.</p>
Expand Down
1 change: 0 additions & 1 deletion docs/api/ko/constants/Textures.html
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ <h2>인코딩</h2>
<code>
THREE.LinearEncoding
THREE.sRGBEncoding
THREE.GammaEncoding
THREE.BasicDepthPacking
THREE.RGBADepthPacking
</code>
Expand Down
1 change: 0 additions & 1 deletion docs/api/zh/constants/Textures.html
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ <h2>编码</h2>
<code>
THREE.LinearEncoding
THREE.sRGBEncoding
THREE.GammaEncoding
THREE.BasicDepthPacking
THREE.RGBADepthPacking
</code>
Expand Down
3 changes: 0 additions & 3 deletions docs/api/zh/renderers/WebGLRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ <h3>[property:Object extensions]</h3>
[page:WebGLRenderer.extensions.get .extensions.get]方法的包装, 用于检查是否支持各种WebGL扩展
</p>

<h3>[property:Float gammaFactor]</h3>
<p>默认是 *2*. </p>

<h3>[property:number outputEncoding]</h3>
<p>定义渲染器的输出编码。默认为[page:Textures THREE.LinearEncoding]</p>
<p>如果渲染目标已经使用 [page:WebGLRenderer.setRenderTarget .setRenderTarget]、之后将直接使用renderTarget.texture.encoding</p>
Expand Down
2 changes: 1 addition & 1 deletion examples/js/shaders/GammaCorrectionShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

vec4 tex = texture2D( tDiffuse, vUv );

gl_FragColor = LinearTosRGB( tex ); // optional: LinearToGamma( tex, float( GAMMA_FACTOR ) );
gl_FragColor = LinearTosRGB( tex );

}`
};
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CubeUVReflectionMapping,
CubeUVRefractionMapping,
LinearEncoding,
GammaEncoding
sRGBEncoding
} from '../../../../build/three.module.js';

import { NodeUniform } from './NodeUniform.js';
Expand Down Expand Up @@ -951,7 +951,7 @@ class NodeBuilder {

if ( encoding === LinearEncoding && this.context.gamma ) {

encoding = GammaEncoding;
encoding = sRGBEncoding;

}

Expand Down
27 changes: 0 additions & 27 deletions examples/jsm/nodes/utils/ColorSpaceNode.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
GammaEncoding,
LinearEncoding,
sRGBEncoding
} from '../../../../build/three.module.js';

import { TempNode } from '../core/TempNode.js';
import { FunctionNode } from '../core/FunctionNode.js';
import { ExpressionNode } from '../core/ExpressionNode.js';

class ColorSpaceNode extends TempNode {

Expand Down Expand Up @@ -100,8 +98,6 @@ class ColorSpaceNode extends TempNode {

ColorSpaceNode.Nodes = ( function () {

// For a discussion of what this is, please read this: http://lousodrome.net/blog/light/2013/05/26/gamma-correct-and-hdr-rendering-in-a-32-bits-buffer/

const LinearToLinear = new FunctionNode( /* glsl */`
vec4 LinearToLinear( in vec4 value ) {

Expand All @@ -110,22 +106,6 @@ ColorSpaceNode.Nodes = ( function () {
}`
);

const GammaToLinear = new FunctionNode( /* glsl */`
vec4 GammaToLinear( in vec4 value, in float gammaFactor ) {

return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );

}`
);

const LinearToGamma = new FunctionNode( /* glsl */`
vec4 LinearToGamma( in vec4 value, in float gammaFactor ) {

return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );

}`
);

const sRGBToLinear = new FunctionNode( /* glsl */`
vec4 sRGBToLinear( in vec4 value ) {

Expand All @@ -144,8 +124,6 @@ ColorSpaceNode.Nodes = ( function () {

return {
LinearToLinear: LinearToLinear,
GammaToLinear: GammaToLinear,
LinearToGamma: LinearToGamma,
sRGBToLinear: sRGBToLinear,
LinearTosRGB: LinearTosRGB
};
Expand All @@ -154,9 +132,6 @@ ColorSpaceNode.Nodes = ( function () {

ColorSpaceNode.LINEAR_TO_LINEAR = 'LinearToLinear';

ColorSpaceNode.GAMMA_TO_LINEAR = 'GammaToLinear';
ColorSpaceNode.LINEAR_TO_GAMMA = 'LinearToGamma';

ColorSpaceNode.SRGB_TO_LINEAR = 'sRGBToLinear';
ColorSpaceNode.LINEAR_TO_SRGB = 'LinearTosRGB';

Expand All @@ -168,8 +143,6 @@ ColorSpaceNode.getEncodingComponents = function ( encoding ) {
return [ 'Linear' ];
case sRGBEncoding:
return [ 'sRGB' ];
case GammaEncoding:
return [ 'Gamma', new ExpressionNode( 'float( GAMMA_FACTOR )', 'f' ) ];

}

Expand Down
12 changes: 2 additions & 10 deletions examples/jsm/renderers/nodes/display/ColorSpaceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { ShaderNode,
pow, mul, add, sub, mix, join,
lessThanEqual } from '../ShaderNode.js';

import { LinearEncoding,
sRGBEncoding/*, GammaEncoding*/ } from '../../../../../build/three.module.js';
import { LinearEncoding, sRGBEncoding } from '../../../../../build/three.module.js';

export const LinearToLinear = new ShaderNode( ( inputs ) => {

Expand Down Expand Up @@ -59,10 +58,6 @@ function getEncodingComponents( encoding ) {
return [ 'Linear' ];
case sRGBEncoding:
return [ 'sRGB' ];
/*
case GammaEncoding:
return [ 'Gamma', new CodeNode( 'float( GAMMA_FACTOR )' ) ];
*/

}

Expand All @@ -74,10 +69,7 @@ class ColorSpaceNode extends TempNode {

static SRGB_TO_LINEAR = 'sRGBToLinear';
static LINEAR_TO_SRGB = 'LinearTosRGB';
/*
static GAMMA_TO_LINEAR = 'GammaToLinear';
static LINEAR_TO_GAMMA = 'LinearToGamma';
*/

constructor( method, node ) {

super( 'vec4' );
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/shaders/GammaCorrectionShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const GammaCorrectionShader = {

vec4 tex = texture2D( tDiffuse, vUv );

gl_FragColor = LinearTosRGB( tex ); // optional: LinearToGamma( tex, float( GAMMA_FACTOR ) );
gl_FragColor = LinearTosRGB( tex );

}`

Expand Down
12 changes: 12 additions & 0 deletions src/Three.Legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,19 @@ Object.defineProperties( WebGLRenderer.prototype, {

}
},
gammaFactor: {
get: function () {

console.warn( 'THREE.WebGLRenderer: .gammaFactor has been removed.' );
return 2;

},
set: function () {

console.warn( 'THREE.WebGLRenderer: .gammaFactor has been removed.' );

}
}
} );

Object.defineProperties( WebGLShadowMap.prototype, {
Expand Down
1 change: 0 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export const TriangleStripDrawMode = 1;
export const TriangleFanDrawMode = 2;
export const LinearEncoding = 3000;
export const sRGBEncoding = 3001;
export const GammaEncoding = 3007;
export const BasicDepthPacking = 3200;
export const RGBADepthPacking = 3201;
export const TangentSpaceNormalMap = 0;
Expand Down
10 changes: 2 additions & 8 deletions src/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
CubeReflectionMapping,
CubeRefractionMapping,
CubeUVReflectionMapping,
GammaEncoding,
LinearEncoding,
LinearFilter,
NoToneMapping,
Expand Down Expand Up @@ -45,8 +44,7 @@ const MAX_SAMPLES = 20;

const ENCODINGS = {
[ LinearEncoding ]: 0,
[ sRGBEncoding ]: 1,
[ GammaEncoding ]: 6
[ sRGBEncoding ]: 1
};

const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
Expand Down Expand Up @@ -904,13 +902,9 @@ function _getEncodings() {

return value;

} else if ( inputEncoding == 1 ) {

return sRGBToLinear( value );

} else {

return GammaToLinear( value, 2.2 );
return sRGBToLinear( value );

}

Expand Down
1 change: 0 additions & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ function WebGLRenderer( parameters = {} ) {

// physically based shading

this.gammaFactor = 2.0; // for backwards compatibility
this.outputEncoding = LinearEncoding;

// physical lights
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
export default /* glsl */`
// For a discussion of what this is, please read this: http://lousodrome.net/blog/light/2013/05/26/gamma-correct-and-hdr-rendering-in-a-32-bits-buffer/

vec4 LinearToLinear( in vec4 value ) {
return value;
}

vec4 GammaToLinear( in vec4 value, in float gammaFactor ) {
return vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );
}

vec4 LinearToGamma( in vec4 value, in float gammaFactor ) {
return vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );
}

vec4 sRGBToLinear( in vec4 value ) {
return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
}
Expand Down
11 changes: 1 addition & 10 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WebGLUniforms } from './WebGLUniforms.js';
import { WebGLShader } from './WebGLShader.js';
import { ShaderChunk } from '../shaders/ShaderChunk.js';
import { RGBFormat, NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, ACESFilmicToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, GammaEncoding, sRGBEncoding, LinearEncoding, GLSL3 } from '../../constants.js';
import { RGBFormat, NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, ACESFilmicToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, sRGBEncoding, LinearEncoding, GLSL3 } from '../../constants.js';

let programIdCount = 0;

Expand All @@ -27,8 +27,6 @@ function getEncodingComponents( encoding ) {
return [ 'Linear', '( value )' ];
case sRGBEncoding:
return [ 'sRGB', '( value )' ];
case GammaEncoding:
return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
default:
console.warn( 'THREE.WebGLProgram: Unsupported encoding:', encoding );
return [ 'Linear', '( value )' ];
Expand Down Expand Up @@ -389,9 +387,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
const envMapModeDefine = generateEnvMapModeDefine( parameters );
const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );


const gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;

const customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );

const customDefines = generateDefines( defines );
Expand Down Expand Up @@ -443,8 +438,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {

parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',

'#define GAMMA_FACTOR ' + gammaFactorDefine,

'#define MAX_BONES ' + parameters.maxBones,
( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
Expand Down Expand Up @@ -593,8 +586,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {

customDefines,

'#define GAMMA_FACTOR ' + gammaFactorDefine,

( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',

Expand Down
1 change: 0 additions & 1 deletion src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
getProgramCacheKeyParameters( array, parameters );
getProgramCacheKeyBooleans( array, parameters );
array.push( renderer.outputEncoding );
array.push( renderer.gammaFactor );

}

Expand Down
1 change: 0 additions & 1 deletion test/unit/src/constants.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export default QUnit.module( 'Constants', () => {
assert.equal( Constants.TriangleFanDrawMode, 2, 'TriangleFanDrawMode is equal to 2' );
assert.equal( Constants.LinearEncoding, 3000, 'LinearEncoding is equal to 3000' );
assert.equal( Constants.sRGBEncoding, 3001, 'sRGBEncoding is equal to 3001' );
assert.equal( Constants.GammaEncoding, 3007, 'GammaEncoding is equal to 3007' );
assert.equal( Constants.BasicDepthPacking, 3200, 'BasicDepthPacking is equal to 3200' );
assert.equal( Constants.RGBADepthPacking, 3201, 'RGBADepthPacking is equal to 3201' );

Expand Down