Skip to content

Feature: 2d Point Lights. #19539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

Adriigbs
Copy link

@Adriigbs Adriigbs commented Jun 8, 2025

Objective

2d Point Light implementation and integration inside Sprite Plugin.

  • Point lights with configurable radius, color, and intensity;
  • Light falloff (linear or exponential);

Solution

crates/bevy_sprite/src/light/point_light_2d.rs:

  • PointLight2D component and FallOffType enum definition.

crates/bevy_sprite/src/render/light.rs:

  • Light extraction from PointLight2D into ExtractedPointLight2D.
  • Processes and store the extracted lights into GpuLights2D for GPU consumption.

crates/bevy_sprite/src/render/mod.rs:

  • Create and add the light bind group to the Sprite pipeline.

crates/bevy_sprite/src/lib.rs:

  • Add extract_point_lights_2d and prepare_point_lights_2d to the SpritePlugin.

crates/bevy_sprite/src/render/sprite.wgsl

  • Light computation.
  • Apply it to the sprite.

Testing

  • tests/light_render.rs
  • examples/2dscene.rs:
    O: Set intensity to 0;
    ArrowUp: Increase intensity;
    ArrowDown: Decrease intensity;
    ArrowRight: Change color;
    N: Change scene;
    SpaceBar: Change fall off type.
  • Might need performance tests.

Showcase

demo.mp4

- Point lights with configurable radius, color, and intensity;
- Light falloff (linear or exponential);
- Example 2dscene.rs to showcase and test the lights;
- tests/light_render.rs tests

Lights are directly integrated into the existing Sprite plugin.

Signed-off-by: Adrian Graur <[email protected]>
Co-authored-by: Daniel Fernandes <[email protected]>
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen M-Needs-Release-Note Work that should be called out in the blog due to impact X-Contentious There are nontrivial implications that should be thought through S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 8, 2025
@alice-i-cecile alice-i-cecile added the D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes label Jun 8, 2025
Copy link
Contributor

github-actions bot commented Jun 8, 2025

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-19539

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.

@KurlykovDanila
Copy link

Amazing progress! As I understand it, all sprites are lit without exception. Is it possible to add a component to ignore lighting for a specific sprite? I think this would be very useful and many may be waiting for this feature, thanks.

@Adriigbs
Copy link
Author

Adriigbs commented Jun 8, 2025

@KurlykovDanila that is totally doable and it didn't cross my mind. I'll be working on that and on the CI errors. Thanks!!

@@ -0,0 +1,152 @@
use bevy_color::Color;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have some more documentation here please?

DrawSpriteBatch,
);

pub struct SetPointLightBindGroup<const I: usize>;
Copy link
Contributor

Choose a reason for hiding this comment

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

More docs would be helpful here please :)

Copy link
Author

Choose a reason for hiding this comment

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

Sure, ill work on it!

@Adriigbs
Copy link
Author

@jbuehler23 should i turn this to draft while i work on things?

Added some documentation and fixed warnings.

Signed-off-by: Adrian Graur <[email protected]>
Copy link
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-19539

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.

Signed-off-by: Adrian Graur <[email protected]>
Copy link
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-19539

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.

Signed-off-by: Adrian Graur <[email protected]>
Copy link
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-19539

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.

Adriigbs added 2 commits June 22, 2025 00:25
Signed-off-by: Adrian Graur <[email protected]>
Signed-off-by: Adrian Graur <[email protected]>
Copy link
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-19539

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.

1 similar comment
Copy link
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-19539

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.

/// This structure is sent to the GPU for lighting calculations.
///
/// - `color_intensity`: RGBA color multiplied by intensity.
/// - `position_radius`: XY position of the light, with Z as unused and W as radius.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why these doc comments shouldn't be on the members?

/// `_view` - The view uniform offset data (unused in this implementation)
/// `_item_query` - The result of the item query (unused since ItemQuery is `()`)
/// `lights_resource` - The GPU lights resource containing the bind group with light data
/// `pass` - The tracked render pass used to record GPU commands
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just a hunch since I don't have a way to check but does this get formatted as a list correctly?

If not I would suggest something like:

* `_item` - The transparent 2D render item (unused in this implementation)
* `_view` - The view uniform offset data (unused in this implementation)
...

Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

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

The example should be move to examples/2d/2d_point_lights

The ColorMaterial should be updated to also support point lights.

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-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Needs-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

6 participants