Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLSL Shader Fog

Started by Andrew Lucas Apr 25, 2009 at 2:35 AM 0 replies 2.6k views
Original Post
Andrew Lucas
Andrew Lucas
Hiya. Recently, I was told that I should use GLSL to create fog in my game, because I was having a lot of blending issues. This was basically about capturing the depth buffer to a texture, and using it to calculate fog in a GLSL shader. I was wondering, does anyone have an example of this kind of shader? To be honest I'm a complete newbie with GLSL, and I have no idea how I should do this kind of thing. As far as I understand, I have to capture the screen rectangle texture, the depth buffer into a texture, and pass these down, together with my fog settings to the shader, and let it work on the texture, and then I just render a quad over the screen? I'd be really happy if I could get some guidance, because I'm kinda lost. Thanks. Andrew.
AndyEsser
AndyEsser
Hi Andrew,

I've not used GLSL in this myself, but I'm doing a similar sort of thing.

What you need to do is render your scene to a Framebuffer Object (Framebuffers 101: http://www.gamedev.net/reference/articles/article2331.asp) with a Depth Attachment.

Then you draw this FBO texture onto a fullscreen quad, and have a GLSL shader active. The shader takes the information from the depth texture, and based on the parameters you provide it, will modulate the RGB colour from the Texture with your fog colour, based on the depth.

Lighthouse3D (http://www.lighthouse3d.com/opengl/glsl/) has some great GLSL tutorials.

Sorry I can't be of more use.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.