Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Water (reflection/refraction)

This topic is 5818 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 currently working on a 3D engine for a game in which you control a kind of submarine. (I didn't design any of it, I'm just making the graphics engine) In any case, as long as everything is underwater, it's OK. However, the design requires that you come close to the water surface in some parts of the game, and also see it, which of course calls for refraction and reflection. Even worse, there has to be seamless transition between being above and under water. Luckily, the water surface is very limited. However, there is a lot of geometry above whater. This has been bugging me for quite a while, as all the information I could find was for concave pools of water. About an hour ago an idea struck me (bad timing; I'm at work - read: day job - right now) and I immediately had to put it to paper. I also drew it up in PSP: crappy picture (this is the version for when you're underwater; version for above water level is y-flipped, plus reversed refraction) My idea is to perform the following steps: (I'm seeing the water surface from below; it's similar for the inverse case) 1. draw everything underwater 2.* set up camera slightly differently (refraction) and draw everything above water 3. set render target to a texture; render everything under water to that surface (frustum is delimited by the water plane, virtual camera is positioned symmetrically to actual camera above water) - this will be the reflection part 4. set render target to yet another texture and set up virtual camera for refraction and render the scene above water to this texture - this will be the refraction part 5. apply the resulting textures to the water mesh and blend using a fresnel number. (projective texturing) * only if I see anything above water directly, i.e. not through the water plane I'll try to figure out the math over the weekend; My only question is: am I sort of on the right track? Is there a much simpler way of doing this? By the way: the poly count will be reasonable; also, you will be able to disable and possibly scale the water reflection/refraction feature if it kicks the framerate down too much. Oh and I just realized that the order of proceedings is crap. It must be done in this order: 3,4,5,1,2 (Z buffer is enabled) Thanks - JQ Full Speed Games. Period. EDIT: linked image. IMG tag didn't seem to work [edited by - JonnyQuest on August 16, 2002 9:33:54 AM]

Share this post

Link to post
Share on other sites
You're on the right track, that's more or less the standard way of doing water reflections/refractions. The key is to render all the reflected and refracted geometry into two distinct textures, and to apply the projectively to the water surface.

So if you are underwater, everything seen above the water surface will be in the projective texture. Everything below is normally rendered. If you are above the water, the whole thing is reversed. You can see the water surface as a kind of 'portal', everything you see through it (or is reflected by it) will be applied by a projective texture and does not need to be rerendered afterwards.

Little catch though: water has changing reflection/refraction vectors per pixel (or per vertex). It's not a simple constant vector as in a static planar reflection. You have to compute the reflection and refraction vectors at least per vertex to get realistic results. That can be efficiently done by perturbation of the projective texture coordinates (using Snell's law for the refraction).

/ Yann

[edited by - Yann L on August 16, 2002 12:45:49 PM]

Share this post

Link to post
Share on other sites
I am aware of that potential problem - I will however go for a simple approach, as the scenes will never be very deep, the camera movement is limited, so the opening angle at which you see the water plane will always be relatively small, which means that noone will notice if there are slight glitches. Apart from that, noone in the development team apart from myself seems to have a pixel-shader capable graphics card, and my Radeon 8500 is 1500km away right now, so a per-pixel approach is more or less out of the question at the moment.

Thanks anyway for your input - you just gave me an idea in your second paragraph for some possibilities of culling which should greatly improve performance.

Full Speed Games. Period.

EDIT: Grammar si suXX0r!!!
also, my damn sig. will never work as it seems...

[edited by - JonnyQuest on August 16, 2002 1:16:53 PM]

Share this post

Link to post
Share on other sites

  • 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!