diff --git a/src/materials/MeshToonMaterial.js b/src/materials/MeshToonMaterial.js index 390ef0aaa16582..72ec94dc3010a3 100644 --- a/src/materials/MeshToonMaterial.js +++ b/src/materials/MeshToonMaterial.js @@ -57,7 +57,7 @@ class MeshToonMaterial extends Material { /** * Gradient map for toon shading. It's required to set - * {@link Texture#minFilter} and {@link Texture#magFilter} to {@linkNearestFilter} + * {@link Texture#minFilter} and {@link Texture#magFilter} to {@link NearestFilter} * when using this type of texture. * * @type {?Texture} diff --git a/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js b/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js index fb50187015c54b..84f8a4169849dd 100644 --- a/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +++ b/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js @@ -2,7 +2,6 @@ export default /* glsl */` #ifdef USE_ENVMAP uniform float envMapIntensity; - uniform float flipEnvMap; uniform mat3 envMapRotation; #ifdef ENVMAP_TYPE_CUBE diff --git a/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js b/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js index 843c623796fd4e..fd753723ac337f 100644 --- a/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +++ b/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js @@ -36,7 +36,7 @@ export default /* glsl */` #ifdef ENVMAP_TYPE_CUBE - vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) ); + vec4 envColor = textureCube( envMap, envMapRotation * reflectVec ); #ifdef ENVMAP_BLENDING_MULTIPLY diff --git a/src/renderers/shaders/ShaderLib.js b/src/renderers/shaders/ShaderLib.js index c16b95c8814f88..944dd4633f7028 100644 --- a/src/renderers/shaders/ShaderLib.js +++ b/src/renderers/shaders/ShaderLib.js @@ -232,7 +232,6 @@ const ShaderLib = { uniforms: { envMap: { value: null }, - flipEnvMap: { value: - 1 }, backgroundBlurriness: { value: 0 }, backgroundIntensity: { value: 1 }, backgroundRotation: { value: /*@__PURE__*/ new Matrix3() } diff --git a/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js b/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js index 8a4acb3265f4a9..a35b1d6411bdba 100644 --- a/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +++ b/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js @@ -27,7 +27,6 @@ export const fragment = /* glsl */` #endif -uniform float flipEnvMap; uniform float backgroundBlurriness; uniform float backgroundIntensity; uniform mat3 backgroundRotation; @@ -40,7 +39,7 @@ void main() { #ifdef ENVMAP_TYPE_CUBE - vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ); + vec4 texColor = textureCube( envMap, backgroundRotation * vWorldDirection ); #elif defined( ENVMAP_TYPE_CUBE_UV ) diff --git a/src/renderers/shaders/UniformsLib.js b/src/renderers/shaders/UniformsLib.js index 127e40e5351c50..4eb9fb8d761a03 100644 --- a/src/renderers/shaders/UniformsLib.js +++ b/src/renderers/shaders/UniformsLib.js @@ -31,7 +31,6 @@ const UniformsLib = { envMap: { value: null }, envMapRotation: { value: /*@__PURE__*/ new Matrix3() }, - flipEnvMap: { value: - 1 }, reflectivity: { value: 1.0 }, // basic, lambert, phong ior: { value: 1.5 }, // physical refractionRatio: { value: 0.98 }, // basic, lambert, phong diff --git a/src/renderers/webgl/WebGLBackground.js b/src/renderers/webgl/WebGLBackground.js index 90344e86834203..9fdc7b7045cca0 100644 --- a/src/renderers/webgl/WebGLBackground.js +++ b/src/renderers/webgl/WebGLBackground.js @@ -4,15 +4,17 @@ import { PlaneGeometry } from '../../geometries/PlaneGeometry.js'; import { ShaderMaterial } from '../../materials/ShaderMaterial.js'; import { Color } from '../../math/Color.js'; import { ColorManagement } from '../../math/ColorManagement.js'; -import { Euler } from '../../math/Euler.js'; +import { Matrix3 } from '../../math/Matrix3.js'; import { Matrix4 } from '../../math/Matrix4.js'; import { Mesh } from '../../objects/Mesh.js'; import { ShaderLib } from '../shaders/ShaderLib.js'; import { cloneUniforms, getUnlitUniformColorSpace } from '../shaders/UniformsUtils.js'; const _rgb = { r: 0, b: 0, g: 0 }; -const _e1 = /*@__PURE__*/ new Euler(); const _m1 = /*@__PURE__*/ new Matrix4(); +const _m = /*@__PURE__*/ new Matrix3(); + +_m.set( - 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ); function WebGLBackground( renderer, environments, state, objects, alpha, premultipliedAlpha ) { @@ -130,24 +132,22 @@ function WebGLBackground( renderer, environments, state, objects, alpha, premult } - _e1.copy( scene.backgroundRotation ); - // accommodate left-handed frame - _e1.x *= - 1; _e1.y *= - 1; _e1.z *= - 1; + boxMesh.material.uniforms.envMap.value = background; + boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness; + boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity; + + + // note: since the matrix is orthonormal, we can use the more-efficient transpose() in lieu of invert() + boxMesh.material.uniforms.backgroundRotation.value.setFromMatrix4( _m1.makeRotationFromEuler( scene.backgroundRotation ) ).transpose(); if ( background.isCubeTexture && background.isRenderTargetTexture === false ) { - // environment maps which are not cube render targets or PMREMs follow a different convention - _e1.y *= - 1; - _e1.z *= - 1; + boxMesh.material.uniforms.backgroundRotation.value.premultiply( _m ); } - boxMesh.material.uniforms.envMap.value = background; - boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background.isRenderTargetTexture === false ) ? - 1 : 1; - boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness; - boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity; - boxMesh.material.uniforms.backgroundRotation.value.setFromMatrix4( _m1.makeRotationFromEuler( _e1 ) ); + boxMesh.material.toneMapped = ColorManagement.getTransfer( background.colorSpace ) !== SRGBTransfer; if ( currentBackground !== background || diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index 93a9bbc51b845f..7c2258e722b372 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -1,10 +1,12 @@ import { BackSide } from '../../constants.js'; import { getUnlitUniformColorSpace } from '../shaders/UniformsUtils.js'; -import { Euler } from '../../math/Euler.js'; +import { Matrix3 } from '../../math/Matrix3.js'; import { Matrix4 } from '../../math/Matrix4.js'; -const _e1 = /*@__PURE__*/ new Euler(); const _m1 = /*@__PURE__*/ new Matrix4(); +const _m = /*@__PURE__*/ new Matrix3(); + +_m.set( - 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 ); function WebGLMaterials( renderer, properties ) { @@ -235,23 +237,16 @@ function WebGLMaterials( renderer, properties ) { uniforms.envMap.value = envMap; - _e1.copy( envMapRotation ); + // note: since the matrix is orthonormal, we can use the more-efficient transpose() in lieu of invert() + uniforms.envMapRotation.value.setFromMatrix4( _m1.makeRotationFromEuler( envMapRotation ) ).transpose(); - // accommodate left-handed frame - _e1.x *= - 1; _e1.y *= - 1; _e1.z *= - 1; if ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) { - // environment maps which are not cube render targets or PMREMs follow a different convention - _e1.y *= - 1; - _e1.z *= - 1; + uniforms.envMapRotation.value.premultiply( _m ); } - uniforms.envMapRotation.value.setFromMatrix4( _m1.makeRotationFromEuler( _e1 ) ); - - uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? - 1 : 1; - uniforms.reflectivity.value = material.reflectivity; uniforms.ior.value = material.ior; uniforms.refractionRatio.value = material.refractionRatio;