Added Light Falloff Curves#24269
Draft
GageHowe wants to merge 2 commits into
Draft
Conversation
Contributor
Author
There was a problem hiding this comment.
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 onPointLightandSpotLight(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.rsexample and register it inCargo.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 + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.






N/A IN PROGRESS