r3f-lighting
enzed/r3f-skills
Light React Three Fiber scenes with direct lights, environment maps, and shadows.
What is r3f-lighting?
Skill for configuring lighting in React Three Fiber scenes using direct lights, image-based lighting, and shadow mapping. Use when setting up scene illumination, debugging shadow artifacts, optimizing lighting performance, or implementing PBR-based reflections.
- Configure ambient, directional, and point lights with shadow casting
- Set up environment maps and HDR/EXR assets for image-based lighting
- Tune shadow camera frustum, bias, and map resolution to eliminate artifacts
- Use Drei helpers like Environment, ContactShadows, and AccumulativeShadows
- Manage lighting performance by limiting shadow-casting lights and render passes
- Align sky geometry, direct lights, and environment for visual consistency
How to install r3f-lighting
npx skills add https://github.com/enzed/r3f-skills --skill r3f-lighting- React Three Fiber 9+ and Three.js r185+
- Drei library for helper components (Environment, ContactShadows, etc.)
- WebGL renderer context
How to use r3f-lighting
- 1.Check your installed Three.js, Fiber, and Drei versions before starting
- 2.Set up ambient and directional lights; enable shadows on Canvas with shadows='percentage'
- 3.Configure shadow camera frustum (left, right, top, bottom, near, far) to tightly frame your scene
- 4.Adjust shadow bias and normalBias to eliminate shadow acne without detaching shadows
- 5.Load an HDR/EXR environment asset or use Drei presets for PBR reflections
- 6.Test shadow contact, clipping, and performance on your target device; retune bias and map resolution as needed
Use cases
- Setting up a shadowed scene with directional light and ground plane
- Implementing PBR reflections using environment maps instead of ambient light alone
- Debugging shadow acne, clipping, or detachment from objects
- Optimizing shadow rendering cost on mobile or performance-constrained devices
- Migrating lighting code across Three.js versions (r182+ PCF changes)
- React Three Fiber developers
- 3D web graphics engineers
- Game and interactive experience developers
- Anyone implementing real-time shadows or image-based lighting in WebGL
r3f-lighting FAQ
Ambient light alone does not provide reflections. Set scene.environment to an HDR/EXR map using Drei Environment or Three.js EnvironmentMapLoader; metallic PBR materials require environment lighting, not just ambient intensity.
Tighten the shadow camera frustum to the useful region, inspect it with CameraHelper, and adjust shadow-normalBias (typically 0.01–0.05). Increasing map resolution without adjusting frustum wastes performance.
RectAreaLight affects Standard and Physical materials but does not cast built-in shadows in WebGL. Use directional or spot lights for shadow-casting area lighting.
scene.background makes the image visible behind the scene; scene.environment provides lighting for PBR reflections. Drei Environment sets both; use them separately if you need different visuals and lighting.
No. ContactShadows is a fast approximation for ground contact; AccumulativeShadows converges across samples. Neither replaces directional shadow mapping for dynamic, moving objects or complex shadow geometry.
Full instructions (SKILL.md)
Source of truth, from enzed/r3f-skills.
name: r3f-lighting description: Light React Three Fiber scenes with direct lights, environment maps, and shadows. Use for light placement, image-based lighting, shadow artifacts, and lighting performance.
React Three Fiber lighting
Check installed Three.js, Fiber, and Drei versions and the renderer first. This example targets Fiber 9 / React 19, Three.js r185, and WebGL.
Start with a deliberate lighting setup
- Use environment lighting for PBR reflections/fill and direct lights for direction and real-time shadowing. More ambient light will not restore missing metallic reflections.
- A scene background and
scene.environmentserve different purposes. DreiEnvironmentassigns lighting;backgroundadditionally makes it visible behind the scene. - Prefer an owned HDR/EXR asset in production. Drei presets are useful for prototyping but depend on external hosting. Check loader support before choosing newer formats.
Skyis visible sky geometry, not automatically a matching sun light or environment. Align the sky, direct light, and environment when visual consistency matters.
Shadowed scene
Mount inside <Canvas shadows="percentage">. On Three.js r182+, PCFShadowMap is soft; Fiber 9's bare shadows selects the deprecated PCFSoftShadowMap.
export default function Example() {
return (
<>
<ambientLight intensity={0.3} />
<directionalLight
position={[3, 5, 3]}
intensity={3}
castShadow
shadow-mapSize={[1024, 1024]}
shadow-camera-left={-4}
shadow-camera-right={4}
shadow-camera-top={4}
shadow-camera-bottom={-4}
shadow-camera-near={0.5}
shadow-camera-far={15}
shadow-normalBias={0.02}
/>
<mesh castShadow position={[0, 0.5, 0]}>
<boxGeometry />
<meshStandardMaterial color="coral" />
</mesh>
<mesh receiveShadow rotation={[-Math.PI / 2, 0, 0]}>
<planeGeometry args={[8, 8]} />
<meshStandardMaterial color="silver" />
</mesh>
</>
)
}
Bias and frustum values above are for this small scene; retune them for actual dimensions.
Shadows and light targets
- Shadow mapping needs renderer shadows enabled, a shadow-casting light, casting meshes, and receiving materials/meshes. Ambient and hemisphere lights do not cast shadows.
- Tighten the shadow camera to the useful region before increasing map resolution. Inspect its frustum with a CameraHelper; bias should address acne without detaching shadows from objects.
- Point-light shadows render six directions. Limit shadow-casting lights and large maps; cost depends on affected geometry and passes, not just light count.
- Moving a directional/spot light's target requires a target Object3D whose world matrix updates. Add a custom target to the scene graph; changing only a detached target's position can leave its world transform stale.
- With WebGL, RectAreaLight affects Standard/Physical materials and does not cast built-in shadows. Initialize
RectAreaLightUniformsLibwhen using the native light path that requires it. - Object/camera layers are not general per-light material masks in WebGLRenderer. Do not promise that matching a light layer to a mesh makes selective illumination work.
Environment and helper cost
- Drei
Lightformeris emissive geometry captured into an Environment; it is not an ordinary real-time light and does not cast direct-light shadows. - Set
frames={1}for genuinely static environment captures or ContactShadows. Animated objects/lighting need recapture; a frozen capture will remain stale. - ContactShadows renders an offscreen depth/blur approximation. It is not free and does not replace all directional shadows.
- AccumulativeShadows converges across samples; changing the scene can require reset/reaccumulation. BakeShadows freezes updates rather than producing a portable baked lightmap.
- SoftShadows patches WebGL shader code. Verify it against the installed Three.js shadow implementation before adding it, especially after a renderer upgrade.
- Keep tone mapping/exposure consistent while tuning lights. Current physically based light intensities should not be mixed blindly with old legacy-light tutorials.
Verify
Check shadow contact, acne, clipping, loaded-model cast/receive flags, and moving objects. Compare static versus animated capture behavior and measure total render passes on the target device.
Sources
- Drei Environment, ContactShadows.
- Three.js shadows, RectAreaLight, DirectionalLight.
- Migration guide — PCF changes in r182 and environment rotation changes in r184.
Related skills
More from enzed/r3f-skills and the wider catalog.

r3f-loaders
Load and reuse 3D assets in React Three Fiber with caching, cloning, and error handling.

r3f-materials
Choose and configure React Three Fiber surface materials, PBR, transparency, and transmission.

r3f-physics
Add Rapier physics simulation to React Three Fiber with rigid bodies, colliders, forces, and joints.

r3f-postprocessing
Configure React Three Fiber postprocessing: bloom, selection effects, ambient occlusion, and depth of field.

r3f-shaders
Implement custom GLSL or TSL materials in React Three Fiber with uniforms and vertex deformation.

r3f-textures
Configure textures in React Three Fiber: color spaces, UV channels, sampling, video, and render targets.