PDA

View Full Version : Manual glGenerateMipMap generation in C++



RealtimeSlave
08-09-2017, 12:12 PM
Hello,

I am considering replacing glGenerateMipMap with a manual C++ based mipmap generation when
loading normal maps (since I read it makes sense to normalize them for each mip map level
EVEN when the normals will be anyway normalized in the shader later).

Anyone knows code examples for this? Probably a simple box filter should do the trick.

Thanks!

Silence
08-10-2017, 12:11 AM
This (https://graphics.ethz.ch/teaching/former/vc_master_06/Downloads/Mipmaps_1.pdf) might help.

RealtimeSlave
08-13-2017, 05:41 AM
Thanks for the link!

For non power of two textures it seems to be more complicated to achieve good results: http://download.nvidia.com/developer/Papers/2005/NP2_Mipmapping/NP2_Mipmap_Creation.pdf

So for now I restrict my normal maps to power of two dimensions.

I have implemented it this way:

For each pixel:
1. Read 4x RGB values from parent level and convert them to 4 normals
2. Add the 4 normals together and normalize the result
3. Convert the normalized result to RGB again and store it in the current level

Hope that is ok?