Skip to content

Commit

Permalink
WebGLRenderer: Always generate mipmaps when "generateMipmaps" is true. (
Browse files Browse the repository at this point in the history
#29677)

* Always generate mipmaps when "generateMipmaps" is true.

* Update HTML examples

* More examples

* Update loaders

* Fix GLTF loader

* Update WebGPURenderer

* Remove unused constants

* Update bindings file to remove unnecessary mipmaps check
  • Loading branch information
gkjohnson authored Oct 19, 2024
1 parent 6e161d5 commit 8cba4e8
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/jsm/interactive/HTMLMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( () => {
Expand Down
1 change: 1 addition & 0 deletions examples/jsm/loaders/3DMLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion examples/jsm/loaders/3MFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );

Expand Down
1 change: 1 addition & 0 deletions examples/jsm/loaders/LottieLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions examples/jsm/loaders/MMDLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,7 @@ class MaterialBuilder {

t.magFilter = NearestFilter;
t.minFilter = NearestFilter;
t.generateMipmaps = false;

}

Expand Down
1 change: 1 addition & 0 deletions examples/jsm/misc/VolumeSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
Expand Down
1 change: 1 addition & 0 deletions examples/webgl_depth_texture.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions examples/webgl_lights_spotlight.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions examples/webgl_materials_texture_filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
Expand Down
1 change: 1 addition & 0 deletions examples/webgl_postprocessing_masking.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions examples/webgl_video_kinect.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions examples/webgpu_compute_particles_rain.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions examples/webgpu_compute_particles_snow.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion examples/webgpu_postprocessing_masking.html
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -116,4 +117,4 @@

</script>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion src/renderers/common/Bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
6 changes: 2 additions & 4 deletions src/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;

}

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl/WebGLTextures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

Expand Down

0 comments on commit 8cba4e8

Please sign in to comment.