Jump to content
Andy Gilbert

Still no Fog?

Recommended Posts

I still dont get how we dont have any fog, especially now we have terrain?

 

Im sure OpenGL has fog features out-of-the-box? Cant we just have them?

 

Andy

Share this post


Link to post

Humm ....

Fog and shaders are not compatible from what i read long time ago.

Some special work is needed if you need fog.

 

A cheap solution :

Make several aligned transparent background big planes always facing camera.

By using several transparent layers you'll heav fog impression.

But indeed not as good as real fog.

Share this post


Link to post

YouGroove, i dont want to use transparent backgrounds, otherwise i would do? Ide like to have the ability to turn on fog.

 

This isnt a "find an alternative" forum, its a sugesstions forum? Please stop posting, unnecessary replies.

 

Andy

Share this post


Link to post

If you want to hack in your own fog, add this to the bottom of all fragment shaders you use just before } to add fog.

 

vec4 fog=vec4(1,1,1,0.05); // R,G,B,strength
#define LOG2 1.442695
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = clamp(exp2(-fog.w*fog.w*z*z*LOG2),0.0,1.0);
gl_FragColor = mix(vec4(fog.xyz,1.0), gl_FragColor, fogFactor);

 

For terrain :

 

terrain.shader, just before gl_FragData[0] = outcolor; add :

 

vec4 fog=vec4(1,1,1,0.05); // R,G,B,strength
#define LOG2 1.442695
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = clamp(exp2(-fog.w*fog.w*z*z*LOG2),0.0,1.0);
outcolor = mix(vec4(fog.xyz,1.0), outcolor, fogFactor);

 

A more elegant way would be to add vec4 fog as a uniform and send color and density from your app using SetVec4

 

 

EDIT: sorry Andy if I'm also derailing your post.

Edited by shadmar

Share this post


Link to post

Hi shad, thanks and no derailing going on. :) I very much welcome useful replies. Ill give that ago, it seems like it will do the trick for now. You really are a shader wiz!

 

Thanks shad

 

Andy

Share this post


Link to post

The plan is to create a post-processing list in the editor and then you can just add effects like fog, SSDO, and whatever other crazy effects Shadmar makes.

Share this post


Link to post

Love that. And I mentioned this before but if possible, please make it so that we can set the strength of any effect, especially in our code. Something like SetEffect(fog, 0.5); which would enable fog at half strength. Of course you'd know the better way to implement that function but that's the idea.

Share this post


Link to post

If you want to hack in your own fog, add this to the bottom of all fragment shaders you use just before } to add fog.

 

vec4 fog=vec4(1,1,1,0.05); // R,G,B,strength
#define LOG2 1.442695
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = clamp(exp2(-fog.w*fog.w*z*z*LOG2),0.0,1.0);
gl_FragColor = mix(vec4(fog.xyz,1.0), gl_FragColor, fogFactor);

 

For terrain :

 

terrain.shader, just before gl_FragData[0] = outcolor; add :

 

vec4 fog=vec4(1,1,1,0.05); // R,G,B,strength
#define LOG2 1.442695
float z = gl_FragCoord.z / gl_FragCoord.w;
float fogFactor = clamp(exp2(-fog.w*fog.w*z*z*LOG2),0.0,1.0);
outcolor = mix(vec4(fog.xyz,1.0), outcolor, fogFactor);

 

A more elegant way would be to add vec4 fog as a uniform and send color and density from your app using SetVec4

 

 

EDIT: sorry Andy if I'm also derailing your post.

 

I have a black screen when I put this to ambientlight.shares. I guess it's no more working? :c

Share this post


Link to post

I have a black screen when I put this to ambientlight.shares. I guess it's no more working? :c

ambientlight.shares? the ambientlight.shader? yeah dont do that. This topic was from over two years ago - there have been many updates since then. Also, have you checked the shadmar's Post Effect shaders in the workshop? I believe klepto's fog is available in there.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...