Full world fog

Are there any way to add a full-world fog? A fog thgat basically is all around you to fade out objects too far away. So that i can hide the cameras far furstum in a nice way?

Do i need to find a custom fog-shader somewhere or should i use particles?

Or are there already a premade fog functionality in jme3?

There is no fog in JME3 for now, it’s still on the todo list.

An alternative could be to create a 2D filter using the linear depth buffer in a shader.

look this tutorial, it explains how to create a per-pixel fog effect

http://www.ozone3d.net/tutorials/glsl_fog/p04.php

nehon said:
There is no fog in JME3 for now, it's still on the todo list.
An alternative could be to create a 2D filter using the linear depth buffer in a shader.
look this tutorial, it explains how to create a per-pixel fog effect
http://www.ozone3d.net/tutorials/glsl_fog/p04.php


But how do i use a GLSL shader in JME3? Do i need to write a material script? And how do i apply it to the entire world?

read this for a complete material overview:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:materials_overview

this for an explanation on shaders and JME3

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:jme3_shaders



Then you’ll have to create your own filter and use the FilterPostProcessor.

The idea is to render the scene to a texture and then display the scene on a full screen quad, and blend the fog on this quad.

ok since it’s a pretty common need, I made a Fog filter for JME3.



Check the last svn revision.

Usage is :



FilterPostProcessor fpp=new FilterPostProcessor(assetManager);

fog=new FogFilter();

fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));

fog.setFogDistance(155);

fog.setFogDensity(2.0f);

fpp.addFilter(fog);

viewPort.addProcessor(fpp);



See TestFog for a complete example



here is a screen





Note that this is a temporary workaround to have fog in JME3, and this will be deprecated sooner or later.

3 Likes

Nehon is… The post processing mastah! :smiley:



Cheers!

~FlaH

Good to see that this feature has made it in, even as a temporary fix :slight_smile:

Too bad it didn’t make it in time for Halloween, spookey!



So, does the 2D implementation mean that, even when the more advanced version is available, this one might still be relevant as the “low-fi” fog?

Not really, Fog can be computed in the main rendered scene, we are planning to implement it through shader injection (the famous!!).

It will be quicker.

Beside, this implementation has some draw backs, like it can’t be anti-aliased, it won’t appear in water reflection, etc…

Once the proper implementation is there, there will be no reason to use this one.

But…since shader injection is “the big chunk”, and won’t come until beta, i guess, this filter will do the trick.

@nehon Will it be posted on the Effects documentation page?

iamcreasy said:
@nehon Will it be posted on the Effects documentation page?

Probably not, whats there to document?? Also as said its only a temporary solution.

what’s the long-term solution?

Shader injections that make any material “foggy” on demand.

i was asking whether there will be a link to the TestFog code, like SSAO.

Its in the sources, jme3test package.

I added the link to jme3test to the effects overview for now, so people see how far we are and that we’re working on it.