Browse Source

Fix RoughnessMipmapper (#22985)

* use proper filtering

* Fixed RoughnessMipmapper

* Update RoughnessMipmapper.js

* Update WebGLTextures.js

* Update WebGLTextures.js

* Update WebGLTextures.js

Co-authored-by: Michael Herzog <[email protected]>
Emmett Lalish 3 năm trước cách đây
mục cha
commit
d80a715d01

+ 3 - 1
examples/jsm/utils/RoughnessMipmapper.js

@@ -119,9 +119,11 @@ class RoughnessMipmapper {
 
 			_renderer.copyFramebufferToTexture( position, material.roughnessMap, mip );
 
+			_mipmapMaterial.uniforms.roughnessMap.value = material.roughnessMap;
+
 		}
 
-		if ( roughnessMap !== material.roughnessMap ) roughnessMap.dispose();
+		roughnessMap.dispose();
 
 		_renderer.setRenderTarget( oldTarget );
 

+ 1 - 13
src/renderers/WebGLRenderer.js

@@ -2049,21 +2049,9 @@ function WebGLRenderer( parameters = {} ) {
 		const width = Math.floor( texture.image.width * levelScale );
 		const height = Math.floor( texture.image.height * levelScale );
 
-		let glFormat = utils.convert( texture.format );
-
-		if ( capabilities.isWebGL2 ) {
-
-			// Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=1120100
-			// Not needed in Chrome 93+
-
-			if ( glFormat === _gl.RGB ) glFormat = _gl.RGB8;
-			if ( glFormat === _gl.RGBA ) glFormat = _gl.RGBA8;
-
-		}
-
 		textures.setTexture2D( texture, 0 );
 
-		_gl.copyTexImage2D( _gl.TEXTURE_2D, level, glFormat, position.x, position.y, width, height, 0 );
+		_gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height );
 
 		state.unbindTexture();
 

+ 10 - 4
src/renderers/webgl/WebGLTextures.js

@@ -181,9 +181,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 	function getMipLevels( texture, image, supportsMips ) {
 
-		if ( textureNeedsGenerateMipmaps( texture, supportsMips ) === true ) {
-
-			// generated mipmaps via gl.generateMipmap()
+		if ( textureNeedsGenerateMipmaps( texture, supportsMips ) === true || ( texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) ) {
 
 			return Math.log2( Math.max( image.width, image.height ) ) + 1;
 
@@ -793,7 +791,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 		} else if ( texture.isFramebufferTexture ) {
 
-			// texture data extracted from framebuffers require mutuable textures defined via gl.copyTexImage2D()
+			if ( useTexStorage && allocateMemory ) {
+
+				state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height );
+
+			} else {
+
+				state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
+
+			}
 
 		} else {