-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Generalized atmospheric scattering media #20838
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
Merged
alice-i-cecile
merged 21 commits into
bevyengine:main
from
ecoskey:feat/general_scattering
Oct 22, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d84604c
use lut sampling in shaders
ecoskey 5c6b9db
fixed stuff but big memory usage
ecoskey b4a9f0e
CPU-side code
ecoskey 14518e9
cleanup
ecoskey b7c2103
Fix NaNs in scattering integral
mate-h d83483f
use lut sampling in shaders
ecoskey 959dd16
fixed stuff but big memory usage
ecoskey 3bbe294
cleanup
ecoskey 5f34082
docs
ecoskey ce3662a
Merge branch 'feat/general_scattering' into m/general_scattering_fix
ecoskey b51148a
Merge pull request #8 from mate-h/m/general_scattering_fix
ecoskey 853b64f
more docs & cleanup
ecoskey 1d3a05e
more docs
ecoskey 2181d5a
module docs done
ecoskey f3b9345
release notes and migration guide
ecoskey 32db9dc
rename to EarthlikeAtmosphere
ecoskey bc194d3
merge branch 'main' into 'feat/general_scattering'
ecoskey 9827f42
add simple doc strings for GpuAtmosphere and ExtractedAtmosphere
ecoskey 570abbe
fix docs
ecoskey beec2c3
remove old todo
ecoskey e78a2df
fix nits
ecoskey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| use crate::{ | ||
| resources::{ | ||
| AtmosphereSamplers, AtmosphereTextures, AtmosphereTransform, AtmosphereTransforms, | ||
| AtmosphereTransformsOffset, | ||
| AtmosphereTransformsOffset, GpuAtmosphere, | ||
| }, | ||
| GpuAtmosphereSettings, GpuLights, LightMeta, ViewLightsUniformOffset, | ||
| ExtractedAtmosphere, GpuAtmosphereSettings, GpuLights, LightMeta, ViewLightsUniformOffset, | ||
| }; | ||
| use bevy_asset::{load_embedded_asset, AssetServer, Assets, Handle, RenderAssetUsages}; | ||
| use bevy_ecs::{ | ||
|
|
@@ -29,8 +29,6 @@ use bevy_render::{ | |
| use bevy_utils::default; | ||
| use tracing::warn; | ||
|
|
||
| use super::Atmosphere; | ||
|
|
||
| // Render world representation of an environment map light for the atmosphere | ||
| #[derive(Component, ExtractComponent, Clone)] | ||
| pub struct AtmosphereEnvironmentMap { | ||
|
|
@@ -65,26 +63,33 @@ pub struct AtmosphereProbePipeline { | |
| pub fn init_atmosphere_probe_layout(mut commands: Commands) { | ||
| let environment = BindGroupLayoutDescriptor::new( | ||
| "environment_bind_group_layout", | ||
| &BindGroupLayoutEntries::sequential( | ||
| &BindGroupLayoutEntries::with_indices( | ||
| ShaderStages::COMPUTE, | ||
| ( | ||
| uniform_buffer::<Atmosphere>(true), | ||
| uniform_buffer::<GpuAtmosphereSettings>(true), | ||
| uniform_buffer::<AtmosphereTransform>(true), | ||
| uniform_buffer::<ViewUniform>(true), | ||
| uniform_buffer::<GpuLights>(true), | ||
| texture_2d(TextureSampleType::Float { filterable: true }), //transmittance lut and sampler | ||
| sampler(SamplerBindingType::Filtering), | ||
| texture_2d(TextureSampleType::Float { filterable: true }), //multiscattering lut and sampler | ||
| sampler(SamplerBindingType::Filtering), | ||
| texture_2d(TextureSampleType::Float { filterable: true }), //sky view lut and sampler | ||
| sampler(SamplerBindingType::Filtering), | ||
| texture_3d(TextureSampleType::Float { filterable: true }), //aerial view lut ans sampler | ||
| sampler(SamplerBindingType::Filtering), | ||
| texture_storage_2d_array( | ||
| // output 2D array texture | ||
| TextureFormat::Rgba16Float, | ||
| StorageTextureAccess::WriteOnly, | ||
| (0, uniform_buffer::<GpuAtmosphere>(true)), | ||
| (1, uniform_buffer::<GpuAtmosphereSettings>(true)), | ||
| (2, uniform_buffer::<AtmosphereTransform>(true)), | ||
| (3, uniform_buffer::<ViewUniform>(true)), | ||
| (4, uniform_buffer::<GpuLights>(true)), | ||
| //transmittance lut and sampler | ||
| (8, texture_2d(TextureSampleType::default())), | ||
| (9, sampler(SamplerBindingType::Filtering)), | ||
| //multiscattering lut and sampler | ||
| (10, texture_2d(TextureSampleType::default())), | ||
| (11, sampler(SamplerBindingType::Filtering)), | ||
| //sky view lut and sampler | ||
| (12, texture_2d(TextureSampleType::default())), | ||
| (13, sampler(SamplerBindingType::Filtering)), | ||
| //aerial view lut ans sampler | ||
| (14, texture_3d(TextureSampleType::default())), | ||
| (15, sampler(SamplerBindingType::Filtering)), | ||
| // output 2D array texture | ||
| ( | ||
| 16, | ||
| texture_storage_2d_array( | ||
| TextureFormat::Rgba16Float, | ||
| StorageTextureAccess::WriteOnly, | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
|
|
@@ -101,7 +106,7 @@ pub(super) fn prepare_atmosphere_probe_bind_groups( | |
| view_uniforms: Res<ViewUniforms>, | ||
| lights_uniforms: Res<LightMeta>, | ||
| atmosphere_transforms: Res<AtmosphereTransforms>, | ||
| atmosphere_uniforms: Res<ComponentUniforms<Atmosphere>>, | ||
| atmosphere_uniforms: Res<ComponentUniforms<GpuAtmosphere>>, | ||
| settings_uniforms: Res<ComponentUniforms<GpuAtmosphereSettings>>, | ||
| pipeline_cache: Res<PipelineCache>, | ||
| mut commands: Commands, | ||
|
|
@@ -110,21 +115,21 @@ pub(super) fn prepare_atmosphere_probe_bind_groups( | |
| let environment = render_device.create_bind_group( | ||
| "environment_bind_group", | ||
| &pipeline_cache.get_bind_group_layout(&layouts.environment), | ||
| &BindGroupEntries::sequential(( | ||
| atmosphere_uniforms.binding().unwrap(), | ||
| settings_uniforms.binding().unwrap(), | ||
| atmosphere_transforms.uniforms().binding().unwrap(), | ||
| view_uniforms.uniforms.binding().unwrap(), | ||
| lights_uniforms.view_gpu_lights.binding().unwrap(), | ||
| &textures.transmittance_lut.default_view, | ||
| &samplers.transmittance_lut, | ||
| &textures.multiscattering_lut.default_view, | ||
| &samplers.multiscattering_lut, | ||
| &textures.sky_view_lut.default_view, | ||
| &samplers.sky_view_lut, | ||
| &textures.aerial_view_lut.default_view, | ||
| &samplers.aerial_view_lut, | ||
| &textures.environment, | ||
| &BindGroupEntries::with_indices(( | ||
|
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. Agreed that doing the switch to with_indices is warranted in this case, so let's just stick to it for now until we re-organize the binding in a dedicated PR. |
||
| (0, atmosphere_uniforms.binding().unwrap()), | ||
| (1, settings_uniforms.binding().unwrap()), | ||
| (2, atmosphere_transforms.uniforms().binding().unwrap()), | ||
| (3, view_uniforms.uniforms.binding().unwrap()), | ||
| (4, lights_uniforms.view_gpu_lights.binding().unwrap()), | ||
| (8, &textures.transmittance_lut.default_view), | ||
| (9, &samplers.transmittance_lut), | ||
| (10, &textures.multiscattering_lut.default_view), | ||
| (11, &samplers.multiscattering_lut), | ||
| (12, &textures.sky_view_lut.default_view), | ||
| (13, &samplers.sky_view_lut), | ||
| (14, &textures.aerial_view_lut.default_view), | ||
| (15, &samplers.aerial_view_lut), | ||
| (16, &textures.environment), | ||
| )), | ||
| ); | ||
|
|
||
|
|
@@ -135,7 +140,7 @@ pub(super) fn prepare_atmosphere_probe_bind_groups( | |
| } | ||
|
|
||
| pub(super) fn prepare_probe_textures( | ||
| view_textures: Query<&AtmosphereTextures, With<Atmosphere>>, | ||
| view_textures: Query<&AtmosphereTextures, With<ExtractedAtmosphere>>, | ||
| probes: Query< | ||
| (Entity, &AtmosphereEnvironmentMap), | ||
| ( | ||
|
|
@@ -246,7 +251,7 @@ pub fn prepare_atmosphere_probe_components( | |
|
|
||
| pub(super) struct EnvironmentNode { | ||
| main_view_query: QueryState<( | ||
| Read<DynamicUniformIndex<Atmosphere>>, | ||
| Read<DynamicUniformIndex<GpuAtmosphere>>, | ||
| Read<DynamicUniformIndex<GpuAtmosphereSettings>>, | ||
| Read<AtmosphereTransformsOffset>, | ||
| Read<ViewUniformOffset>, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.