-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Re-introduce "Replace Ambient Lights with Environment Map Lights (#17482)" #18207
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
base: main
Are you sure you want to change the base?
Changes from all commits
0778d9c
8274ccf
492016b
247c829
f43b4a8
f52ac2d
3e44275
c70513b
6379011
1ea7cf5
1c4a8c9
362be00
c87a15c
fb3a807
c2bb959
435af5d
0f2d7b6
7256c26
77f7333
4c7c2f0
eab52ce
e58a1b7
d3fb19b
47529ae
83fe161
613f3bf
e4798f3
80b718b
40ea776
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,14 @@ | ||||||
| use bevy_asset::Handle; | ||||||
| use bevy_asset::{uuid_handle, Assets, Handle, RenderAssetUsages}; | ||||||
| use bevy_camera::visibility::Visibility; | ||||||
| use bevy_color::{Color, ColorToPacked, Srgba}; | ||||||
| use bevy_ecs::prelude::*; | ||||||
| use bevy_image::Image; | ||||||
| use bevy_math::Quat; | ||||||
| use bevy_reflect::prelude::*; | ||||||
| use bevy_transform::components::Transform; | ||||||
| use wgpu_types::{ | ||||||
| Extent3d, TextureDimension, TextureFormat, TextureViewDescriptor, TextureViewDimension, | ||||||
| }; | ||||||
|
|
||||||
| /// A marker component for a light probe, which is a cuboid region that provides | ||||||
| /// global illumination to all fragments inside it. | ||||||
|
|
@@ -96,14 +100,82 @@ pub struct EnvironmentMapLight { | |||||
| pub affects_lightmapped_mesh_diffuse: bool, | ||||||
| } | ||||||
|
|
||||||
| impl EnvironmentMapLight { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't comment on the struct definition above, but I think we need a |
||||||
| /// An environment map with a uniform color, useful for uniform ambient lighting. | ||||||
| pub fn solid_color(assets: &mut Assets<Image>, color: Color) -> Self { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I don't have an obvious alternative pattern to use here but for some reason constructors that accept asset collections feels awkward to me. part of me feels like a EnvironmentLightMap::from_image(images.add(Color::WHITE));but that wouldn't work for the gradient version. Although maybe would if there was some kind of gradient type in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
so that e.g. |
||||||
| Self::hemispherical_gradient(assets, color, color, color) | ||||||
| } | ||||||
|
|
||||||
| /// An environment map with a hemispherical gradient, fading between the sky and ground colors | ||||||
| /// at the horizon. Useful as a very simple 'sky'. | ||||||
| pub fn hemispherical_gradient( | ||||||
| assets: &mut Assets<Image>, | ||||||
| top_color: Color, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider making mid_color a parameter too |
||||||
| mid_color: Color, | ||||||
| bottom_color: Color, | ||||||
|
Comment on lines
+113
to
+115
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz turn these into |
||||||
| ) -> Self { | ||||||
| let handle = assets.add(Self::hemispherical_gradient_cubemap( | ||||||
| top_color, | ||||||
| mid_color, | ||||||
| bottom_color, | ||||||
| )); | ||||||
|
|
||||||
| Self { | ||||||
| diffuse_map: handle.clone(), | ||||||
| specular_map: handle, | ||||||
| ..Default::default() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub(crate) fn hemispherical_gradient_cubemap( | ||||||
| top_color: Color, | ||||||
| mid_color: Color, | ||||||
| bottom_color: Color, | ||||||
| ) -> Image { | ||||||
| let top_color: Srgba = top_color.into(); | ||||||
| let mid_color: Srgba = mid_color.into(); | ||||||
| let bottom_color: Srgba = bottom_color.into(); | ||||||
| Image { | ||||||
| texture_view_descriptor: Some(TextureViewDescriptor { | ||||||
| dimension: Some(TextureViewDimension::Cube), | ||||||
| ..Default::default() | ||||||
| }), | ||||||
| ..Image::new( | ||||||
| Extent3d { | ||||||
| width: 1, | ||||||
| height: 1, | ||||||
| depth_or_array_layers: 6, | ||||||
| }, | ||||||
| TextureDimension::D2, | ||||||
| [ | ||||||
| mid_color, | ||||||
| mid_color, | ||||||
| top_color, | ||||||
| bottom_color, | ||||||
| mid_color, | ||||||
| mid_color, | ||||||
| ] | ||||||
| .into_iter() | ||||||
| .flat_map(Srgba::to_u8_array) | ||||||
| .collect(), | ||||||
| TextureFormat::Rgba8UnormSrgb, | ||||||
| RenderAssetUsages::RENDER_WORLD, | ||||||
| ) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub const DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE: Handle<Image> = | ||||||
| uuid_handle!("99e3f21e-9c08-4924-9895-fa8599416316"); | ||||||
|
|
||||||
| impl Default for EnvironmentMapLight { | ||||||
| fn default() -> Self { | ||||||
| EnvironmentMapLight { | ||||||
| diffuse_map: Handle::default(), | ||||||
| specular_map: Handle::default(), | ||||||
| diffuse_map: DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, | ||||||
| specular_map: DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, | ||||||
| intensity: 0.0, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be made non-zero
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nah |
||||||
| rotation: Quat::IDENTITY, | ||||||
| affects_lightmapped_mesh_diffuse: true, | ||||||
| affects_lightmapped_mesh_diffuse: false, | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the default environment light be pure white like this? I think a better default would be a sky-like gradient, or maybe even the atmosphere env light. probably out of scope for this PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for this PR should keep it white to keep it similar to the current default of ambient light, but I agree that in the future we should consider a nicer default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree, but thats for a different PR