This document outlines the implementation of volumetric clouds in the sky rendering in Rays.rust.
We have implemented realistic cloud rendering using a participating media approach. Clouds exist as a volumetric layer in the atmosphere that scatters and absorbs light, creating a more realistic and dynamic sky.
- Implemented 3D Perlin noise for cloud shape generation
- Added fractal Brownian motion (fBm) for multi-octave detail
- Implemented Worley noise (cellular noise) for cloud detail
- Combined noise functions for natural-looking cloud patterns
- Includes visualization tests for easy verification
- Created
CloudLayerstruct implementingParticipatingMedium - Handles scattering and absorption of light through clouds
- Uses a simplified Henyey-Greenstein phase function for anisotropic scattering
- Implements variable density based on noise evaluation and altitude
- Defines bounds for the cloud layer with parameters for base height, thickness, and horizontal extent
- Implements ray marching through the volume with density-based sampling
- Uses adaptive step sizes based on density for better performance
- Probabilistic density sampling for natural cloud edges
- Clouds blend naturally with the existing sky renderer
- Light transport between clouds and atmosphere creates realistic sunrise/sunset effects
- Anisotropic scattering parameter to control cloud appearance (forward vs. isotropic scattering)
- Added JSON configuration options for creating cloud layers
- Supports full customization of all cloud parameters
- Easy to create different types of cloud formations
To add clouds to a scene, add a "clouds" object to your scene JSON file:
{
"type": "clouds",
"base_height": 700,
"thickness": 300,
"density": 0.5,
"noise_scale": 0.002,
"height_falloff": 0.15,
"anisotropy": 0.3,
"color": [1.0, 1.0, 1.0],
"extent": 5000.0,
"worley_density": 2.0,
"seed": 42
}| Parameter | Description | Default Value |
|---|---|---|
base_height |
Cloud layer bottom height | 800.0 |
thickness |
Cloud layer vertical thickness | 400.0 |
density |
Maximum cloud density factor | 0.6 |
noise_scale |
Scale factor for noise patterns | 0.001 |
height_falloff |
Controls density decrease with height | 0.1 |
anisotropy |
Forward scattering coefficient (higher = more directional) | 0.2 |
color |
Base color of clouds | [1.0, 1.0, 1.0] |
extent |
Horizontal extent of cloud layer | 10000.0 |
worley_density |
Density of cellular noise features | 1.0 |
seed |
Random seed for noise generation | 42 |
Two example scenes have been provided:
demo/scenes/sky-clouds.json- Earth-like cloud layer with blue skydemo/scenes/sky-sunset-clouds.json- Golden-tinted clouds during sunset
The ray marching algorithm works as follows:
- Check if ray intersects the cloud layer bounding box
- March along the ray with adaptive step sizes
- At each step, evaluate cloud density using combined noise patterns
- Apply probability-based hit detection based on density
- Return intersection point and normal for the material system
Cloud density is determined by:
- PerlinNoise-based fBm for large-scale cloud shapes
- WorleyNoise for detailed cellular structures
- Height-based falloff for realistic vertical profile
- Combined with vertical profile curve (more dense in middle, less at edges)
- Adaptive step sizes during ray marching (larger steps in low-density regions)
- Probabilistic sampling to reduce unnecessary calculations
- Clear bounding box for early ray termination
- Class-based approach for efficient noise calculations
- Multiple cloud layers/types (cumulus, stratus, cirrus)
- Self-shadowing between clouds
- Animation support with wind direction and speed
- Additional presets for common weather patterns
- Optimizations for faster rendering