Skip to content

Cluster RectLight#24827

Open
dylansechet wants to merge 3 commits into
bevyengine:mainfrom
dylansechet:cluster_rect_light
Open

Cluster RectLight#24827
dylansechet wants to merge 3 commits into
bevyengine:mainfrom
dylansechet:cluster_rect_light

Conversation

@dylansechet

Copy link
Copy Markdown
Contributor

Objective

This clusters rectangular area lights, lifting the restriction on their number and making them behave more like point and spot lights. This should also improve performance.

On platforms without enough storage buffers (eg WebGL2), we fall back to the current non-clustered path.

Addresses the first item in #23700.

Testing

Flied around in the rect_light example with cpu clustrering, gpu clustering and WGPU_SETTINGS_PRIO=webgl2.

@dylansechet dylansechet changed the title Cluster RectLight Cluster RectLight Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-24827

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@kfc35 kfc35 added A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 1, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Jul 1, 2026
@alice-i-cecile alice-i-cecile requested a review from pcwalton July 6, 2026 05:48
@alice-i-cecile alice-i-cecile added C-Performance A change motivated by improving speed, memory usage or compile times X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Jul 6, 2026

@pcwalton pcwalton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good modulo a few nits, great cleanup.

pub(crate) light_custom_data: Vec4,
// For rect lights: pack height in color_inverse_square_range.w.
pub(crate) color_inverse_square_range: Vec4,
// For rect lights: pack width in position_radius.w.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

uber-nit: extra space before “width”

// making rect lights clusterable.
// These are per-view because we have no mechanism for "non-clustered but non-view-specific" lights.
// We could introduce such a thing, but it may not be worth it for this fallback path that's only used
// when we have too few storage buffers to cluster area lights.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed, especially since the “not enough storage buffers” case means WebGL 2, which is near end of life.

let right = rect_light.transform.right().into();
let up = rect_light.transform.up().into();
gpu_lights.rect_lights[index] = GpuRectLight {
color: Vec4::from_slice(&rect_light.color.to_f32_array())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can just be color: rect_light.color.to_vec4() * rect_light.intensity(), no?


fn rect_light(
light_id: u32,
light: RectLight,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you pass this as a ptr<function, …>? We’ve had severe performance problems in the past from passing large structs by value in shaders (the optimizer’s ability to optimize this pattern is kind of disappointing) and RectLight is pretty big.

fn quat_rotate(q: vec4<f32>, dir: vec3<f32>) -> vec3<f32> {
let t = 2.0 * cross(q.xyz, dir);
return dir + q.w * t + cross(q.xyz, t);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you’re moving this function from environment_map.wgsl, do you want to delete the copy there and change environment_map.wgsl to import this function? That’d be cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

4 participants