Skip to content

Added Light Falloff Curves#24269

Draft
GageHowe wants to merge 2 commits into
bevyengine:mainfrom
GageHowe:light-falloff-curves
Draft

Added Light Falloff Curves#24269
GageHowe wants to merge 2 commits into
bevyengine:mainfrom
GageHowe:light-falloff-curves

Conversation

@GageHowe
Copy link
Copy Markdown
Contributor

N/A IN PROGRESS

Copilot AI review requested due to automatic review settings May 12, 2026 19:14
@GageHowe GageHowe marked this pull request as draft May 12, 2026 19:15
@GageHowe
Copy link
Copy Markdown
Contributor Author

image image image image image image

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces configurable distance falloff curves for punctual lights (point + spot) and wires those modes through clustered lighting on both the Rust and WGSL sides, with an accompanying example to visualize the differences.

Changes:

  • Add LightFalloff (InverseSquare / Linear / Exponential) and expose it on PointLight and SpotLight (defaulting to inverse-square).
  • Encode falloff mode into GPU light flags, update clustered-light ordering/bucketing, and update PBR + volumetric fog shaders to apply the correct attenuation per light.
  • Add a new examples/3d/light_falloff.rs example and register it in Cargo.toml.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
examples/3d/light_falloff.rs New example demonstrating point/spot light falloff modes with simple controls/UI.
crates/bevy_pbr/src/volumetric_fog/volumetric_fog.wgsl Apply falloff-aware distance attenuation for volumetric fog lighting.
crates/bevy_pbr/src/render/pbr_lighting.wgsl Split distance attenuation into inverse-square/linear/exponential helpers and route point/spot lighting accordingly.
crates/bevy_pbr/src/render/pbr_functions.wgsl Iterate lights by falloff buckets (SSBO path) and branch by falloff (fallback path).
crates/bevy_pbr/src/render/mesh_view_types.wgsl Define falloff flag encoding constants and expand SSBO cluster offsets/counts layout.
crates/bevy_pbr/src/render/light.rs Extract/store falloff on lights; encode falloff into GPU flags; include falloff in clusterable object types.
crates/bevy_pbr/src/render/clustered_forward.wgsl Update SSBO cluster range unpacking for falloff-bucketed point/spot lights.
crates/bevy_pbr/src/cluster/mod.rs Expand GPU cluster offset/count storage to 3 UVec4s and write per-falloff counts on SSBO targets.
crates/bevy_pbr/src/cluster/cluster_raster.wgsl Bucket point/spot lights by falloff during GPU clustering and update scratch counters/layout.
crates/bevy_pbr/src/cluster/cluster_allocate.wgsl Zero/size/update cluster count buffers for the expanded SSBO layout.
crates/bevy_light/src/spot_light.rs Add falloff: LightFalloff to SpotLight with default.
crates/bevy_light/src/point_light.rs Add falloff: LightFalloff to PointLight with default.
crates/bevy_light/src/light_falloff.rs New LightFalloff enum with stable shader/bucketing indices.
crates/bevy_light/src/lib.rs Export LightFalloff (including in the prelude).
crates/bevy_light/src/cluster/mod.rs Track per-falloff point/spot counts per cluster and plumb falloff into add_* helpers.
crates/bevy_light/src/cluster/assign.rs Include falloff in clusterable light types and ordering so falloff bucketing is stable.
Cargo.toml Register the new light_falloff example metadata.
Comments suppressed due to low confidence (2)

crates/bevy_pbr/src/cluster/cluster_raster.wgsl:523

  • In GPU clustering (POPULATE_PASS), the irradiance volume base offset does not include the reflection-probe count (offsets_and_counts.data[cluster_index][1u].w). This will make irradiance volumes write into the reflection-probe segment instead of after it. Include the reflection-probe count in the computed offset.
        case CLUSTERABLE_OBJECT_TYPE_IRRADIANCE_VOLUME: {
            return offsets_and_counts.data[cluster_index][0u].x +
                offsets_and_counts.data[cluster_index][0u].y +
                offsets_and_counts.data[cluster_index][0u].z +
                offsets_and_counts.data[cluster_index][0u].w +
                offsets_and_counts.data[cluster_index][1u].x +
                offsets_and_counts.data[cluster_index][1u].y +
                offsets_and_counts.data[cluster_index][1u].z +
                atomicAdd(
                    &scratchpad_offsets_and_counts.data[cluster_index].irradiance_volumes,
                    1u
                );
        }

crates/bevy_pbr/src/cluster/cluster_raster.wgsl:532

  • In GPU clustering (POPULATE_PASS), the decal base offset currently excludes both the reflection-probe count (offsets_and_counts.data[cluster_index][1u].w) and the irradiance-volume count (offsets_and_counts.data[cluster_index][2u].x). This will cause decals to overwrite earlier segments. Update the offset expression so decals start after point lights + spot lights + reflection probes + irradiance volumes.
        case CLUSTERABLE_OBJECT_TYPE_DECAL: {
            return offsets_and_counts.data[cluster_index][0u].x +
                offsets_and_counts.data[cluster_index][0u].y +
                offsets_and_counts.data[cluster_index][0u].z +
                offsets_and_counts.data[cluster_index][0u].w +
                offsets_and_counts.data[cluster_index][1u].x +
                offsets_and_counts.data[cluster_index][1u].y +
                offsets_and_counts.data[cluster_index][1u].z +
                atomicAdd(&scratchpad_offsets_and_counts.data[cluster_index].decals, 1u);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

offsets_and_counts.data[cluster_index][0u].z +
offsets_and_counts.data[cluster_index][0u].w +
offsets_and_counts.data[cluster_index][1u].x +
offsets_and_counts.data[cluster_index][1u].y +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants