Ok. I’ve merged the fog for Lighting.j3md (single and multi-pass) and shortly will do the same for PBRLighting. I’ll update the docs, but I’ll write it here for now.
There are 3 types of fog:
- linear (cheapest, best for android).
- exponential (medium, better than linear).
- exponential squared (best, most expensive).
Enable fog by setting “UseFog” to true in your material and setting a “FogColor”.
material.setBoolean("UseFog", true);
material.setColor("FogColor", new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f);
To determine the type of fog you’ll use, set the value for the fog you require.
Linear Fog
For linear fog you set a start and end value. The start value determines when the fog starts fading in and the end value determines when the fading will end. Any distance before start will not have fog and any distance after end will have full fog.
float start = 10.0f;
float end = 60.0f;
material.setVector2("LinearFog", new Vector2f(start , end));
The graph below shows the level of fog as a minimum distance of 10 and maximum distance of 60.
Exponential fog
Pretty simple stuff. It follows an exponential line. The larger the number the quicker the fog will reach full fog. The smaller the number the longer it will take to reach full fog.
float exp = 0.015f;
material.setFloat("ExpFog", exp);
Exponential Squared
Again - basic math functions. This method takes longer to fade in before “jumping” to a full rapid fade increase.
float expsq = 0.02f;
material.setFloat("ExpSqFog", expsq);
The image below shows all three functions together. Each line shows the increase in fog level over distance.
- Red - Linear
- Green - Exponential
- Blue - Exponential Squared.
And finally, there is a test class available for those that speak code better than English