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

Specify units in AmbientLight::brightness docs #13297

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BD103
Copy link
Member

@BD103 BD103 commented May 9, 2024

Objective

Solution

  • Specify that, after applying AmbientLight, the resulting units are in cd/m^2.
  • This is based on @fintelia's comment, and will need to be verified.

Changelog

  • Specified units for AmbientLight's brightness field.

@BD103 BD103 added C-Docs An addition or correction to our documentation D-Trivial Nice and easy! A great choice to get started with Bevy A-Rendering Drawing game state to the screen D-Domain-Expert Requires deep knowledge in a given domain S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 9, 2024
@BD103 BD103 added this to the 0.14 milestone May 9, 2024
@@ -20,6 +20,10 @@ use super::*;
pub struct AmbientLight {
pub color: Color,
/// A direct scale factor multiplied with `color` before being passed to the shader.
///
/// After applying this multiplier, the resulting value should be in units of [cd/m^2].
Copy link
Member

Choose a reason for hiding this comment

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

Is it that straightforward? Does it depend on the color type? Is alpha ignored? How can I get the total brightness from each channel?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know; I was just following the comments in the issue. @fintelia or @superdump, could you comment on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

First the color gets converted to linear sRGB (if necessary) and scaled by the brightness:

ambient_color: Vec4::from_slice(&LinearRgba::from(ambient_light.color).to_f32_array())
* ambient_light.brightness,

Then the alpha channel gets completely ignored via a swizzle and the RGB channels are used for rendering calculations:

return (diffuse_ambient + specular_ambient * specular_occlusion) * lights.ambient_color.rgb * occlusion;

Interpreting the meaning of the three values in the RGB channels is a much deeper rabbit hole. My non-expert understanding is that a value like (100.0, 100.0, 100.0) corresponds to a total light intensity of 100 cd/m^2 divided up as 21 cd/m^2 of red light, 72 cd/m^2 of green light, and 7 cd/m^2 of blue light. Where the colors precise meanings of "red light", "green light", and "blue light" are given by the sRGB spec and the relative weights also come from that same spec

Copy link
Contributor

Choose a reason for hiding this comment

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

Based on its usage in prepare_lights, the ambient light is always converted to LinearRgba (so colour space does not matter), and the colour passed to the GPU is this colour scaled by brightness.

So, we could either say Color is unitless (a scalar) and brightness is in cd/m^2, or the reverse. I think we want to say Color is unitless because it conceptually makes more sense that brightness is the intensity value (candela/square-metre).

@alice-i-cecile alice-i-cecile removed this from the 0.14 milestone May 13, 2024
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-Docs An addition or correction to our documentation D-Domain-Expert Requires deep knowledge in a given domain D-Trivial Nice and easy! A great choice to get started with Bevy S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AmbientLight docs doesn't specify units
5 participants