Using fog filter

Hello,

I have troubles understanding how fog works in JMonkeyEngine.
In the previous technologies i used, i had to define the color and distance of fog:

  • if it was configured to 100 meters, objects at 10 meters were almost untouched.
  • at 50 meters they were half fog color and half normal color.
  • at 90 meters they were almost fog colored.
  • at 100 and further, they were invisible because at full fog color.

In some technologies, i had possibility to also define a start distance (fog color start at start distance instead of 0) or also the final density (if 0.5 for instance, objects at 100 and further were just half fog color, half normal color).

In JME, there is a distance and a density as parameter of a fog filter. But when i tried several values, nothing looks like what i would expect:

  • With density of 1.0 and distance of 100, it look like i look at my game behind a (dirty) windows: everything is affected equally by fog color, like 50%, distance almost don’t play a role.
  • with density of 0.5 and distance of 1000, there is a slight fog around.

Is there something i didn’t understand or something i did wrong ?

Here is the code i use:

fpp = new FilterPostProcessor(assetManager);
fog = new FogFilter(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f), 1.0f, 100f);
fpp.addFilter(fog);

Thanks in advance,

Ga3L

I think you may have to just play with the values. For example, what does 1000 distance and 1 density do?

In the end, I suspect you will be very disappointed with a post-processing fog. It sounds like you are used to shader fog. There are posts around on the forum where folks have forked JME’s Lighting shader to support fog. (It’s actually one of the simpler shader projects to do if you were ever interested in learning a little about shaders.)

Unfortunately, for whatever reason, JME never included fog support by default in its lighting shader (or PBR). I think the excuse was always that it could be wired in with shader nodes… but that would have required lighting and/or PBR to have been converted to Shader Nodes format.

It’s the best place for it, though… because being able to set different fog for different materials is really great. You can also have fog change near the ground and so on. All things impossible with the post-processing Fog that only has access to the rendered screen and depth buffer to do its thing (ie: it will even fog the sky box or in-scene UI elements which is frequently undesirable.)

3 Likes

However if you are a lazy dude and dont yet want to spend time converting the shaders to support fog because you want to focus on doing the super important stuff, you might want to give my post processing fog a try :smiley:

probably big bummer for you up front: it doesnt work the way you are used to with distance and density values, instead you define a plane that seperates fogged from non-fogged area and for the fogged area you can define a density factor, however as soon as you’re in the fogged area, fog starts right infront of you (dependant on the density there is no fog though right infront of you) and increases linearly based on the density you provided

it is a postprocessing effect, however it allows fog to get thicker towards the ground and its easier to plug in than converting all the shaders you are using probably

1 Like