Jump to content

Still no Fog?


Andy Gilbert
 Share

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

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

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.

Stop toying and make games

Link to comment
Share on other sites

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

  • Upvote 1

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

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
  • Upvote 2

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

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

The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do.

 

Leadwerks Game-Ready 3D Models:https://sellfy.com/gib3d

Link to comment
Share on other sites

  • 2 years later...

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

I am not silly. My english is just not really great. T_T

But I'm learning! :D

Link to comment
Share on other sites

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.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...