#include "/Lib/BasicFunctions/LightingConstants.glsl" // MinecraftPT — Volumetric Fog // Height-based volumetric fog with 3D noise, ray marched in the volumetric pass. #ifndef VOLUMETRIC_FOG_GLSL uniform sampler3D CloudNoise3D; #define VOLUMETRIC_FOG_GLSL // Fog density at a world position (height + noise) float GetVolumetricFogDensity(vec3 worldPos, float time){ float height = worldPos.y; // Two-layer height fog float density = VFOG_DENSITY_BASE; density += exp(-(height - VFOG_HEIGHT) * VFOG_FALLOFF) * VFOG_DENSITY; density += exp(-(height - VFOG_HEIGHT_2) * VFOG_FALLOFF * 2.0) * VFOG_DENSITY * 0.5; // Noise variation #ifdef VFOG_NOISE_TYPE if (VFOG_NOISE_TYPE > 0){ vec3 p = worldPos * vec3(VFOG_NOISE_HORIZONTAL_SCALE, VFOG_NOISE_VERTICAL_SCALE, VFOG_NOISE_HORIZONTAL_SCALE) + vec3(time * 0.01, 0.0, time * 0.008); float n = 0.0; float amp = 0.5; for (int i = 0; i < VFOG_NOISE_OCTAVE; i++){ n += textureLod(CloudNoise3D, fract(p), 0.0).r * amp; p *= 2.0; amp *= 0.5; } density *= 1.0 + (n - 0.5) * VFOG_NOISE_COVERAGE * 2.0; } #endif // Rain fog boost density *= 1.0 + wetness * VFOG_RAIN_DENSITY_MUL; return max(density, 0.0); } // In-scattering color for fog (sun + sky) vec3 GetFogColor(vec3 worldPos, vec3 sunDir){ vec3 sunColor = GetSunIrradiance() * VFOG_SUNLIGHT_DENSITY; vec3 skyColor = GetAtmoIrradiance(); return skyColor + sunColor * 0.5; } #endif