11use crate :: {
22 resources:: {
33 AtmosphereSamplers , AtmosphereTextures , AtmosphereTransform , AtmosphereTransforms ,
4- AtmosphereTransformsOffset ,
4+ AtmosphereTransformsOffset , GpuAtmosphere ,
55 } ,
6- GpuAtmosphereSettings , GpuLights , LightMeta , ViewLightsUniformOffset ,
6+ ExtractedAtmosphere , GpuAtmosphereSettings , GpuLights , LightMeta , ViewLightsUniformOffset ,
77} ;
88use bevy_asset:: { load_embedded_asset, AssetServer , Assets , Handle , RenderAssetUsages } ;
99use bevy_ecs:: {
@@ -29,8 +29,6 @@ use bevy_render::{
2929use bevy_utils:: default;
3030use tracing:: warn;
3131
32- use super :: Atmosphere ;
33-
3432// Render world representation of an environment map light for the atmosphere
3533#[ derive( Component , ExtractComponent , Clone ) ]
3634pub struct AtmosphereEnvironmentMap {
@@ -63,28 +61,37 @@ pub struct AtmosphereProbePipeline {
6361}
6462
6563pub fn init_atmosphere_probe_layout ( mut commands : Commands , render_device : Res < RenderDevice > ) {
64+ const FILTERED_TEX : TextureSampleType = TextureSampleType :: Float { filterable : true } ;
65+ const FILTERED_SMP : SamplerBindingType = SamplerBindingType :: Filtering ;
6666 let environment = render_device. create_bind_group_layout (
6767 "environment_bind_group_layout" ,
68- & BindGroupLayoutEntries :: sequential (
68+ & BindGroupLayoutEntries :: with_indices (
6969 ShaderStages :: COMPUTE ,
7070 (
71- uniform_buffer :: < Atmosphere > ( true ) ,
72- uniform_buffer :: < GpuAtmosphereSettings > ( true ) ,
73- uniform_buffer :: < AtmosphereTransform > ( true ) ,
74- uniform_buffer :: < ViewUniform > ( true ) ,
75- uniform_buffer :: < GpuLights > ( true ) ,
76- texture_2d ( TextureSampleType :: Float { filterable : true } ) , //transmittance lut and sampler
77- sampler ( SamplerBindingType :: Filtering ) ,
78- texture_2d ( TextureSampleType :: Float { filterable : true } ) , //multiscattering lut and sampler
79- sampler ( SamplerBindingType :: Filtering ) ,
80- texture_2d ( TextureSampleType :: Float { filterable : true } ) , //sky view lut and sampler
81- sampler ( SamplerBindingType :: Filtering ) ,
82- texture_3d ( TextureSampleType :: Float { filterable : true } ) , //aerial view lut ans sampler
83- sampler ( SamplerBindingType :: Filtering ) ,
84- texture_storage_2d_array (
85- // output 2D array texture
86- TextureFormat :: Rgba16Float ,
87- StorageTextureAccess :: WriteOnly ,
71+ ( 0 , uniform_buffer :: < GpuAtmosphere > ( true ) ) ,
72+ ( 1 , uniform_buffer :: < GpuAtmosphereSettings > ( true ) ) ,
73+ ( 2 , uniform_buffer :: < AtmosphereTransform > ( true ) ) ,
74+ ( 3 , uniform_buffer :: < ViewUniform > ( true ) ) ,
75+ ( 4 , uniform_buffer :: < GpuLights > ( true ) ) ,
76+ //transmittance lut and sampler
77+ ( 8 , texture_2d ( FILTERED_TEX ) ) ,
78+ ( 9 , sampler ( FILTERED_SMP ) ) ,
79+ //multiscattering lut and sampler
80+ ( 10 , texture_2d ( FILTERED_TEX ) ) ,
81+ ( 11 , sampler ( FILTERED_SMP ) ) ,
82+ //sky view lut and sampler
83+ ( 12 , texture_2d ( FILTERED_TEX ) ) ,
84+ ( 13 , sampler ( FILTERED_SMP ) ) ,
85+ //aerial view lut ans sampler
86+ ( 14 , texture_3d ( FILTERED_TEX ) ) ,
87+ ( 15 , sampler ( FILTERED_SMP ) ) ,
88+ // output 2D array texture
89+ (
90+ 16 ,
91+ texture_storage_2d_array (
92+ TextureFormat :: Rgba16Float ,
93+ StorageTextureAccess :: WriteOnly ,
94+ ) ,
8895 ) ,
8996 ) ,
9097 ) ,
@@ -101,29 +108,29 @@ pub(super) fn prepare_atmosphere_probe_bind_groups(
101108 view_uniforms : Res < ViewUniforms > ,
102109 lights_uniforms : Res < LightMeta > ,
103110 atmosphere_transforms : Res < AtmosphereTransforms > ,
104- atmosphere_uniforms : Res < ComponentUniforms < Atmosphere > > ,
111+ atmosphere_uniforms : Res < ComponentUniforms < GpuAtmosphere > > ,
105112 settings_uniforms : Res < ComponentUniforms < GpuAtmosphereSettings > > ,
106113 mut commands : Commands ,
107114) {
108115 for ( entity, textures) in & probes {
109116 let environment = render_device. create_bind_group (
110117 "environment_bind_group" ,
111118 & layouts. environment ,
112- & BindGroupEntries :: sequential ( (
113- atmosphere_uniforms. binding ( ) . unwrap ( ) ,
114- settings_uniforms. binding ( ) . unwrap ( ) ,
115- atmosphere_transforms. uniforms ( ) . binding ( ) . unwrap ( ) ,
116- view_uniforms. uniforms . binding ( ) . unwrap ( ) ,
117- lights_uniforms. view_gpu_lights . binding ( ) . unwrap ( ) ,
118- & textures. transmittance_lut . default_view ,
119- & samplers. transmittance_lut ,
120- & textures. multiscattering_lut . default_view ,
121- & samplers. multiscattering_lut ,
122- & textures. sky_view_lut . default_view ,
123- & samplers. sky_view_lut ,
124- & textures. aerial_view_lut . default_view ,
125- & samplers. aerial_view_lut ,
126- & textures. environment ,
119+ & BindGroupEntries :: with_indices ( (
120+ ( 0 , atmosphere_uniforms. binding ( ) . unwrap ( ) ) ,
121+ ( 1 , settings_uniforms. binding ( ) . unwrap ( ) ) ,
122+ ( 2 , atmosphere_transforms. uniforms ( ) . binding ( ) . unwrap ( ) ) ,
123+ ( 3 , view_uniforms. uniforms . binding ( ) . unwrap ( ) ) ,
124+ ( 4 , lights_uniforms. view_gpu_lights . binding ( ) . unwrap ( ) ) ,
125+ ( 8 , & textures. transmittance_lut . default_view ) ,
126+ ( 9 , & samplers. transmittance_lut ) ,
127+ ( 10 , & textures. multiscattering_lut . default_view ) ,
128+ ( 11 , & samplers. multiscattering_lut ) ,
129+ ( 12 , & textures. sky_view_lut . default_view ) ,
130+ ( 13 , & samplers. sky_view_lut ) ,
131+ ( 14 , & textures. aerial_view_lut . default_view ) ,
132+ ( 15 , & samplers. aerial_view_lut ) ,
133+ ( 16 , & textures. environment ) ,
127134 ) ) ,
128135 ) ;
129136
@@ -134,7 +141,7 @@ pub(super) fn prepare_atmosphere_probe_bind_groups(
134141}
135142
136143pub ( super ) fn prepare_probe_textures (
137- view_textures : Query < & AtmosphereTextures , With < Atmosphere > > ,
144+ view_textures : Query < & AtmosphereTextures , With < ExtractedAtmosphere > > ,
138145 probes : Query <
139146 ( Entity , & AtmosphereEnvironmentMap ) ,
140147 (
@@ -245,7 +252,7 @@ pub fn prepare_atmosphere_probe_components(
245252
246253pub ( super ) struct EnvironmentNode {
247254 main_view_query : QueryState < (
248- Read < DynamicUniformIndex < Atmosphere > > ,
255+ Read < DynamicUniformIndex < GpuAtmosphere > > ,
249256 Read < DynamicUniformIndex < GpuAtmosphereSettings > > ,
250257 Read < AtmosphereTransformsOffset > ,
251258 Read < ViewUniformOffset > ,
0 commit comments