Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLRenderer: Always generate mipmaps when "generateMipmaps" is true. #29677

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

gkjohnson
Copy link
Collaborator

@gkjohnson gkjohnson commented Oct 17, 2024

Fixed #18861

Description

Change the behavior of Texture mipmap generation to always respect the generateMipmaps flag. Previously mipmaps would only be generated when "minFilter" and "magFilter" required mip maps, as well, but with default support for textureLod in WebGL2 and textureSampleLevel in WebGPU, filtering is no longer the only way to use mipmaps.

This change will mean that mipmaps will be generated for all non-data textures by default; even when users set filtering to use NEAREST. This will potentially result in higher memory usage and a (small?) performance cost even if they're not used.

@gkjohnson gkjohnson added this to the r170 milestone Oct 17, 2024
Copy link

github-actions bot commented Oct 17, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 690.8
171.12
690.77
171.12
-36 B
-3 B
WebGPU 816.43
220.08
816.39
220.05
-44 B
-22 B
WebGPU Nodes 815.94
219.95
815.9
219.92
-44 B
-22 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 463.45
111.9
463.41
111.89
-34 B
-3 B
WebGPU 538.61
145.41
538.57
145.38
-42 B
-25 B
WebGPU Nodes 494.73
135.28
494.69
135.26
-42 B
-17 B

@gkjohnson gkjohnson marked this pull request as draft October 17, 2024 07:05
@gkjohnson gkjohnson marked this pull request as ready for review October 17, 2024 07:06
@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 17, 2024

To better reflect the change, we should update example code that uses nearest or linear filtering without requiring mipmaps. E.g.: webgl_materials_texture_filters.

Looking at this specific example, the textures texturePainting, texturePainting2 and textureCanvas2 should now set generateMipmaps to false.

WebGPURenderer must also be updated in this PR. The relevant line is:

return ( texture.isCompressedTexture === true ) || ( ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter ) );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mipmaps are not generated if minFilter is set to NearestFilter or LinearFilter
2 participants