Skip to content
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

Add basic light gizmos #12228

Merged
merged 8 commits into from
Mar 3, 2024
Merged

Conversation

Kanabenki
Copy link
Contributor

@Kanabenki Kanabenki commented Mar 1, 2024

Objective

Solution

  • Add a ShowLightGizmo and its related gizmo group and plugin, that shows a gizmo for all lights of an entities when inserted on it. Light display can also be toggled globally through the gizmo config in the same way it can already be done for Aabbs.
  • Add distinct segment setters for height and base one Cone3dBuilder. This allow having a properly rounded base without too much edges along the height. The doc comments explain how to ensure height and base connect when setting different values.

Gizmo for the three light types without radius with the depth bias set to -1:
without-radius

With Radius:
with-radius

Possible future improvements:

  • Add a billboarded sprite with a distinct sprite for each light type.
  • Display the intensity of the light somehow (no idea how to represent that apart from some text).

Changelog

Added

  • The new ShowLightGizmo, part of the LightGizmoPlugin and configurable globally with LightGizmoConfigGroup, allows drawing gizmo for PointLight, SpotLight and DirectionalLight. The gizmos color behavior can be controlled with the LightGizmoColor member of ShowLightGizmo and LightGizmoConfigGroup.
  • The cone gizmo builder (Cone3dBuilder) now allows setting a differing number of segments for the base and height.

@Kanabenki Kanabenki added C-Feature A new feature, making something new possible A-Gizmos Visual editor and debug gizmos labels Mar 1, 2024
@alice-i-cecile alice-i-cecile requested a review from nicopap March 1, 2024 19:05
@alice-i-cecile
Copy link
Member

They're pretty, but I'm not sure I see the utility of these. Can you or @nicopap say more about where users might use these?

@Kanabenki
Copy link
Contributor Author

Kanabenki commented Mar 1, 2024

They're pretty, but I'm not sure I see the utility of these. Can you or @nicopap say more about where users might use these?

The common use case I've seen them in other engines is to highlight the color and boundaries of a selected light in the editor. Unity, Unreal and Godot all have some kind of wireframe display to outline a light area and/or direction when it is selected.

I'm on mobile right now but I'll update with some screenshots to show what I mean as soon as I can.

Edit:

Here's how it look in Godot:

godot-spot

In Unreal:

unreal-spot

In Unity (with HDRP, as the default renderer does not seems to allow setting the spot light inner angle and the gizmo show less info). This seems to be the same approach as the one I took here.

spot-unity

@alice-i-cecile
Copy link
Member

Ah neat, for debugging lights themselves. Okay, that makes much more sense to me :)

@alice-i-cecile alice-i-cecile added the M-Needs-Release-Note Work that should be called out in the blog due to impact label Mar 1, 2024
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I'm happy with the code quality, and these should exist, but we need an example demonstrating how to use these :) Simple is totally fine: I basically just want a cube, a floor, some lights and the light gizmos being toggled.

Comment on lines 30 to 35
fn draw_gizmos<'a, P, S, D>(
point_lights: P,
spot_lights: S,
directional_lights: D,
gizmos: &mut Gizmos<LightGizmoConfigGroup>,
) where
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It might be nice from an organizational/readability perspective to split these up into a function-per-light

Copy link
Contributor

github-actions bot commented Mar 3, 2024

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

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

Just one comment. Everything else looks good to me!

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 3, 2024
@alice-i-cecile alice-i-cecile enabled auto-merge March 3, 2024 18:49
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 3, 2024
Merged via the queue into bevyengine:main with commit de0ed29 Mar 3, 2024
29 checks passed
@nicopap nicopap mentioned this pull request Mar 4, 2024
57 tasks
spectria-limina pushed a commit to spectria-limina/bevy that referenced this pull request Mar 9, 2024
# Objective

- Part of bevyengine#9400.
- Add light gizmos for `SpotLight`, `PointLight` and `DirectionalLight`.

## Solution

- Add a `ShowLightGizmo` and its related gizmo group and plugin, that
shows a gizmo for all lights of an entities when inserted on it. Light
display can also be toggled globally through the gizmo config in the
same way it can already be done for `Aabb`s.
- Add distinct segment setters for height and base one `Cone3dBuilder`.
This allow having a properly rounded base without too much edges along
the height. The doc comments explain how to ensure height and base
connect when setting different values.

Gizmo for the three light types without radius with the depth bias set
to -1:

![without-radius](https://github.com/bevyengine/bevy/assets/18357657/699d0154-f367-4727-9b09-8b458d96a0e2)

With Radius:

![with-radius](https://github.com/bevyengine/bevy/assets/18357657/f3af003e-dbba-427a-a305-c5cc1676e340)

Possible future improvements:
- Add a billboarded sprite with a distinct sprite for each light type.
- Display the intensity of the light somehow (no idea how to represent
that apart from some text).

---

## Changelog

### Added

- The new `ShowLightGizmo`, part of the `LightGizmoPlugin` and
configurable globally with `LightGizmoConfigGroup`, allows drawing gizmo
for `PointLight`, `SpotLight` and `DirectionalLight`. The gizmos color
behavior can be controlled with the `LightGizmoColor` member of
`ShowLightGizmo` and `LightGizmoConfigGroup`.
- The cone gizmo builder (`Cone3dBuilder`) now allows setting a
differing number of segments for the base and height.

---------

Co-authored-by: Gino Valente <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Gizmos Visual editor and debug gizmos C-Feature A new feature, making something new possible M-Needs-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants