Sign in to follow this  
HolyFish

FBO's and mipmapping (water-rendering)

Recommended Posts

HolyFish    127
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 );

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

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 );
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rt->depthID );

//generate mipmaps for the FBO
glGenerateMipmapEXT(GL_TEXTURE_2D);

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
coordz    130
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
HolyFish    127
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
pansk    122

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
remdul    176
Quote:
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:

normalmap
result

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this