fenomas

Fog is closer at center of view

Recommended Posts

Hi,

I'm trying out the fog feature in a scene, and having trouble getting it behave in a way that makes sense visually.

The trouble is, linear fog is much stronger in the center of the viewport than at the edges. E.g in this demo - at first you should see a certain number of cubes directly in front of the camera, but if you rotate the camera you'll be able to see a further cube that wasn't visible initially.

I assume this happens because fog distance is being calculated as distance from the camera along the camera vector, rather than just distance from the camera.

Is this a bug, or a feature, or something that can be worked around? Thanks!

Share this post


Link to post
Share on other sites

Even as if you look down (move the camera angle towards the ground) more cubes become visible - it seems that the fog behaves as if it were attached to the camera and not as fog within the 3d world.

Share this post


Link to post
Share on other sites
1 hour ago, jpdev said:

Even as if you look down (move the camera angle towards the ground) more cubes become visible

Yes, that's the same issue. The cubes appear or disappear depending on how close they are to the camera vector (either horizontally or vertically).

Share this post


Link to post
Share on other sites

Looks like fog depends on Z value of Z-buffer instead of using the calculated distance from camera.
I have seen this effect in many games.
Probably fog which depends on distance works much slower, but it should be possible to modify shader in that way.

Share this post


Link to post
Share on other sites

It is not a physical fog but a distance fog.

Distance is computed here:

https://github.com/BabylonJS/Babylon.js/blob/master/src/Shaders/ShadersInclude/fogVertex.fx

As you can see the distance if from the vertex to the camera (on z axis). 

 

It is fairly easy to change it to len( (view * worldPos) ) which, I agree, makes more sense

 

Share this post


Link to post
Share on other sites

Whoa. It now looks much better. Does it change performance much?
Maybe it makes sense to add this feature as an option in fog settings, for example as

scene.fogMode=BABYLON.Scene.FOGMODE_LINEAR_DISTANCE |  FOGMODE_EXP_DISTANCE | FOGMODE_EXP2_DISTANCE

?

Share this post


Link to post
Share on other sites

Wow this looks nice!!!

It is now just one step from what I planned, the layered fog.
When the fog density is linearly or exponentially decreases with height.

Is that height, world y position of vertex  worldPos.y? so worldPos .y does not depend on camera position or direction?
 

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

  • Recently Browsing   0 members

    No registered users viewing this page.