Skip to content

Commit

Permalink
Revert "HalfFloat PMREM (mrdoob#22998)"
Browse files Browse the repository at this point in the history
This reverts commit 2768965.
  • Loading branch information
chubei-oppen committed Jan 4, 2022
1 parent c635a12 commit ef1ac18
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 20 deletions.
68 changes: 56 additions & 12 deletions src/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
CubeRefractionMapping,
CubeUVReflectionMapping,
LinearEncoding,
LinearFilter,
NoToneMapping,
NearestFilter,
NoBlending,
RGBEEncoding,
RGBAFormat,
RGBEFormat,
UnsignedByteType,
sRGBEncoding,
HalfFloatType
sRGBEncoding
} from '../constants.js';

import { BufferAttribute } from '../core/BufferAttribute.js';
Expand Down Expand Up @@ -226,12 +226,12 @@ class PMREMGenerator {
_allocateTargets( texture ) { // warning: null texture is valid

const params = {
magFilter: LinearFilter,
minFilter: LinearFilter,
magFilter: NearestFilter,
minFilter: NearestFilter,
generateMipmaps: false,
type: HalfFloatType,
format: RGBAFormat,
encoding: LinearEncoding,
type: UnsignedByteType,
format: RGBEFormat,
encoding: _isLDR( texture ) ? texture.encoding : RGBEEncoding,
depthBuffer: false
};

Expand Down Expand Up @@ -259,10 +259,12 @@ class PMREMGenerator {
const renderer = this._renderer;

const originalAutoClear = renderer.autoClear;
const outputEncoding = renderer.outputEncoding;
const toneMapping = renderer.toneMapping;
renderer.getClearColor( _clearColor );

renderer.toneMapping = NoToneMapping;
renderer.outputEncoding = LinearEncoding;
renderer.autoClear = false;

const backgroundMaterial = new MeshBasicMaterial( {
Expand Down Expand Up @@ -332,6 +334,7 @@ class PMREMGenerator {
backgroundBox.material.dispose();

renderer.toneMapping = toneMapping;
renderer.outputEncoding = outputEncoding;
renderer.autoClear = originalAutoClear;
scene.background = background;

Expand Down Expand Up @@ -389,6 +392,7 @@ class PMREMGenerator {
}

this._setEncoding( uniforms[ 'inputEncoding' ], texture );
this._setEncoding( uniforms[ 'outputEncoding' ], cubeUVRenderTarget.texture );

_setViewport( cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX );

Expand Down Expand Up @@ -520,6 +524,9 @@ class PMREMGenerator {
blurUniforms[ 'dTheta' ].value = radiansPerPixel;
blurUniforms[ 'mipInt' ].value = LOD_MAX - lodIn;

this._setEncoding( blurUniforms[ 'inputEncoding' ], targetIn.texture );
this._setEncoding( blurUniforms[ 'outputEncoding' ], targetIn.texture );

const outputSize = _sizeLods[ lodOut ];
const x = 3 * Math.max( 0, SIZE_MAX - 2 * outputSize );
const y = ( lodOut === 0 ? 0 : 2 * SIZE_MAX ) + 2 * outputSize * ( lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0 );
Expand All @@ -532,6 +539,14 @@ class PMREMGenerator {

}

function _isLDR( texture ) {

if ( texture === undefined || texture.type !== UnsignedByteType ) return false;

return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding;

}

function _createPlanes() {

const _lodPlanes = [];
Expand Down Expand Up @@ -644,7 +659,9 @@ function _getBlurShader( maxSamples ) {
'latitudinal': { value: false },
'dTheta': { value: 0 },
'mipInt': { value: 0 },
'poleAxis': { value: poleAxis }
'poleAxis': { value: poleAxis },
'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
},

vertexShader: _getCommonVertexShader(),
Expand Down Expand Up @@ -710,6 +727,8 @@ function _getBlurShader( maxSamples ) {
}
gl_FragColor = linearToOutputTexel( gl_FragColor );
}
`,

Expand All @@ -733,7 +752,8 @@ function _getEquirectShader() {
uniforms: {
'envMap': { value: null },
'texelSize': { value: texelSize },
'inputEncoding': { value: ENCODINGS[ LinearEncoding ] }
'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
},

vertexShader: _getCommonVertexShader(),
Expand Down Expand Up @@ -773,6 +793,8 @@ function _getEquirectShader() {
vec3 bm = mix( bl, br, f.x );
gl_FragColor.rgb = mix( tm, bm, f.y );
gl_FragColor = linearToOutputTexel( gl_FragColor );
}
`,

Expand All @@ -794,7 +816,8 @@ function _getCubemapShader() {

uniforms: {
'envMap': { value: null },
'inputEncoding': { value: ENCODINGS[ LinearEncoding ] }
'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
},

vertexShader: _getCommonVertexShader(),
Expand All @@ -812,7 +835,9 @@ function _getCubemapShader() {
void main() {
gl_FragColor = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) );
gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
gl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;
gl_FragColor = linearToOutputTexel( gl_FragColor );
}
`,
Expand Down Expand Up @@ -895,6 +920,7 @@ function _getEncodings() {
return /* glsl */`
uniform int inputEncoding;
uniform int outputEncoding;
#include <encodings_pars_fragment>
Expand All @@ -916,6 +942,24 @@ function _getEncodings() {
}
vec4 linearToOutputTexel( vec4 value ) {
if ( outputEncoding == 0 ) {
return value;
} else if ( outputEncoding == 1 ) {
return LinearTosRGB( value );
} else if ( outputEncoding == 2 ) {
return LinearToRGBE( value );
}
}
vec4 envMapTexelToLinear( vec4 color ) {
return inputTexelToLinear( color );
Expand Down
6 changes: 0 additions & 6 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,6 @@ function WebGLRenderer( parameters = {} ) {
materialProperties.numIntersection = parameters.numClipIntersection;
materialProperties.vertexAlphas = parameters.vertexAlphas;
materialProperties.vertexTangents = parameters.vertexTangents;
materialProperties.toneMapping = parameters.toneMapping;

}

Expand All @@ -1429,7 +1428,6 @@ function WebGLRenderer( parameters = {} ) {
const morphTargets = !! geometry.morphAttributes.position;
const morphNormals = !! geometry.morphAttributes.normal;
const morphTargetsCount = !! geometry.morphAttributes.position ? geometry.morphAttributes.position.length : 0;
const toneMapping = material.toneMapped ? _this.toneMapping : NoToneMapping;

const materialProperties = properties.get( material );
const lights = currentRenderState.state.lights;
Expand Down Expand Up @@ -1511,10 +1509,6 @@ function WebGLRenderer( parameters = {} ) {

needsProgramChange = true;

} else if ( materialProperties.toneMapping !== toneMapping ) {

needsProgramChange = true;

} else if ( capabilities.isWebGL2 === true && materialProperties.morphTargetsCount !== morphTargetsCount ) {

needsProgramChange = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export default /* glsl */`
float texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );
vec2 uv = getUV( direction, face ) * ( faceSize - 1.0 ) + 0.5;
vec2 uv = getUV( direction, face ) * ( faceSize - 1.0 );
vec2 f = fract( uv );
uv += 0.5 - f;
if ( face > 2.0 ) {
Expand All @@ -113,7 +117,25 @@ export default /* glsl */`
uv *= texelSize;
return texture2D( envMap, uv ).rgb;
vec3 tl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;
uv.x += texelSize;
vec3 tr = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;
uv.y += texelSize;
vec3 br = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;
uv.x -= texelSize;
vec3 bl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;
vec3 tm = mix( tl, tr, f.x );
vec3 bm = mix( bl, br, f.x );
return mix( tm, bm, f.y );
}
Expand Down

0 comments on commit ef1ac18

Please sign in to comment.