water plane extends to infinity

Started by
6 comments, last by nooan 18 years, 8 months ago
How do games like FarCry extend the water plane out to infinity ?
Author Freeworld3Dhttp://www.freeworld3d.org
Advertisement
Probably have a super-huge quad that covers a very large area. Far Cry's water actually doesn't extend out to infinity. I've seen some user made maps in which the water DOES end.

If you do want literally infinite water though, you could make a trapezoid or quad that always has one 'side' where the camera is, perpindicular to the view direction, and another side at the cam's far plane.
I haven't seen FarCry's water, but assuming it is just a flat quad(2 triangles) you could do something like the following:

Have 9 quads, each 2 triangles. These would be of the same size, but have different positions. They would look like this:

+--+--+--+|  |  |  |+--+--+--+|  |  |  |+--+--+--+|  |  |  |+--+--+--+


Then if we assume the constants QUAD_WIDTH and QUAD_HEIGHT is the width and height of a single quad and PlayerX and PlayerY is the players x and y coordinate. Each quad should be assigned to exactly tha same texture, shaders, materials etc. So you wouldn't see if all quads was moved along the x or y axis by QUAD_WIDTH or QUAD_HEIGHT. All you need to do is transform the quad so the middle is under the player. In pseudo code(In comments I will explain what happen if player pos is 200,100:

// Calculationsstatic const uint QUAD_WIDTH  = 75;static const uint QUAD_HEIGHT = 75;int XIndex = QUAD_WIDTH/PlayerX; // 200/75 == 2int YIndex = QUAD_HEIGHT/PlayerY; // 100/75 == 1// Subtract one because the XIndex is relative to// the middle quad, but we need relative to left.QuadXTrans = (XIndex-1)*QUAD_WIDTH;    // Subtract one because the YIndex is relative to// the middle quad, but we need relative to bottom.QuadYTrans = (YIndex-1)*QUAD_HEIGHT;//RenderingTransformWorld(Vector3(QuadXTrans,QuadYTrans,WATER_HEIGHT));DrawQuads(WaterQuads,    9 // 9 quads.    );
Perhaps using a technique like this one?

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Quote:Original post by superpig
Perhaps using a technique like this one?


I actually looked at this one and its just a big quad.
Author Freeworld3Dhttp://www.freeworld3d.org
Quote:Original post by oconnellseanm
Quote:Original post by superpig
Perhaps using a technique like this one?


I actually looked at this one and its just a big quad.


Basically, yeah. Pretty, ain't it?

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Yeah the projected grid has a very nice effect. As well as not needing to worry about LOD since it always uses the same number of polys to render no matter the distance from the camera.

That paper however talks about having a second frustum and keeping track of the crazy projector. But a friend and I found that if you do one or two extra collision steps the projector does not back fire anymore, and you get the same results. The only problem was worrying about the depth however to fix this you just set the projection a bit wider. So instead of -1....1 you just grow it depending on the depth you have set. I just played with numbers, so it was not very scientific, anyhow it projected from a slightly wider range to cover up the edges when the swells animated.

I like the idea just not the projector.
The projected grid approach is very interesting and it was employed not only in the aforementioned paper but also in NVidia's Clear Sailing demo (a bad implementation though). It is a very good approach for rendering infinite water areas as an ocean with automatic LOD. One drawback is that water is basically drawn everywhere, which might be a problem in a complete terrain engine (though tricks exist to mask out unwanted areas).
With regards to the projected grid paper, I honestly found the proposed hack of using a modified projector unnecessary. That implementation also suffers from the fact that the number of used triangles is independent of the actual screen area covered by water. Thus, in patological situations (when looking upwards) you can have the full vertex buffer covering only few rows of pixels. I figured out a simple and robust procedure to overcome those issues. If you are interested I can detail the algorithm here.
A simpler technique to fake infinite water is that of rendering a large quad which fades to the same horizon colour of the sky (I guess Far Cry uses this approach).

Cheers
Stefano LanzaTyphoon Engine

This topic is closed to new replies.

Advertisement