Skip to content

Re-introduce "Replace Ambient Lights with Environment Map Lights (#17482)"#18207

Open
SparkyPotato wants to merge 29 commits into
bevyengine:mainfrom
SparkyPotato:revert-18167-revert-ambient-light-change
Open

Re-introduce "Replace Ambient Lights with Environment Map Lights (#17482)"#18207
SparkyPotato wants to merge 29 commits into
bevyengine:mainfrom
SparkyPotato:revert-18167-revert-ambient-light-change

Conversation

@SparkyPotato

@SparkyPotato SparkyPotato commented Mar 9, 2025

Copy link
Copy Markdown
Contributor

#17482 was reverted due to unintentional changes in ambient light rendering.
However, after further inspection, that was due to environment maps being more physically-correct, so the changes are positive.

Closes #17367.

@github-actions

github-actions Bot commented Mar 9, 2025

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

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.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen X-Needs-SME This type of work requires an SME to approve it. S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 9, 2025
@alice-i-cecile alice-i-cecile added M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Mar 9, 2025
@github-actions

github-actions Bot commented Mar 9, 2025

Copy link
Copy Markdown
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

@alice-i-cecile

Copy link
Copy Markdown
Member

However, after further inspection, that was due to environment maps being more physically-correct, so the changes are positive.

Can you say more about this? Has this been discussed elsewhere?

I'd really like to do this, but we need clear rationale for changing how user scenes are rendered.

@mockersf

mockersf commented Mar 9, 2025

Copy link
Copy Markdown
Member

AmbientLight is still a resource that is initialised by default with this PR, but also marked as deprecrated.

Does that mean we'll change again how every scene renders in the next version?

@mockersf mockersf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Example code shouldn't use deprecated things, they need to be updated to use the new component.

@mockersf

mockersf commented Mar 9, 2025

Copy link
Copy Markdown
Member

this would also close #17367

@aloucks

aloucks commented Mar 9, 2025

Copy link
Copy Markdown
Contributor

Would it make sense to rename the EnvironmentMapLight struct to AmbientLight?

Conceptually, it is ambient light, right? Isn't it just being implemented with an environment map?

@IceSentry

Copy link
Copy Markdown
Contributor

Can you say more about this? Has this been discussed elsewhere?

It was discussed on discord.

Does that mean we'll change again how every scene renders in the next version?

There's no plan that I'm aware of to do other changes related to this. The main goal is still to yeet the non physical ambient light but have an easy way to still emulate an ambient light with less overall shader code to maintain.

Would it make sense to rename the EnvironmentMapLight struct to AmbientLight?

No, because the EnvironmentMapLight is still using an environment map, it can just be used with a small map to emulate an ambient light, but it's more advanced than just a flat ambient light.

@SparkyPotato

Copy link
Copy Markdown
Contributor Author

