Powder Effect Formulation for GLSL Clouds

The powder effect is an empirical lighting approximation used in real-time volumetric cloud rendering to simulate complex multiple scattering within dense cloud formations. In GLSL raymarching shaders, integrating the powder effect modifies the standard Beer-Lambert attenuation to create deep contrast and self-shadowing in dense cloud crevices. This prevents forward-scattering highlights from washing out the cloud structure, producing realistic, detailed volumetric cloudscapes.

The Core Concept

In real clouds, water droplets densely scatter light in multiple directions. Standard single-scattering models rely on the Beer-Lambert law, which states that light transmittance decreases exponentially with optical depth:

\[T = e^{-d}\]

While Beer's law correctly attenuates light through uniform media, it fails to capture the internal illumination and edge darkening observed in dense cloud tops. In dense areas, light is scattered out of the medium quickly when entering peaks, causing crevices and opposite edges to appear darker relative to the surrounding volume. The "powder effect" artificially re-creates this phenomenon by reversing the exponential decay, ensuring that higher local density dampens direct illumination.

Mathematical Formulation

The standard powder formulation represents transmittance \(P\) as an inverted exponential decay relative to density or optical depth \(d\):

\[P(d) = 1.0 - e^{-d \cdot k}\]

Where:

  • \(d\) is the sampled optical thickness or density along the light ray.
  • \(k\) is a tuning scalar (typically set between \(2.0\) and \(4.0\)) controlling how aggressively the dark fringes form.

To achieve physically plausible lighting, the powder term is multiplied directly by Beer’s law transmittance:

\[\text{Attenuation} = 2.0 \cdot e^{-d} \cdot (1.0 - e^{-d \cdot 2.0})\]

The constant factor of \(2.0\) acts as a normalization multiplier to maintain energy conservation across the combined curve.

Enhancing Forward Scattering

Forward scattering in GLSL clouds is traditionally calculated using the Henyey-Greenstein phase function:

\[g \in (0, 1)\] \[p(\theta) = \frac{1 - g^2}{4\pi (1 + g^2 - 2g \cos\theta)^{1.5}}\]

When the view vector aligns closely with the sun vector (\(\cos\theta \to 1\)), forward scattering creates an intense silver lining effect. Without the powder effect, this highlight flattens surface details by overexposing both thin wisps and thick billows.

When the powder effect is coupled with Henyey-Greenstein scattering, the forward-scattering peak is preserved on thin, grazing cloud edges while deep, high-density regions are suppressed. This differential lighting accentuates the contours of cumulus clouds during high-phase-angle lighting conditions, such as sunsets.

GLSL Implementation

Below is a GLSL implementation combining dual-lobe Henyey-Greenstein phase scattering, Beer-Lambert attenuation, and the powder effect:

// Dual-lobe Henyey-Greenstein phase function
float henyeyGreenstein(float cosAngle, float g) {
    float g2 = g * g;
    return (1.0 - g2) / (4.0 * 3.14159265 * pow(1.0 + g2 - 2.0 * g * cosAngle, 1.5));
}

float cloudPhase(float cosAngle) {
    // Combine forward and backward scattering lobes
    float forward = henyeyGreenstein(cosAngle, 0.7);
    float backward = henyeyGreenstein(cosAngle, -0.2);
    return mix(forward, backward, 0.3);
}

// Combined Beer-Powder attenuation
float getLightEnergy(float opticalDepth, float cosAngle) {
    // Standard Beer-Lambert Law
    float beer = exp(-opticalDepth);
    
    // Powder effect term
    float powder = 1.0 - exp(-opticalDepth * 2.0);
    
    // Combined transmittance
    float lightTransmittance = 2.0 * beer * powder;
    
    // Modulate direct light with phase function
    return lightTransmittance * cloudPhase(cosAngle);
}

Tuning Parameters

  • Powder Multiplier: Adjusting the inner coefficient (e.g., -opticalDepth * 2.0) alters crevice contrast. Higher values restrict the dark edges to only the densest pockets, whereas lower values spread the darkening broadly across the cloud volume.
  • Sun Angle Modulation: The powder effect can be dynamically scaled based on the light phase angle. Fading the powder effect out when facing directly away from the sun ensures that back-lit surfaces remain properly shadowed without artificial inversions.