From a2ac17c37a11825b6822e200369c600629c2319b Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Fri, 9 Jan 2026 19:46:14 -0500 Subject: [PATCH 1/4] Add EnvironmentMapLight creation helper functions --- crates/bevy_light/Cargo.toml | 1 + crates/bevy_light/src/probe.rs | 71 +++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/crates/bevy_light/Cargo.toml b/crates/bevy_light/Cargo.toml index 391f6031ed19f..f32e223071756 100644 --- a/crates/bevy_light/Cargo.toml +++ b/crates/bevy_light/Cargo.toml @@ -27,6 +27,7 @@ bevy_color = { path = "../bevy_color", version = "0.18.0-dev", features = [ # other tracing = { version = "0.1", default-features = false } +wgpu-types = { version = "27", default-features = false } [features] default = [] diff --git a/crates/bevy_light/src/probe.rs b/crates/bevy_light/src/probe.rs index 213a02b4a0619..c162872361c1b 100644 --- a/crates/bevy_light/src/probe.rs +++ b/crates/bevy_light/src/probe.rs @@ -1,10 +1,14 @@ -use bevy_asset::Handle; +use bevy_asset::{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, UVec2}; 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,6 +100,71 @@ pub struct EnvironmentMapLight { pub affects_lightmapped_mesh_diffuse: bool, } +impl EnvironmentMapLight { + /// An environment map with a uniform color, useful for uniform ambient lighting. + pub fn solid_color(assets: &mut Assets, color: Color) -> Self { + 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, + top_color: Color, + mid_color: Color, + bottom_color: Color, + ) -> 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, + ) + } + } +} + impl Default for EnvironmentMapLight { fn default() -> Self { EnvironmentMapLight { From 02142e649a9cfb9ff5e952be48dc94f855412921 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Fri, 9 Jan 2026 20:31:08 -0500 Subject: [PATCH 2/4] into --- crates/bevy_light/src/probe.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/bevy_light/src/probe.rs b/crates/bevy_light/src/probe.rs index c162872361c1b..c2c19306a7476 100644 --- a/crates/bevy_light/src/probe.rs +++ b/crates/bevy_light/src/probe.rs @@ -102,7 +102,8 @@ pub struct EnvironmentMapLight { impl EnvironmentMapLight { /// An environment map with a uniform color, useful for uniform ambient lighting. - pub fn solid_color(assets: &mut Assets, color: Color) -> Self { + pub fn solid_color(assets: &mut Assets, color: impl Into) -> Self { + let color = color.into(); Self::hemispherical_gradient(assets, color, color, color) } @@ -110,14 +111,14 @@ impl EnvironmentMapLight { /// at the horizon. Useful as a very simple 'sky'. pub fn hemispherical_gradient( assets: &mut Assets, - top_color: Color, - mid_color: Color, - bottom_color: Color, + top_color: impl Into, + mid_color: impl Into, + bottom_color: impl Into, ) -> Self { let handle = assets.add(Self::hemispherical_gradient_cubemap( - top_color, - mid_color, - bottom_color, + top_color.into(), + mid_color.into(), + bottom_color.into(), )); Self { From 10c5a5b04e98de97c704da861650ef08b163d022 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Tue, 13 Jan 2026 15:42:21 -0500 Subject: [PATCH 3/4] feedback --- crates/bevy_light/src/probe.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_light/src/probe.rs b/crates/bevy_light/src/probe.rs index c2c19306a7476..bbb3740c8c3f8 100644 --- a/crates/bevy_light/src/probe.rs +++ b/crates/bevy_light/src/probe.rs @@ -159,7 +159,7 @@ impl EnvironmentMapLight { .into_iter() .flat_map(Srgba::to_u8_array) .collect(), - TextureFormat::Rgba8UnormSrgb, + TextureFormat::Rgba16Float, RenderAssetUsages::RENDER_WORLD, ) } From 8644a7aac696886e4996e3f0ace54e824908f88c Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Wed, 14 Jan 2026 03:05:54 -0500 Subject: [PATCH 4/4] fix --- crates/bevy_light/Cargo.toml | 1 + crates/bevy_light/src/probe.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/bevy_light/Cargo.toml b/crates/bevy_light/Cargo.toml index f32e223071756..04cedbe6857fa 100644 --- a/crates/bevy_light/Cargo.toml +++ b/crates/bevy_light/Cargo.toml @@ -28,6 +28,7 @@ bevy_color = { path = "../bevy_color", version = "0.18.0-dev", features = [ # other tracing = { version = "0.1", default-features = false } wgpu-types = { version = "27", default-features = false } +half = "2.7.1" [features] default = [] diff --git a/crates/bevy_light/src/probe.rs b/crates/bevy_light/src/probe.rs index bbb3740c8c3f8..7f2ff4e4fd0a5 100644 --- a/crates/bevy_light/src/probe.rs +++ b/crates/bevy_light/src/probe.rs @@ -1,6 +1,6 @@ use bevy_asset::{Assets, Handle, RenderAssetUsages}; use bevy_camera::visibility::Visibility; -use bevy_color::{Color, ColorToPacked, Srgba}; +use bevy_color::{Color, ColorToComponents, Srgba}; use bevy_ecs::prelude::*; use bevy_image::Image; use bevy_math::{Quat, UVec2}; @@ -157,7 +157,8 @@ impl EnvironmentMapLight { mid_color, ] .into_iter() - .flat_map(Srgba::to_u8_array) + .flat_map(|c| c.to_f32_array().map(half::f16::from_f32)) + .flat_map(half::f16::to_le_bytes) .collect(), TextureFormat::Rgba16Float, RenderAssetUsages::RENDER_WORLD,