-
Notifications
You must be signed in to change notification settings - Fork 41
Description
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).