Sign in to follow this  
Jalien

OpenGL Volumetric fog shader

Recommended Posts

I just want to get the effect as the picture shows:
[img]http://i885.photobucket.com/albums/ac52/SuperJalien/volumetricfog.jpg[/img]
I use the OpenGL extention GL_EXT_fog_coord to implement volumetric fog, but, it seems to be the whole screen is filled with fog,why?
For the purpose of studing,I want to use cg shader to implement volumetric fog.Does anyone get it?I found little information about it.
I have spent a lot of time on it,but little progress I get. :(
Any help will be apreciated.

Share this post


Link to post
Share on other sites
[quote name='Jalien' timestamp='1306596248' post='4816790']I just want to get the effect as the picture shows:[/quote]To get the "volumetric cube of fog" in the picture, for each pixel, you need to calculate the ray from that pixel to the camera, and then calculate the distance that the ray passes through the fog volume.
If the fog is a box, then you can perform a ray-box intersection test in your fragment shader to find the entry/exit points and measure the distance between them.
[quote]I use the OpenGL extention GL_EXT_fog_coord to implement volumetric fog, but, it seems to be the whole screen is filled with fog,why?[/quote]To answer "[i]why?[/i]" you'd have to tell us what you did with GL_EXT_fog_coord, and what you expected it to do.
That extension is designed to allow you to specify per-vertex fog in the fixed-function pipeline.

Share this post


Link to post
Share on other sites
Thanks for your reply.[img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img][quote name='Hodgman' timestamp='1306597338' post='4816796']
for each pixel, you need to calculate the ray from that pixel to the camera, and then calculate the distance that the ray passes through the fog volume.
If the fog is a box, then you can perform a ray-box intersection test in your fragment shader to find the entry/exit points and measure the distance between them.
[/quote]
Maybe I should learn something about ray-box intersection." for each pixel",Do you mean that I should use pixel shader? and "perform a ray-box intersection test in your fragment shader ", or fragment shader? I just don't know how to perform piexl operation.
[quote]
To answer "[i]why?[/i]" you'd have to tell us what you did with GL_EXT_fog_coord, and what you expected it to do.
That extension is designed to allow you to specify per-vertex fog in the fixed-function pipeline.
[/quote]
The source code is on the other computer. I used it in another engine. The engine offerd an interface for us to embed OpenGL code,I just use the GL_EXT_fog_coord to implement
volumetric fog as NeHe's lesson 41,and then draw my scene. I just want to use it to simluate visibility underwater, the fog should exist only underwater.

Thanks you again.[img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img]

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