4. Lights
Lighting transforms flat 3D scenes into vibrant, realistic visuals. In previous chapters, we did not explicitly set the lights because Vuer provides default lights. This chapter will show you how to upgrade that simple setup to professional, cinematic lighting like this:
The above scene uses a sophisticated four-light setup with warm/cool color contrast and soft shadows. We'll learn how to build this step by step, starting with the fundamentals.
Light Types
Vuer provides six main light types. In our optimized scene above, we use AmbientLight, SpotLight, and RectAreaLight. Let's explore all available types:
Click the show/hide button in the left-hand list to control the light switch and view the effects of different lights and their combinations.
Starting with Basic Lighting
Let's start by understanding the two fundamental light types: ambient and directional.
AmbientLight - Global Base Lighting
Ambient light illuminates all objects uniformly from all directions, providing a base level of brightness.
Key parameters: color (default: "#ffffff"), intensity (default: 0.5)
Key characteristics:
- No shadows or direction
- Prevents completely black areas
- Objects appear flat without depth
- Very performance-efficient
DirectionalLight - Adding Depth with Shadows
Directional light simulates distant light sources like the sun, casting parallel rays across the entire scene:
Key parameters: color, intensity (default: 0.5), position, castShadow (enable shadows)
Key characteristics:
- Creates parallel rays like sunlight
- Position indicates direction (not actual location)
- Can cast sharp, defined shadows
- Excellent for primary scene illumination
Additional Light Types
PointLight - Omnidirectional Light
Point lights emit in all directions from a single point, like a light bulb:
Key parameters: color, intensity (default: 20), position, showSphere (display sphere at light position), castShadow (enable shadows)
Use cases: Light bulbs, torches, candles, magical orbs
SpotLight - Focused Beam
Spotlight creates a cone of light, perfect for dramatic focused illumination. The optimized scene at the top uses two spotlights: a warm orange key light (main illumination) and a cool blue rim light (edge highlight) to create professional, cinematic lighting with warm/cool color contrast:
Key parameters: color, intensity, position, angle (cone angle in radians, default: π/3), penumbra (edge softness 0-1, default: 0), distance (range, 0=infinite), decay (falloff rate, default: 2), castShadow
Use cases: Flashlights, stage lighting, dramatic effects
HemisphereLight - Natural Outdoor Lighting
Hemisphere light simulates natural outdoor lighting with different sky and ground colors:
Key parameters: skyColor (top hemisphere color), groundColor (bottom hemisphere color), intensity (default: 1.0), helper
Note: Cannot cast shadows.
Use cases: Outdoor scenes, natural ambient light
RectAreaLight - Soft Area Lighting
Rectangular area lights emit from a surface, creating soft, realistic lighting. In our optimized scene, we use a RectAreaLight as the fill light with soft purple color (#e8d5ff) to reduce harsh shadows without eliminating them entirely:
Key parameters: color, intensity (default: 1.0), width, height, position, lookAt (direction to face), helper
Important: Only works with standard and physical materials. Cannot cast shadows.
Use cases: Softboxes, windows, studio lighting
Adding Shadows to Your Scene
Lighting and shadows always work together. In the scene at the beginning of this chapter, you may have noticed the soft, realistic shadows that add depth and dimension. To achieve that effect, we need to configure shadow properties alongside our lights.
Shadow Basics
For shadows to appear in your scene, you need three components:
- Light source with
castShadow=True- The light must be configured to cast shadows - Objects with
castShadow=True- Objects that should create shadows - Surfaces with
receiveShadow=True- Surfaces (like floors) that display shadows
Key points:
- Only
DirectionalLight,SpotLight, andPointLightcan cast shadows AmbientLight,HemisphereLight, andRectAreaLightcannot cast shadows- Objects must use
lambert,phong,standard, orphysicalmaterials for shadows to work - The
basicmaterial type ignores all lighting and shadows
Shadow Camera Range Limitation
Even with castShadow=True configured, shadows have a limited range determined by the shadow camera. If your scene is large or objects are far from the light source, you may notice missing or clipped shadows.
Each light with shadows uses an internal "shadow camera" to render the shadow map. Objects outside this camera's view won't cast shadows. This is why you might see:
- Shadows suddenly cutting off at a certain distance
- Missing shadows for objects far from the light
- Incomplete shadows on large floor planes
When do you need shadow configuration?
- Large scenes (objects spread over 10+ units)
- Distant objects that need to cast shadows
- SpotLight or DirectionalLight covering a wide area
- When you notice shadows are clipped or missing
For small scenes with objects close together (within ~5-10 units), the default shadow camera usually works fine. For larger scenes, you'll need to configure the shadow camera range as shown below.
Advanced Shadow Configuration
For finer control over shadow quality and appearance, you can configure shadow properties using flattened attribute names:
Note: Shadow properties use flattened attribute names with hyphens (e.g., shadow-mapSize, shadow-camera-far). Use the **{} unpacking syntax to pass these attributes.
Shadow quality settings:
mapSize=[512, 512]- Low quality, better performancemapSize=[1024, 1024]- Medium quality (default)mapSize=[2048, 2048]- High quality (recommended for final renders)mapSize=[4096, 4096]- Ultra quality, significant performance cost
Common shadow parameters:
bias- Prevents "shadow acne" artifacts, typically-0.0001to-0.001radius- Softens shadow edges (only works with certain shadow types)camera.near/far- Controls shadow rendering rangecamera.fov(SpotLight) - Field of view for shadow cameracamera.left/right/top/bottom(DirectionalLight) - Defines shadow coverage area
Complete Example: Professional Lighting with Shadows
Let's put everything together. The scene shown at the beginning of this chapter uses a four-light setup with shadow configuration to create professional, cinematic lighting. Here's the complete code:
Source Code
This example demonstrates the concepts covered in this chapter: multiple light types working together, shadow configuration for realistic depth, and careful balance of light intensities and colors to create professional, cinematic results.
What's Next?
Now that you understand lighting, you can:
Continue with rendering:
-
Render Modes - Learn about different rendering modes
- Post-processing Effects - Add bloom and other effects
- Path Tracing - Create photorealistic renders
Explore interactive features:
- Animation - Animate objects and cameras
- Events and Interaction - Handle user clicks and input
- VR/AR - Build immersive experiences
Quick lighting tips to remember:
- Start with
AmbientLight(0.3) +DirectionalLight(1.0) - Use
lambertorstandardmaterials to see lighting effects - Add
castShadow=Trueand a floor withreceiveShadow=Truefor depth - Use 3-5 lights maximum for good performance