Skip to content

Volumetric Effects

Strata provides volumetric rendering for fog, god rays, underwater effects, and atmospheric rendering to create immersive environments.

import { VolumetricFogMesh } from '@strata-game-library/core';
<VolumetricFogMesh density={0.02} color="#8899aa" />

Height-based volumetric fog:

import { VolumetricFogMesh } from '@strata-game-library/core';
<VolumetricFogMesh
// Fog parameters
density={0.02}
color="#8899aa"
// Height falloff
heightFalloff={0.1}
baseHeight={0}
maxHeight={50}
// Animation
animated
animationSpeed={0.1}
noiseScale={0.05}
// Rendering
steps={32} // Ray march steps
maxDistance={200} // Max fog distance
// Sun interaction
sunPosition={[100, 50, 100]}
sunScattering={0.3}
/>
PropTypeDefaultDescription
densitynumber0.02Fog density
colorstring'#ffffff'Fog color
heightFalloffnumber0.1Vertical falloff rate
baseHeightnumber0Fog floor height
maxHeightnumber100Fog ceiling height
stepsnumber32Ray march quality

Simple distance-based fog (post-processing):

import { EnhancedFog } from '@strata-game-library/core';
<EnhancedFog
color="#aabbcc"
near={10}
far={200}
density={0.01}
/>

Complete underwater effect:

import { UnderwaterOverlay } from '@strata-game-library/core';
<UnderwaterOverlay
// Fog
fogColor="#003366"
fogDensity={0.03}
// Caustics
caustics
causticsIntensity={0.4}
causticsScale={0.5}
causticsSpeed={0.3}
// Color absorption
depthColor="#001122"
absorptionRate={0.1}
// Particles
particles
particleCount={500}
particleSize={0.05}
particleSpeed={0.02}
// Surface distortion
surfaceDistortion
distortionStrength={0.02}
/>

Volumetric light shafts:

import { GodRays } from '@strata-game-library/core';
<GodRays
// Light source
lightPosition={[50, 80, 50]}
lightColor="#ffffee"
// Ray parameters
intensity={0.5}
decay={0.95}
density={0.5}
// Quality
samples={60}
maxLength={1}
// Occlusion
occlusionMesh={treesRef}
/>

All-in-one volumetric controller:

import { VolumetricEffects } from '@strata-game-library/core';
<VolumetricEffects
// Fog
fog
fogDensity={0.015}
fogColor="#9ab"
// God rays
godRays
godRayIntensity={0.4}
sunPosition={[100, 80, 50]}
// Height fog
heightFog
heightFogDensity={0.03}
heightFogMax={30}
/>

Traditional distance-based fog:

<VolumetricFogMesh
type="distance"
density={0.01}
near={10}
far={300}
/>

Fog that accumulates at lower elevations:

<VolumetricFogMesh
type="height"
density={0.03}
baseHeight={0}
maxHeight={20}
heightFalloff={0.15}
/>

True 3D fog with noise:

<VolumetricFogMesh
type="volumetric"
density={0.02}
noiseScale={0.03}
noiseOctaves={4}
animated
animationSpeed={0.05}
/>
<GodRays
lightPosition={[100, 100, 0]}
intensity={0.5}
samples={60}
/>

God rays through occluding geometry:

const treesRef = useRef();
<group ref={treesRef}>
<TreeInstances count={100} spread={50} />
</group>
<GodRays
lightPosition={[50, 80, 0]}
intensity={0.6}
occlusionMesh={treesRef}
occlusionDensity={0.8}
/>
<GodRays
lightPosition={sunPosition}
intensity={0.4}
cloudOcclusion
cloudTexture={cloudNoiseTexture}
/>
import { useCamera } from '@react-three/fiber';
function UnderwaterScene() {
const camera = useCamera();
const isUnderwater = camera.position.y < waterLevel;
return (
<>
<Water waterLevel={0} />
{isUnderwater && (
<UnderwaterOverlay
fogColor="#002244"
caustics
/>
)}
</>
);
}
<UnderwaterOverlay
// Deeper = darker blue
shallowColor="#0066aa"
deepColor="#001122"
depthTransition={30}
// Deeper = more fog
fogDensity={0.02}
fogDensityScale={1.5} // Multiplier per 10 units depth
/>

Light patterns on underwater surfaces:

<UnderwaterOverlay
caustics
causticsTexture={causticsMap} // Optional texture
causticsIntensity={0.5}
causticsScale={0.3}
causticsSpeed={0.4}
// Apply to scene
affectScene
/>
import { AtmosphericScattering } from '@strata-game-library/core';
<AtmosphericScattering
sunPosition={[100, 50, 100]}
rayleighCoefficient={0.0025}
mieCoefficient={0.001}
scatteringStrength={1}
/>
<AtmosphericScattering
densityFalloff={0.0001}
baseAltitude={0}
atmosphereHeight={8000}
/>
<VolumetricFogMesh
density={0.04}
color="#778899"
animated
animationSpeed={0.2}
noiseScale={0.1}
/>
<VolumetricFogMesh
density={0.06}
color="#eeeeff"
heightFog
maxHeight={100}
/>
<VolumetricFogMesh
density={0.08}
color="#c4a35a"
animated
animationSpeed={0.5}
noiseScale={0.2}
windDirection={[1, 0, 0.3]}
/>

Use volumetric shaders directly:

import {
// Fog shader is exported as an object with vertex and fragment properties
volumetricFogShader,
// God rays shaders are exported separately
godRaysVertexShader,
godRaysFragmentShader,
// Underwater shader is also an object
underwaterShader
} from '@strata-game-library/shaders';
import * as THREE from 'three';
import { useThree } from '@react-three/fiber';
function VolumetricFogCustom() {
const { camera } = useThree();
const fogMaterial = new THREE.ShaderMaterial({
vertexShader: volumetricFogShader.vertex,
fragmentShader: volumetricFogShader.fragment,
uniforms: {
uDensity: { value: 0.02 },
uColor: { value: new THREE.Color('#8899aa') },
uCameraPos: { value: camera.position },
uTime: { value: 0 }
},
transparent: true,
depthWrite: false
});
return <mesh material={fogMaterial}>{/* ... */}</mesh>;
}
// Mobile - 30 FPS
<VolumetricFogMesh
steps={16}
density={0.01}
animated={false}
/>
// Desktop - 60 FPS
<VolumetricFogMesh
steps={32}
density={0.02}
animated
/>
// High-end
<VolumetricFogMesh
steps={64}
density={0.03}
animated
noiseOctaves={4}
/>
  1. Lower ray march steps on mobile (16-24)
  2. Reduce density for distant fog
  3. Disable animation if not needed
  4. Use simpler fog types (distance vs volumetric)
  5. Limit god ray samples (30-60)

See the interactive sky & volumetrics demo running live in your browser.

View Live Demo | View Source