From d98923f9787f44c9c77cd03cce1524c1112d7cd4 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 17 Oct 2024 14:59:01 +0900 Subject: [PATCH 1/8] Always generate mipmaps when "generateMipmaps" is true. --- src/renderers/webgl/WebGLTextures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgl/WebGLTextures.js b/src/renderers/webgl/WebGLTextures.js index 5663c8e8affb88..9aac03e5dfe07a 100644 --- a/src/renderers/webgl/WebGLTextures.js +++ b/src/renderers/webgl/WebGLTextures.js @@ -107,7 +107,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, function textureNeedsGenerateMipmaps( texture ) { - return texture.generateMipmaps && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter; + return texture.generateMipmaps; } From 9b683f46ca9b10551c9fc03483baac4ef049bf73 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 17 Oct 2024 18:46:48 +0900 Subject: [PATCH 2/8] Update HTML examples --- examples/webgl_depth_texture.html | 1 + examples/webgl_materials_texture_filters.html | 1 + examples/webgl_video_kinect.html | 1 + examples/webgpu_compute_particles_rain.html | 1 + examples/webgpu_compute_particles_snow.html | 1 + 5 files changed, 5 insertions(+) diff --git a/examples/webgl_depth_texture.html b/examples/webgl_depth_texture.html index f3b3601cbc4746..9ea6e249a08f28 100644 --- a/examples/webgl_depth_texture.html +++ b/examples/webgl_depth_texture.html @@ -148,6 +148,7 @@ target = new THREE.WebGLRenderTarget( window.innerWidth * dpr, window.innerHeight * dpr ); target.texture.minFilter = THREE.NearestFilter; target.texture.magFilter = THREE.NearestFilter; + target.texture.generateMipmaps = false; target.stencilBuffer = ( format === THREE.DepthStencilFormat ) ? true : false; target.samples = samples; diff --git a/examples/webgl_materials_texture_filters.html b/examples/webgl_materials_texture_filters.html index 3867020a910005..8086349d073d89 100644 --- a/examples/webgl_materials_texture_filters.html +++ b/examples/webgl_materials_texture_filters.html @@ -109,6 +109,7 @@ const textureCanvas2 = textureCanvas.clone(); textureCanvas2.magFilter = THREE.NearestFilter; textureCanvas2.minFilter = THREE.NearestFilter; + textureCanvas2.generateMipmaps = false; const materialCanvas = new THREE.MeshBasicMaterial( { map: textureCanvas } ); const materialCanvas2 = new THREE.MeshBasicMaterial( { color: 0xffccaa, map: textureCanvas2 } ); diff --git a/examples/webgl_video_kinect.html b/examples/webgl_video_kinect.html index e8f909095c21b7..b77bb3b9309179 100644 --- a/examples/webgl_video_kinect.html +++ b/examples/webgl_video_kinect.html @@ -110,6 +110,7 @@ const texture = new THREE.VideoTexture( video ); texture.minFilter = THREE.NearestFilter; + texture.generateMipmaps = false; const width = 640, height = 480; const nearClipping = 850, farClipping = 4000; diff --git a/examples/webgpu_compute_particles_rain.html b/examples/webgpu_compute_particles_rain.html index a2265a0607cd88..9fea602f021952 100644 --- a/examples/webgpu_compute_particles_rain.html +++ b/examples/webgpu_compute_particles_rain.html @@ -87,6 +87,7 @@ collisionPosRT.texture.type = THREE.HalfFloatType; collisionPosRT.texture.magFilter = THREE.NearestFilter; collisionPosRT.texture.minFilter = THREE.NearestFilter; + collisionPosRT.texture.generateMipmaps = false; collisionPosMaterial = new THREE.MeshBasicNodeMaterial(); collisionPosMaterial.colorNode = positionWorld; diff --git a/examples/webgpu_compute_particles_snow.html b/examples/webgpu_compute_particles_snow.html index ec23d8432c0b13..837de5e0ccc656 100644 --- a/examples/webgpu_compute_particles_snow.html +++ b/examples/webgpu_compute_particles_snow.html @@ -85,6 +85,7 @@ collisionPosRT.texture.type = THREE.HalfFloatType; collisionPosRT.texture.magFilter = THREE.NearestFilter; collisionPosRT.texture.minFilter = THREE.NearestFilter; + collisionPosRT.texture.generateMipmaps = false; collisionPosMaterial = new THREE.MeshBasicNodeMaterial(); collisionPosMaterial.fog = false; From a8e7f4e34276b392adef3de7d253e1d408afae44 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 17 Oct 2024 18:52:50 +0900 Subject: [PATCH 3/8] More examples --- examples/webgl_lights_spotlight.html | 1 + examples/webgl_postprocessing_masking.html | 1 + examples/webgpu_postprocessing_masking.html | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/webgl_lights_spotlight.html b/examples/webgl_lights_spotlight.html index 507c94cf41be1e..e08d102c3478a3 100644 --- a/examples/webgl_lights_spotlight.html +++ b/examples/webgl_lights_spotlight.html @@ -77,6 +77,7 @@ const texture = loader.load( filename ); texture.minFilter = THREE.LinearFilter; texture.magFilter = THREE.LinearFilter; + texture.generateMipmaps = false; texture.colorSpace = THREE.SRGBColorSpace; textures[ filename ] = texture; diff --git a/examples/webgl_postprocessing_masking.html b/examples/webgl_postprocessing_masking.html index e89d22be58df7c..b66b8a0fc52b71 100644 --- a/examples/webgl_postprocessing_masking.html +++ b/examples/webgl_postprocessing_masking.html @@ -68,6 +68,7 @@ const texture1 = new THREE.TextureLoader().load( 'textures/758px-Canestra_di_frutta_(Caravaggio).jpg' ); texture1.colorSpace = THREE.SRGBColorSpace; texture1.minFilter = THREE.LinearFilter; + texture1.generateMipmaps = false; const texture2 = new THREE.TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' ); texture2.colorSpace = THREE.SRGBColorSpace; diff --git a/examples/webgpu_postprocessing_masking.html b/examples/webgpu_postprocessing_masking.html index 0b16e4236effea..3c8dd12ff803b9 100644 --- a/examples/webgpu_postprocessing_masking.html +++ b/examples/webgpu_postprocessing_masking.html @@ -53,6 +53,7 @@ const texture1 = new THREE.TextureLoader().load( 'textures/758px-Canestra_di_frutta_(Caravaggio).jpg' ); texture1.colorSpace = THREE.SRGBColorSpace; texture1.minFilter = THREE.LinearFilter; + texture1.generateMipmaps = false; texture1.flipY = false; const texture2 = new THREE.TextureLoader().load( 'textures/2294472375_24a3b8ef46_o.jpg' ); @@ -116,4 +117,4 @@ - \ No newline at end of file + From 66fc5a88d6b959b0f3e1384b4e4324a9644f3bd6 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 17 Oct 2024 18:58:00 +0900 Subject: [PATCH 4/8] Update loaders --- examples/jsm/interactive/HTMLMesh.js | 1 + examples/jsm/loaders/3DMLoader.js | 1 + examples/jsm/loaders/3MFLoader.js | 4 +++- examples/jsm/loaders/LottieLoader.js | 1 + examples/jsm/loaders/MMDLoader.js | 1 + examples/jsm/misc/VolumeSlice.js | 1 + 6 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/jsm/interactive/HTMLMesh.js b/examples/jsm/interactive/HTMLMesh.js index c7c5fa49f50c8f..14c8c1ee22260f 100644 --- a/examples/jsm/interactive/HTMLMesh.js +++ b/examples/jsm/interactive/HTMLMesh.js @@ -62,6 +62,7 @@ class HTMLTexture extends CanvasTexture { this.colorSpace = SRGBColorSpace; this.minFilter = LinearFilter; this.magFilter = LinearFilter; + this.generateMipmaps = false; // Create an observer on the DOM, and run html2canvas update in the next loop const observer = new MutationObserver( () => { diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 6b1fc39ada2fc2..c22d947fa5bf9b 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -745,6 +745,7 @@ class Rhino3dmLoader extends Loader { const texture = new CanvasTexture( ctx.canvas ); texture.minFilter = LinearFilter; + texture.generateMipmaps = false; texture.wrapS = ClampToEdgeWrapping; texture.wrapT = ClampToEdgeWrapping; diff --git a/examples/jsm/loaders/3MFLoader.js b/examples/jsm/loaders/3MFLoader.js index 4f2b0ed452230f..01e7c9883854fb 100644 --- a/examples/jsm/loaders/3MFLoader.js +++ b/examples/jsm/loaders/3MFLoader.js @@ -386,7 +386,7 @@ class ThreeMFLoader extends Loader { const attrib = portNodes[ i ].attributes[ j ]; if ( attrib.specified ) { - args[ attrib.name ] = attrib.value; + args[ attrib.name ] = attrib.value; } } @@ -929,11 +929,13 @@ class ThreeMFLoader extends Loader { case 'linear': texture.magFilter = LinearFilter; texture.minFilter = LinearFilter; + texture.generateMipmaps = false; break; case 'nearest': texture.magFilter = NearestFilter; texture.minFilter = NearestFilter; + texture.generateMipmaps = false; break; default: diff --git a/examples/jsm/loaders/LottieLoader.js b/examples/jsm/loaders/LottieLoader.js index 4ef0401c223feb..7d5a7798a928a3 100644 --- a/examples/jsm/loaders/LottieLoader.js +++ b/examples/jsm/loaders/LottieLoader.js @@ -22,6 +22,7 @@ class LottieLoader extends Loader { const texture = new CanvasTexture(); texture.minFilter = NearestFilter; + texture.generateMipmaps = false; texture.colorSpace = SRGBColorSpace; const loader = new FileLoader( this.manager ); diff --git a/examples/jsm/loaders/MMDLoader.js b/examples/jsm/loaders/MMDLoader.js index 46bfa1f3f31e57..2c5f84c87a2603 100644 --- a/examples/jsm/loaders/MMDLoader.js +++ b/examples/jsm/loaders/MMDLoader.js @@ -1467,6 +1467,7 @@ class MaterialBuilder { t.magFilter = NearestFilter; t.minFilter = NearestFilter; + t.generateMipmaps = false; } diff --git a/examples/jsm/misc/VolumeSlice.js b/examples/jsm/misc/VolumeSlice.js index 980830ecf23c52..bb99c2d118296b 100644 --- a/examples/jsm/misc/VolumeSlice.js +++ b/examples/jsm/misc/VolumeSlice.js @@ -68,6 +68,7 @@ class VolumeSlice { const canvasMap = new Texture( this.canvas ); canvasMap.minFilter = LinearFilter; + canvasMap.generateMipmaps = false; canvasMap.wrapS = canvasMap.wrapT = ClampToEdgeWrapping; canvasMap.colorSpace = SRGBColorSpace; const material = new MeshBasicMaterial( { map: canvasMap, side: DoubleSide, transparent: true } ); From 4c2b03159df81f68fc6e6c0e5c831982fd8f4f5c Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 17 Oct 2024 18:58:07 +0900 Subject: [PATCH 5/8] Fix GLTF loader --- examples/jsm/loaders/GLTFLoader.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index e39cbcb9233e31..e493a72e121782 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -3230,6 +3230,7 @@ class GLTFParser { texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter; texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping; texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping; + texture.generateMipmaps = texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter; parser.associations.set( texture, { textures: textureIndex } ); From 371e7e263890bd61c12bcd3549b363aff364b963 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 17 Oct 2024 19:00:13 +0900 Subject: [PATCH 6/8] Update WebGPURenderer --- src/renderers/common/Textures.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/renderers/common/Textures.js b/src/renderers/common/Textures.js index 0ac03c936acdc9..04f0ab4c731ed4 100644 --- a/src/renderers/common/Textures.js +++ b/src/renderers/common/Textures.js @@ -335,9 +335,7 @@ class Textures extends DataMap { needsMipmaps( texture ) { - if ( this.isEnvironmentTexture( texture ) ) return true; - - return ( texture.isCompressedTexture === true ) || ( ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter ) ); + return this.isEnvironmentTexture( texture ) || texture.isCompressedTexture === true || texture.generateMipmaps; } From d986c71646544b6f5771341616a2e51d54885d85 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 17 Oct 2024 19:17:16 +0900 Subject: [PATCH 7/8] Remove unused constants --- src/renderers/common/Textures.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/common/Textures.js b/src/renderers/common/Textures.js index 04f0ab4c731ed4..3a817fcd450814 100644 --- a/src/renderers/common/Textures.js +++ b/src/renderers/common/Textures.js @@ -2,7 +2,7 @@ import DataMap from './DataMap.js'; import { Vector3 } from '../../math/Vector3.js'; import { DepthTexture } from '../../textures/DepthTexture.js'; -import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, LinearFilter, NearestFilter, EquirectangularReflectionMapping, EquirectangularRefractionMapping, CubeReflectionMapping, CubeRefractionMapping, UnsignedByteType } from '../../constants.js'; +import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, EquirectangularReflectionMapping, EquirectangularRefractionMapping, CubeReflectionMapping, CubeRefractionMapping, UnsignedByteType } from '../../constants.js'; const _size = /*@__PURE__*/ new Vector3(); From 5453498b03ed284d33441f1a0c498d85f0250ad8 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Thu, 17 Oct 2024 23:04:42 +0900 Subject: [PATCH 8/8] Update bindings file to remove unnecessary mipmaps check --- src/renderers/common/Bindings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/common/Bindings.js b/src/renderers/common/Bindings.js index 571d3def6cc962..2e7992156ebc25 100644 --- a/src/renderers/common/Bindings.js +++ b/src/renderers/common/Bindings.js @@ -177,7 +177,7 @@ class Bindings extends DataMap { textureData.needsMipmap = true; - } else if ( texture.generateMipmaps === true && this.textures.needsMipmaps( texture ) && textureData.needsMipmap === true ) { + } else if ( this.textures.needsMipmaps( texture ) && textureData.needsMipmap === true ) { this.backend.generateMipmaps( texture );