Jump to content
  • Advertisement
Sign in to follow this  
stalef

Generate MipMap on GPU

This topic is 3953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to generate mipmaps on the GPU? I have a normal map that is generated each frame on the CPU, and I would like to generate mipmaps for it on the GPU if possible. I guess I could make a fragment shader to generate each mipmap level, but is it possible to store the result directly to a texture at a given mipmap level, or do I have to read the result back to CPU memory and then upload to the correct mipmap level? By the way, is it usual to use mipmaps for normal maps?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
I guess I could make a fragment shader to generate each mipmap level
this is the way to go. I remember hardware that supported this but it was done internally in the driver then. You saved the API overhead this way but it should not be much.
You render into a render target and then you read the render target as a texture.

Share this post


Link to post
Share on other sites
Quote:
Original post by stalef
Is it possible to generate mipmaps on the GPU?

Yes - you can do it "manually" the way that you and wolf describe, or you can get the API/hardware to do it for you. Look into "autogen mipmaps" in DirectX or glGenerateMipmaps (or similar) in the OpenGL FBO extension.

Quote:
Original post by stalef
By the way, is it usual to use mipmaps for normal maps?

Yes, although it's not exactly correct. If you're generating them "manually" there are some more clever things that you can do rather than just averaging to downsample. There was an NVIDIA paper and a recent SIGGRAPH paper too on the topic of filtering/mipmapping normal maps.

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyTX
Yes - you can do it "manually" the way that you and wolf describe, or you can get the API/hardware to do it for you. Look into "autogen mipmaps" in DirectX or glGenerateMipmaps (or similar) in the OpenGL FBO extension.


I suspect doing it "manually" will be slow sice it involves "unnecessary" copying between GPU-memmory and CPU-memory and then back again. I do need to do this each frame.

Since the texture contains normals i guess using API/harware to do this would give uncorrect result (this resulting normals would not be normalized etc. )

Quote:
Original post by AndyTX
Yes, although it's not exactly correct. If you're generating them "manually" there are some more clever things that you can do rather than just averaging to downsample. There was an NVIDIA paper and a recent SIGGRAPH paper too on the topic of filtering/mipmapping normal maps.


Thanks, I will look for it. I went to SIGGRAPH, but I guess I missed this....

Share this post


Link to post
Share on other sites
Quote:
Original post by stalef
I suspect doing it "manually" will be slow sice it involves "unnecessary" copying between GPU-memmory and CPU-memory and then back again. I do need to do this each frame.

No, "manually" all on the GPU. One "pass" per mipmap, going from the top down each pass reading from the results of the previous one and averaging 4 fragments at a time (or just using bilinear filtering if supported for the given texture format). It won't be much slower than the API method since that's all the hardware is doing anyways :)

Quote:
Original post by stalef
Since the texture contains normals i guess using API/harware to do this would give uncorrect result (this resulting normals would not be normalized etc. )

Right, but you can always renormalize on lookup. Note that even bilinear filtering has the same "problem": your normals won't necessarily be normalized. Averaging normals isn't "correct" per se in any case, but it's pretty standard to just use hardware filtering for it anyways.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!