is there an explanation why some scenes are darker (https://pixel-eagle.com/project/b25a040a-a980-4602-b90c-d480ab84076d/run/9021/compare/9009?screenshot=3D+Rendering/ssao.png or https://pixel-eagle.com/project/b25a040a-a980-4602-b90c-d480ab84076d/run/9021/compare/9009?screenshot=3D+Rendering/pbr.png) and some are lighter (https://pixel-eagle.com/project/b25a040a-a980-4602-b90c-d480ab84076d/run/9021/compare/9009?screenshot=3D+Rendering/spotlight.png or https://pixel-eagle.com/project/b25a040a-a980-4602-b90c-d480ab84076d/run/9021/compare/9009?screenshot=3D+Rendering/ssao.png)?

on https://pixel-eagle.com/project/b25a040a-a980-4602-b90c-d480ab84076d/run/9021/compare/9009?screenshot=3D+Rendering/anisotropy.png some details completely disappear. for example the dark bar between the light filaments that should be there when looking at https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/AnisotropyBarnLamp

Certain scenes are darker since they had both an ambient light and an environment map, but now the ambient light is overridden by the environment map. For scenes that are lighter, this is because the ambient light had no effect on specular reflections, whereas the environment map does.

Example code shouldn't use deprecated things, they need to be updated to use the new component.

Examples that modified the ambient light have been updated to use environment map lights instead, but I haven't modified any that relied on the default resource. That change should probably be done when we remove AmbientLight in the next version.

@rparrett

Copy link
Copy Markdown
Contributor

I feel like we should make some effort to preserve the scenes of our users. If the new light is brighter because it is more physically correct then it seems like the default intensity should be lower. Or we at least need to tell users what happened and how to fix their scenes.

Just linking for reference, the PR that set the current default ambient intensity: 11868.

@mockersf

Copy link
Copy Markdown
Member

Examples that modified the ambient light have been updated to use environment map lights instead

There are still examples that use ambient light, they should be fixed now

@mockersf

Copy link
Copy Markdown
Member

I also think that if we deprecate AmbientLight, it should be not kept as a resource initialised by default.

@SparkyPotato

Copy link
Copy Markdown
Contributor Author

I also think that if we deprecate AmbientLight, it should be not kept as a resource initialised by default.

This makes sense, but I'm not sure how to replace that with a default environment map, because the new constructors require an &mut Assets<Image> to create the 1x1 cubemaps.

While I do think that having no lights by default is a good idea, as it forces users to be deliberate with their lighting setup, it does hurt quick prototyping.

@hukasu

hukasu commented Mar 10, 2025

Copy link
Copy Markdown
Contributor

can't you create a default image on startup to use for the default environment map?

@hukasu

hukasu commented Mar 10, 2025

Copy link
Copy Markdown
Contributor

bevy already has this 1x1 default images

/// A handle to a 1 x 1 transparent white image.
///
/// Like [`Handle<Image>::default`], this is a handle to a fallback image asset.
/// While that handle points to an opaque white 1 x 1 image, this handle points to a transparent 1 x 1 white image.
// Number randomly selected by fair WolframAlpha query. Totally arbitrary.
pub const TRANSPARENT_IMAGE_HANDLE: Handle<Image> =
weak_handle!("d18ad97e-a322-4981-9505-44c59a4b5e46");

other locations with images created on setup

/// The handle to the default chromatic aberration lookup texture.
///
/// This is just a 3x1 image consisting of one red pixel, one green pixel, and
/// one blue pixel, in that order.
const DEFAULT_CHROMATIC_ABERRATION_LUT_HANDLE: Handle<Image> =
weak_handle!("dc3e3307-40a1-49bb-be6d-e0634e8836b2");

const SMAA_AREA_LUT_TEXTURE_HANDLE: Handle<Image> =
weak_handle!("569c4d67-c7fa-4958-b1af-0836023603c0");
/// The handle of the search LUT, a KTX2 format texture that SMAA uses internally.
const SMAA_SEARCH_LUT_TEXTURE_HANDLE: Handle<Image> =
weak_handle!("43b97515-252e-4c8a-b9af-f2fc528a1c27");

@mockersf

Copy link
Copy Markdown
Member

yup you can static embed small assets, a 1x1 cubemap shouldn't use a lot of memory

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers and removed X-Needs-SME This type of work requires an SME to approve it. labels Aug 6, 2025
Comment thread examples/3d/fog.rs
App::new()
.insert_resource(AmbientLight::NONE)
.add_plugins(DefaultPlugins)
.add_plugins(DefaultPlugins.set(bevy::pbr::PbrPlugin {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I dislike that we need to reach in to plugin config to override a "camera default". Semantically in most cases I think people should be saying "I dont want this camera to have the default". We are composing scenes here, and Plugin settings are not scene properties. This design choice was almost certainly a product of required component behavior (which you currently can't disable for a specific spawn ... and I'm not convinced we ever want that). I would almost prefer camera.insert(EnvironmentMapLight { intensity: 0, ..default()}) for the common case. That would mean we'd be rendering environment maps when we don't need them though. Making EnvironmentMapLight an enum probably makes sense. See my next comment for more motivation.

Comment thread examples/3d/lighting.rs
// environment lights' brightnesses are measured in candela per meter square, calculable as (color * intensity)
EnvironmentMapLight {
intensity: 80.0,
..EnvironmentMapLight::solid_color(&mut images, ORANGE_RED.into())

@cart cart Aug 6, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This unnecessarily regresses the UX of the (very) common case "I want colored ambient light". As others have mentioned, it also makes doing things like animating the color more challenging.

In light of this (and my comment above, and the desired EnvironmentLight rename), I think we should make EnvironmentLight an enum:

enum EnvironmentLight {
    CubeMap {
        diffuse_map: Handle<Image>,
        intensity: f32,
        /* other fields */
    },
    Color {
        color: Color,
        intensity: f32,
    },
    Disabled,
}

I think this should be done before 0.17 to make this a "pleasant" change, ease migration, and avoid double breakage. We can then also remove all of the bevy::pbr::PbrPlugin { default_environment_map_light: false } nastiness in favor of camera.insert(EnvironmentLight::Disabled)

@cart

cart commented Aug 6, 2025

Copy link
Copy Markdown
Member

I'm cool with merging this now, provided we block 0.17 on the changes above.

@atlv24

atlv24 commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

punting this to 0.18, will write up an issue on the path forward

@atlv24 atlv24 modified the milestones: 0.17, 0.18 Aug 6, 2025
@cart

cart commented Aug 6, 2025

Copy link
Copy Markdown
Member

(We had a Discord conversation here with some context)

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Aug 11, 2025
@Igor-dvr

Igor-dvr commented Sep 17, 2025

Copy link
Copy Markdown

Iiuc we should probably have environment/dome light type that encapsulates an enum: Color/AmbientLight, EnvironmetTexture, SkyTexture, something else. You can configure this light with only one option but can have multiple such lights with different options in a scene. Related:


impl EnvironmentMapLight {
/// An environment map with a uniform color, useful for uniform ambient lighting.
pub fn solid_color(assets: &mut Assets<Image>, color: Color) -> Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pub fn solid_color(assets: &mut Assets<Image>, color: Color) -> Self {
pub fn solid_color(assets: &mut Assets<Image>, color: impl Into<Color>) -> Self {

so that e.g. tailwind::AMBER_100 works :)

Comment on lines +113 to +115
top_color: Color,
mid_color: Color,
bottom_color: Color,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

plz turn these into impl Into<Color> too

@alice-i-cecile alice-i-cecile removed this from the 0.18 milestone Dec 10, 2025
github-merge-queue Bot pushed a commit that referenced this pull request Jan 14, 2026
# Objective

- Add EnvironmentMapLight creation helper functions

## Solution

- Rip them from #18207

## Testing

- tested in linked PR
@cart cart closed this May 5, 2026
@cart cart reopened this May 5, 2026
@alice-i-cecile alice-i-cecile added this to the 0.20 milestone Jun 9, 2026
@alice-i-cecile alice-i-cecile added S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jun 9, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Jun 9, 2026
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 M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers

Projects

Status: Needs SME Triage
Status: No status

Development

Successfully merging this pull request may close these issues.

Remove ambient light as a resource