A CloudLayer represents a single layer of clouds. You can define up to 4 layers within a <Clouds /> component. If you want to define your own custom cloud setup, set disableDefaultLayers to true on the <Clouds /> component first.
To animate layers (e.g., changing altitude), you can use a ref to the underlying CloudLayer implementation from @takram/three-clouds and modify its properties inside a useFrame loop.
import { EffectComposer } from '@react-three/postprocessing'
import { AerialPerspective, Atmosphere } from '@takram/three-atmosphere/r3f'
import { CloudLayer as CloudLayerImpl } from '@takram/three-clouds'
import { CloudLayer, Clouds } from '@takram/three-clouds/r3f'
import { useRef } from 'react'
import { useFrame } from '@react-three/fiber'
const Scene = () => {
// Modify an instance of the CloudLayer class transiently if props change
// frequently.
const layerRef = useRef<CloudLayerImpl>(null)
useFrame(({ clock }) => {
const layer = layerRef.current
if (layer != null) {
layer.height += clock.getDelta()
}
})
return (
<Atmosphere>
<EffectComposer enableNormalPass>
{/* Set disableDefaultLayers to remove the default cloud layers.
Otherwise, CloudLayer props patches the default cloud layers. */}
<Clouds disableDefaultLayers>
<CloudLayer
channel='r'
altitude={1000}
height={1000}
shadow
/>
<CloudLayer
ref={layerRef}
channel='r'
altitude={2000}
height={800}
shadow
/>
{/* Create fog near the ground, for example. */}
<CloudLayer
channel='a'
height={300}
densityScale={0.05}
shapeAmount={0.2}
shapeDetailAmount={0}
shapeAlteringBias={0.5}
coverageFilterWidth={1}
densityProfile={{
expTerm: 1,
exponent: 1e-3,
constantTerm: 0,
linearTerm: 0
}}
/>
{/* The number of cloud layers is limited to 4. */}
</Clouds>
<AerialPerspective sky sunLight skyLight />
</EffectComposer>
</Atmosphere>
)
}