Volume fog shader? (underwater space)

Started by
4 comments, last by solenoidz 14 years ago
hello there, I've been looking for a way to make an underwater area look nice. so far I've got the water surface with a nice shader, but I still need some effects for what goes on below that water surface. I reckon the first thing to have is a blue-ish fog, since the density of the water causes much less viewing distance (or something like that). so anyway, I've been looking for a way to do this, and since my engine (Nebula2) only uses linear fog (added through a post-process I believe), and since I have several water volumes at different heights (ie. the sea and other lakes up some hills), I thought the best way would be using a fog volume (or what I think it is: I make a box and apply a special shader to it, which draws fog inside of it instead of the box outer faces) so I've been looking for any sample of such shader, but I've had no luck. this seems to be an old topic (I found a reference to the DXSDK 8.1 samples, but mine only has samples from DX9 and up - and nothing about fog), so perhaps there's already an easy solution out there. anyone know of any? my engine uses DX9 btw, so a DX9 HLSL shader would be best. thanks later

Chosker - Developer of Elium - Prison Escape

Advertisement
Someone answer this topic Im interested in this too!!!!
Quote:
which draws fog inside of it instead of the box outer faces


I'm not sure there is such a technique as this, the only thing a gpu really does is draw triangles, I've never heard of being able to render a volume.

If you want to render a volume I would think you would need to fake it by drawing several planes that intersect the volume. Like for example you can align a series of transparent blue planes beneath the water surface, such that the deeper the water is the more planes that will be overlapping the water floor (and thus be darker and bluer). Might need to come up with an interesting idea to hide the discrete depth steps though or it will look unnatural.

Another idea I had was if you can associate the vertices on the ocean floor with a special shader. You could pass a uniform plane to the shader (the top of the water) as well as the eye position. You can draw a line between the eye and the vertex, and then intersect this line with the water top plane. Then you could use this to figure out the distance between the plane and the vertex, and color the floor vertex based on this distance.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Quote:I'm not sure there is such a technique as this, the only thing a gpu really does is draw triangles, I've never heard of being able to render a volume.

well I want some fog with a Z limit instead of just a depth limit. as seen in quake3 (fog only near the floor).

Quote:Another idea I had was if you can associate the vertices on the ocean floor with a special shader. You could pass a uniform plane to the shader (the top of the water) as well as the eye position. You can draw a line between the eye and the vertex, and then intersect this line with the water top plane. Then you could use this to figure out the distance between the plane and the vertex, and color the floor vertex based on this distance.

while it's not a bad idea, it wouldn't affect other underwater objects, therefore it wouldn't be fog


anyone else has any ideas on doing underwater fog? I mean a lot of games do it

Chosker - Developer of Elium - Prison Escape

Siggraph 2006 had an presentation on this subject. The slides can be found here. Along with some other interesting stuff, you'll find fog volumes on page 21 up to and including 25.

They use Direct3D 10. I don't know if this can be coded in Direct3D 9.

Emiel1
If you have seas and lakes, can't you just test your camera position against the Bounding box of each lake water volume and sea and if your camera is in the box then apply your post-processing fog as you normally do. If you have full-screen depth rendered already, you can reconstruct world-space position of each pixel on screen and check if it's bellow you water plane, so you can apply fog to underwater scenes even if you are looking from above the water surface or to make soft fade out and beach foam if the Y position of the pixel if close enough to Y position of the terrain, i.e the water plane and terrain mesh intersect there.

[Edited by - solenoidz on April 3, 2010 6:31:04 AM]

This topic is closed to new replies.

Advertisement