fenomas Posted February 10, 2017 Share Posted February 10, 2017 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! jpdev and adam 2 Quote Link to comment Share on other sites More sharing options...
jpdev Posted February 10, 2017 Share Posted February 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
fenomas Posted February 10, 2017 Author Share Posted February 10, 2017 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). Quote Link to comment Share on other sites More sharing options...
ceedee Posted February 10, 2017 Share Posted February 10, 2017 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 10, 2017 Share Posted February 10, 2017 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 Nabroski, jpdev and NasimiAsl 3 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 10, 2017 Share Posted February 10, 2017 Actually I went ahead and did it jerome, NasimiAsl, jpdev and 1 other 4 Quote Link to comment Share on other sites More sharing options...
ceedee Posted February 10, 2017 Share Posted February 10, 2017 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 ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 10, 2017 Share Posted February 10, 2017 Ping @Dad72 Seems like it is not only community based finally davrous 1 Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted February 11, 2017 Share Posted February 11, 2017 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? Quote Link to comment Share on other sites More sharing options...
adam Posted February 11, 2017 Share Posted February 11, 2017 Here is the old fog: https://jsfiddle.net/usxek13s/7/ This new fog is a great improvement. http://playground.babylonjs.com/#1QMRN6#1 jerome, NasimiAsl and jpdev 3 Quote Link to comment Share on other sites More sharing options...
fenomas Posted February 12, 2017 Author Share Posted February 12, 2017 Thanks for the speedy fix DK! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 13, 2017 Share Posted February 13, 2017 @BitOfGold layered fog is a bit more complex as you need to see it even if there is no object to support it. You will probably need to render a quad or something to simulate it Quote Link to comment Share on other sites More sharing options...
Nabroski Posted February 14, 2017 Share Posted February 14, 2017 seems to be the very rare situation where a question was solved. Quote Link to comment Share on other sites More sharing options...
fenomas Posted February 14, 2017 Author Share Posted February 14, 2017 My experience is that most questions get solved here. As long as they're concise and come with a minimal playground Hats off to the developers! jerome and adam 2 Quote Link to comment Share on other sites More sharing options...
Nabroski Posted February 14, 2017 Share Posted February 14, 2017 edit: sorry, i just was confused whether the issue was solved or not. i seems solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.