Skip to content

Commit d80a715

Browse files
elalishMugen87
andauthored
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 <michael.herzog@human-interactive.org>
1 parent 0225997 commit d80a715

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

examples/jsm/utils/RoughnessMipmapper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ class RoughnessMipmapper {
119119

120120
_renderer.copyFramebufferToTexture( position, material.roughnessMap, mip );
121121

122+
_mipmapMaterial.uniforms.roughnessMap.value = material.roughnessMap;
123+
122124
}
123125

124-
if ( roughnessMap !== material.roughnessMap ) roughnessMap.dispose();
126+
roughnessMap.dispose();
125127

126128
_renderer.setRenderTarget( oldTarget );
127129

src/renderers/WebGLRenderer.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,21 +2049,9 @@ function WebGLRenderer( parameters = {} ) {
20492049
const width = Math.floor( texture.image.width * levelScale );
20502050
const height = Math.floor( texture.image.height * levelScale );
20512051

2052-
let glFormat = utils.convert( texture.format );
2053-
2054-
if ( capabilities.isWebGL2 ) {
2055-
2056-
// Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=1120100
2057-
// Not needed in Chrome 93+
2058-
2059-
if ( glFormat === _gl.RGB ) glFormat = _gl.RGB8;
2060-
if ( glFormat === _gl.RGBA ) glFormat = _gl.RGBA8;
2061-
2062-
}
2063-
20642052
textures.setTexture2D( texture, 0 );
20652053

2066-
_gl.copyTexImage2D( _gl.TEXTURE_2D, level, glFormat, position.x, position.y, width, height, 0 );
2054+
_gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height );
20672055

20682056
state.unbindTexture();
20692057

src/renderers/webgl/WebGLTextures.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
181181

182182
function getMipLevels( texture, image, supportsMips ) {
183183

184-
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) === true ) {
185-
186-
// generated mipmaps via gl.generateMipmap()
184+
if ( textureNeedsGenerateMipmaps( texture, supportsMips ) === true || ( texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) ) {
187185

188186
return Math.log2( Math.max( image.width, image.height ) ) + 1;
189187

@@ -793,7 +791,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
793791

794792
} else if ( texture.isFramebufferTexture ) {
795793

796-
// texture data extracted from framebuffers require mutuable textures defined via gl.copyTexImage2D()
794+
if ( useTexStorage && allocateMemory ) {
795+
796+
state.texStorage2D( _gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height );
797+
798+
} else {
799+
800+
state.texImage2D( _gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
801+
802+
}
797803

798804
} else {
799805

0 commit comments

Comments
 (0)