Addendum:
If I in the shader already retract the position in the 3d space, then the implementation of the nebulization is almost forced:
I just have to calculate the distance to the camera to know the intensity of the cloud. And since I also know “y”, I can represent the cloud as a gradient. Dark and somewhat moddy below, rather light gray above.
The heart of the fog is this snippet of code from the frag-shader:
#if defined(HAS_FOG) || defined(HAS_MAGICMARKMAP) || defined(HAS_MAGICMARKINDEX1) || defined(HAS_MAGICMARKINDEX2)
vec4 worldPos = g_WorldMatrix * vec4(position, 1.0);
float rP;
float rR;
float reduction;
#endif
(…)
#ifdef HAS_FOG
float fog_x= m_FogCamPos.x - worldPos.x;
float fog_z= m_FogCamPos.z - worldPos.z;
float fog_y= max(0.0,min(1.0, worldPos.y / m_FogTop));
vec4 fog_color = m_FogStartColorUp*fog_y + m_FogStartColor0*(1.0-fog_y);
rP = max(0.0, fog_x*fog_x + fog_z*fog_z - m_FogStartDistanceSqr);
rR = min(1.0, rP / m_FogDistanceSqr);
color =fog_color*rR + color*(1.0-rR);
#endif
The new MaterialParameters are:
Vector3 FogCamPos // x-y-z camera position in 3d space, clear Param == fog is off
Float FogStartDistanceSqr // Start distance ^2
Color FogStartColor0 // Start color on y == 0
Float FogTop // y of FogStartColorUp
Color FogStartColorUp // Start color on y == FogTop
Float FogDistanceSqr // distance ^2