Jump to content
  • Advertisement
Sign in to follow this  

FBO's and mipmapping (water-rendering)

This topic is 4334 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

Hi, I'm working on a simple water demo, the rendering goes fine but I'm having some artifacts and i'd like to finetune them now the development is nearing the end. As you can see on this screenshot I'm having some graphical glitches near the horizon. The further you see the less detail you should notice on the water, this isn't the case here. I can imagine this has something to do with mipmapping (or better: the lack of mipmapping). As you see on this screenshot it's not always very noticable, though it's there and I'd like to fix it. I tried using some fog-like-thingy but this doesn't do the trick and looks very fake when there is a background, like on this screenshot I'm using FBO's but I can't find a way to generate mipmaps for my textures. Please note that the textures are not static (they are animated and regenerated now and then) so I should have to recalculate the mipmaps aswell. I did some searching about it and found that I should use glGenerateMipmapEXT() for this. Though perhaps I'm doing something wrong, but I'm pretty sure no mipmaps are being generated. Here is my code:
//Generation of the FBO (happens at initialisation time)
glGenFramebuffersEXT( 1, &rt->frameID );
glGenRenderbuffersEXT( 1, &rt->depthID );

glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rt->depthID );
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height );

glGenTextures( 1, &tex->textureID );
glBindTexture( GL_TEXTURE_2D, tex->textureID );


glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 
		          width, height, 
		          0, GL_RGB, GL_UNSIGNED_BYTE, 0 );

//Render to the FBO (happens almost every frame)
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rt->frameID );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, rt->texture->textureID, 0 );

//generate mipmaps for the FBO

If someone would take some time to look at the code I would be much obliged :) Thank you!

Share this post

Link to post
Share on other sites
When setting up you're texture you're only using GL_LINEAR (i.e. no mip mapping). Use one of the mipmapping filtering modes, e.g. GL_LINEAR_MIPMAP_LINEAR

Share this post

Link to post
Share on other sites
Well, I played around with your suggestion but the situation now is worse.

Let me further explain my situation:
To animate and shade the water I generate perlin noise for which I calculate a normal map in a shader (by rendering it to a FBO, so I can use it later as a texture). Using the normal-map I calculate the reflections/refractions on the water. It's that normal-map that gives problems in the distance, due to the rasterisation problems you see on the screenshots.
Using your method to calculate mipmaps, the normal map seems to somehow get corrupt (it seems the texture gets zero'd out)

Meanwhile I tried something else: I tried manipulating the texturecoordinates based on the distance in a shader (the further away, the more it get's stretched) but this introduces visible "lines" between different "stretch zones". More zones would solve this, but it doesn't seem like the best sollution to me.

Perhaps someone here has experience with rendering huge bodies of water? Yann_L comes to mind :)

Nontheless, thanks for the help!

Share this post

Link to post
Share on other sites

When activating GL_LINEAR_MIPMAP_LINEAR in GL_TEXTURE_MIN_FILTER you said your mipmaps were blank. Was also the main texture (level 0) blank?
Are you sure your FBO was attached correctly?

I had a similar problem, receive GL_FRAMEBUFFER_UNSUPPORTED_EXT from nVidia (7300 go) and another GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT from ATI (x1800xl) when trying to attach textures with GL_LINEAR_MIPMAP_LINEAR.

The only workaround I found is to setup the GL_TEXTURE_MIN_FILTER as GL_LINEAR or GL_NEAREST when activating the FBO, then re-enable the GL_LINEAR_MIPMAP_LINEAR, build the mipmaps and use the textures.

Hope it helps.

Share this post

Link to post
Share on other sites
Using your method to calculate mipmaps, the normal map seems to somehow get corrupt (it seems the texture gets zero'd out)

If not all mipmaps are present, and OpenGL is expecting there are, your texture will be white, even level 0.

I've never has this problem with noisy reflections near the horizon, never understood why many demos/games even have this problem. One thing I did notice in my own water is that the normal map bumps must be very subtle:


I think that when the normalmap angles vary to much the mipmaps will cause problems, even when they are normalized. Not sure though.

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!