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

wishlist: mipmaps for textures #99

Open
claudeha opened this issue Jun 6, 2022 · 0 comments
Open

wishlist: mipmaps for textures #99

claudeha opened this issue Jun 6, 2022 · 0 comments

Comments

@claudeha
Copy link

claudeha commented Jun 6, 2022

Mipmapping is a technique using multiple downscaled levels of texture to improve quality (reduced aliasing) when displaying textures smaller than the resolution of the base level.

Shadertoy website has a few options for channel images: filter mode (nearest / linear / mipmap) , wrap mode (clamp / repeat), flipping (none / vertical).

There are two steps involved, first use glGenerateMipmap() (supported in OpenGLES 2+, OpenGL 3+) after changing texture base level data to generate the downscaled levels, then using glTexParameteri() with GL_TEXTURE_MIN_FILTER GL_LINEAR_MIPMAP_LINEAR. (Other minification filters are available, but linear/linear should be a good default to start with.)

This would allow some cool things to be done apart from improved quality of images: for just one example you can compare the sample from the base level with a sample from a downscaled level (which gives a local average) to do simple peak detection (I currently do this in my shader for the FFT channel of the audio texture by looping over a neighbourhood and reading the texture multiple times, which is very inefficient - it could be two texture reads with mipmaps).

Note: generating mipmaps for large textures can be performance intensive for the GPU (especially if you need to do it every frame), so if my other wishlist item for multliple buffers/shaders gets implemented, there would need to be a way to turn it off for selected buffers and just use GL_NEAREST for texture filtering. The audio texture should be small enough not to need this turning off but an option might not hurt.

Note: if glGenerateMipmap() is not available (desktop OpenGL < 3 and no suitable extension), you can do it yourself with framebuffers from OpenGL extensions (they are not in core until OpenGL 3+) or as a last resort by downscaling on the CPU and uploading each level to the GPU texture separately (probably not worth doing that though).

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

No branches or pull requests

1 participant