VRC Light Volumes Documentation

repository·main·Indexed 20 days ago

https://github.com/redsim/vrclightvolumes

An optimized voxel-based lighting solution for VRChat that provides a high-performance alternative to traditional light probes and analytic lighting for avatars, dynamic props, and static objects. It features baked per-pixel voxel lighting, support for regular and point light volumes, and integration with various compatible shaders and Amplify Shader Editor (ASE).

Tokens
16.6K
Snippets
17
Records
60
Agent score
68%

What's inside VRC Light Volumes

  1. Overview of VRC Light Volumes

    main
    VRC Light Volumes is an optimized, next-gen voxel-based light probe replacement and analytic lighting solution designed for VRChat. It provides baked per-pixel voxel-based lighting that can affect avatars and dynamic props (requires shader integration).
  2. Use cases for Regular and Point Light Volumes

    main

    Regular Light Volumes

    • Small Static Props: Use for props that require high lightmap resolution to avoid visible seams (Light Volumes are voxel-based and seam-free).
    • Dynamic Batching: If low-poly dynamic props use the same material and have Light Probes and Reflection Probes disabled, they can be dynamically batched at runtime.
    • Volumetric Effects: Combine with particles for volumetric fog.
    • Lighting Toggles: Switch between two volumes at runtime to toggle room lighting.
    • Dynamic GI: Use for TV screens or Audio Link dynamic lights.

    Point Light Volumes

    • Portable Lights: Use Spot Lights as flashlights or Point Lights as dynamic sources.
    • Studio Lighting: Use Area Lights as soft boxes.
    • Dynamic Environments: Moving blinking lights for clubs, image/cubemap projectors, and Audio Link integration.
  3. How Light Volumes work using Spherical Harmonics

    main

    The VRC Light Volumes system uses L1 Spherical Harmonics (SH) to approximate how light affects a point in 3D space. This is a computationally efficient method suitable for real-time rendering.

    L1 Spherical Harmonics consist of:

    • L0: Ambient color. Represents the average light color at a point without directional information.
    • L1 Red: A vector representing the average direction and intensity of Red light.
    • L1 Green: A vector representing the average direction and intensity of Green light.
    • L1 Blue: A vector representing the average direction and intensity of Blue light.
  4. How Point Light Volumes work

    main

    Unlike regular Light Volumes which use voxels, Point Light Volumes compute lighting analytically in real time using mathematical formulas. They use L1 SH and an inverse square attenuation model, which accounts for the physical size of the light source.

    Attenuation and Color Calculation

    The attenuation is calculated as: $$\text{Attenuation} = \frac{1}{\text{LightSize}^2 + \text{DistanceToLight}^2}$$

    The final color is determined by: $$\text{FinalColor} = \text{Attenuation} \times \text{Color} \times \text{Intensity} \times \text{LightSize}^2$$

    Note that intensity is multiplied by the square of the light's size, causing it to behave like light emitted per unit surface area.

    Distance Culling

    To optimize performance, lights are culled at a distance using a squared distance mask: $$\text{Mask} = \text{Saturate}\left(1 - \frac{\text{DistanceToLight}^2}{\text{CutoffDistance}^2}\right)$$

    The Saturate() function clamps the result between 0 and 1, and the final light color is multiplied by this mask.

  5. Configure Light Shapes: Parametric, LUT, and Custom

    main

    You can choose between three light shape modes:

    1. Parametric (Default)

    Uses inverse-square light attenuation.

    • Light Source Size: Represents the physical radius of the light-emitting surface (e.g., a bulb). Scaling the GameObject also scales this value.
    • Intensity: Represents light emitted per unit of surface area. Small Light Source Size values require very high Intensity to achieve a visible range.
    • Spot Light specific:
      • Angle: Cone angle in degrees (can exceed 180° for an inverted cone).
      • Falloff: Adjusts cone edge softness.

    2. LUT (Look Up Table)

    Used for complex shapes and custom attenuation.

    • Spot Light: Uses a 2D texture. Horizontal axis = color change from center to edge. Vertical axis = attenuation (e.g., linear or custom).
    • Point Light: Uses only the vertical texture direction (horizontal is ignored).
    • Note: Requires manual Range configuration.

    3. Custom

    Used for projecting textures or cubemaps.

    • Cookies: Can project colored textures (acting as a projector).
    • Point Light Cubemaps: Perfect for disco balls or star projectors.
    • Note: In Custom mode, the Angle property cannot create an inverted cone (unlike Spot Light mode).
  6. Understand Light Volume data and storage

    main

    Light Volumes are 3D textures composed of voxels. Each voxel stores numerical data representing the L1 SH coefficients rather than standard RGBA colors.

    Data Structure

    Because L1 SH requires 12 channels (L0 + 3 color channels $\times$ 3 vector components) and standard 3D textures only support 4 channels (RGBA), the system splits the data across three separate 3D textures.

    Storage and Performance

    • Texture Atlas: For shader performance, these three textures (and data from multiple Light Volumes in a scene) are combined into a single large 3D texture atlas.
    • Padding: Padding is added around texture "islands" within the atlas to prevent light leaking between different volumes.
    • UVW Mapping: The system stores 3D UV (UVW) information to convert world-space coordinates into positions within the SH atlas.
  7. How the VRC Light Volumes system works

    main

    VRC Light Volumes is an optimized lighting solution for VRChat (designed for SDK3 and Udon) consisting of two distinct systems:

    1. Regular Light Volumes: A voxel-based solution that replaces Unity's light probes with per-pixel lighting. It functions similarly to Unity 6's Adaptive Probe Volumes (APV) but uses manual, ReflectionProbe-like volume placement. Use this for baked, high-quality environmental lighting.

    2. Point Light Volumes: A parametric lighting system for dynamic lights (Point, Spot, and Area lights). Unlike the regular system, these are not voxel-based and use LUT textures or parametric math. They can support up to 128 active lights per scene and can project light cookies or cubemaps, but they do not support real-time shadows.

  8. TV Screen Integration Overview and Limitations

    main

    The TV Screens Integration package provides a way to achieve real-time global illumination from video players.

    Key Characteristics:

    • Visual Style: Similar to LTCGI but without real screen reflections; optimized for matte materials.
    • Performance: High performance.
    • Capabilities: Shadows both avatars and the environment.

    Limitations:

    • No Reflections: Does not produce screen reflections like LTCGI.
    • Color Averaging: Only projects a single average screen color rather than detailed screen data.
  9. How Light Volume evaluation works in shaders

    main

    Light Volume evaluation is performed entirely within the shader. To use this, a material must include specific shader code that supports Light Volumes.

    The shader calculates the world position of a pixel, samples the SH data from the atlas using interpolated voxel values, and computes the final color using the following formula:

    FinalColor = L0 + dot(L1, WorldNormal);

    This formula represents the fastest and simplest method for evaluating SH data.

  10. Understand the difference between Light Volume and Light Volume Instance

    main

    The VRC Light Volumes system uses two distinct components to manage lighting data:

    1. Light Volume (Editor-only): A helper script used in the Unity Editor to configure settings and manage 3D textures. It is not included in the VRChat upload. Use this to set up your volumes and manage the baking process.

    2. Light Volume Instance (Udon script): The actual runtime component that stores all data required for rendering. This is what is uploaded to VRChat.

    Usage Note: Do not modify Light Volume Instance values manually in the editor; always use the Light Volume component instead. However, if you are writing Udon logic to change lighting at runtime (e.g., animating light intensity), you should reference and manipulate the Light Volume Instance component directly.

  11. Understand the Point Light Volumes component structure

    main

    The Point Light Volumes system uses two distinct components to manage lights:

    1. Point Light Volume (Editor-only): A helper script used to configure light settings in the Unity Editor. It is not included in the VRChat upload. Use this for all manual setup.
    2. Point Light Volume Instance (Udon script): The actual runtime component that stores data and renders the light in-game.

    Usage Rule:

    • For manual setup in the editor, always use the Point Light Volume component.
    • For runtime logic (e.g., changing light color or position via Udon), you must reference and modify the Point Light Volume Instance component, as it is the one that functions in-game.
  12. Custom SH Evaluation Requirements

    main

    If you choose to implement your own evaluation method instead of using LightVolumeEvaluate(), you must use L1 components.

    Warning: Using only the L0 (ambient) term will result in unrealistic shading and can make objects appear translucent. Proper shading requires considering L1 directions, or at minimum, the magnitude and direction of the dominant light.