Advertisement

Realistic water blending

Started by December 23, 2004 12:54 PM
4 comments, last by Ruudje 19 years, 11 months ago
Does anyone know of good settings for rendering water? In my project I have 1 waterplane, which is at "zero" height (not really though, but it kindof marks the zero-plain of my virtual game-world) It's drawn like so:

void RenderWaterPlain(void)
{
	glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
	glEnable(GL_BLEND);

	glBindTexture(GL_TEXTURE_2D, texture[WaterAnimState].texID);	

	glBegin(GL_QUADS);
		glTexCoord2f(WaterScroll, 0.0f); 
		glVertex3f( 0, WaterHeight, 0 );

		glTexCoord2f(WaterScroll + Map.Mapsize[0] * Map.Gridsize[0], 0.0f); 
		glVertex3f( Map.Mapsize[0] * Map.Gridsize[0], WaterHeight, 0);

		glTexCoord2f(WaterScroll + Map.Mapsize[0] * Map.Gridsize[0], Map.Mapsize[1] * Map.Gridsize[1]); 
		glVertex3f( Map.Mapsize[0] * Map.Gridsize[0], WaterHeight, Map.Mapsize[1] * Map.Gridsize[1]);

		glTexCoord2f(WaterScroll, Map.Mapsize[1] * Map.Gridsize[1]); 
		glVertex3f( 0, WaterHeight, Map.Mapsize[1] * Map.Gridsize[1]);
	glEnd();

	glDisable(GL_BLEND);
	glColor4f(1.0f,1.0f,1.0f,1.0f);

	WaterScroll = float(timeGetTime()) / 40000;

	if(timeGetTime() - WaterLastUpdate > 50)
	{
		WaterAnimState++;
		WaterLastUpdate = timeGetTime();
	}

	if(WaterAnimState > 31) 
		WaterAnimState = 0;
}
Any advise?
pixel shaders
Advertisement
problem is that pixel shaders don't control blending.

Unless you go to the extreme of rendering to a texture both the contents under the water and above (reflection), and use a shader to blend between these - with ripples and the like distorting the image.

But I doubt you're going to go that far.

You will end up most likly needing to use multiple layers to get the effect you want. Or multitexutring, or maybe both.

Battlefield 1942, for example has very simple water, but it looks farily nice. All it is, is standard alpha blending (one_minus_src_alpha, src_alpha) - and the vertex colour's alpha is used here - which is set to an approximate depth of the water. So as the water gets shallow, it fades out. The water surface it'self uses two textures, moving in different directions, and modulated together.. which gives a fairly good water look for very cheap. On top there is also a lot of specular reflection from the sun light which helps. I think they may also fudge the alpha a bit with a texture..
You should note that this effect is most likly achieved with combiners.

well thats battlefield anywho
It currently looks like this:

Sample

The caustig-effect is animated
The waterplane slowly scrolls back and forth
The heightlevel slowly varies (sinus)

There is currently no shading ni the render as I have yet to decide to use a realistic (with shades) or toon-like rendermethod.

The world is tile-based but the water is 1 large plane.
that doesn't really look all that bad. Maybe if the texture was darker it would blend in more.
I think the main goal of water is that you don't notice it.. When it stands out screaming at you then you have a problem.
Consider just using generic alpha blending, just with very very slight transperency. Maybe draw another layer before hand, modulating (like you currently do, just not 2x modulate) with a very light blue, to get a very slight blue tint. Later on, if you add a sky box, you could then go ahead and add a shader to reflect the sky box with a bit of rippling.

The problem with a single flat infinite plane representing the water is:
a) floating point innacuracy means the plane can 'jitter' on the near clip plane,
and b) it's more difficult to do depth-dependant effects (like fade out) - unless you have a 'depth map' texture.
The whole project was "inspired" by an old game some of you may know ;) it's called Transport Tycoon. I'm probably going for a somewhat toon-like appearence. Outlining shapes maybe etc. So I think I'll keep it like this for now.. I didnt like it when it showed more of the land underwater..

This topic is closed to new replies.

Advertisement