Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/atmosphere/aerial_view_lut.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}


@group(0) @binding(16) var aerial_view_lut_out: texture_storage_3d<rgba16float, write>;
@group(0) @binding(13) var aerial_view_lut_out: texture_storage_3d<rgba16float, write>;

@compute
@workgroup_size(16, 16, 1)
Expand Down
11 changes: 4 additions & 7 deletions crates/bevy_pbr/src/atmosphere/bindings.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
@group(0) @binding(7) var medium_sampler: sampler;

@group(0) @binding(8) var transmittance_lut: texture_2d<f32>;
@group(0) @binding(9) var transmittance_lut_sampler: sampler;
@group(0) @binding(10) var multiscattering_lut: texture_2d<f32>;
@group(0) @binding(11) var multiscattering_lut_sampler: sampler;
@group(0) @binding(12) var sky_view_lut: texture_2d<f32>;
@group(0) @binding(13) var sky_view_lut_sampler: sampler;
@group(0) @binding(14) var aerial_view_lut: texture_3d<f32>;
@group(0) @binding(15) var aerial_view_lut_sampler: sampler;
@group(0) @binding(9) var multiscattering_lut: texture_2d<f32>;
@group(0) @binding(10) var sky_view_lut: texture_2d<f32>;
@group(0) @binding(11) var aerial_view_lut: texture_3d<f32>;
@group(0) @binding(12) var atmosphere_lut_sampler: sampler;
41 changes: 18 additions & 23 deletions crates/bevy_pbr/src/atmosphere/environment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
resources::{
AtmosphereSamplers, AtmosphereTextures, AtmosphereTransform, AtmosphereTransforms,
AtmosphereSampler, AtmosphereTextures, AtmosphereTransform, AtmosphereTransforms,
AtmosphereTransformsOffset, GpuAtmosphere,
},
ExtractedAtmosphere, GpuAtmosphereSettings, GpuLights, LightMeta, ViewLightsUniformOffset,
Expand Down Expand Up @@ -66,26 +66,21 @@ pub fn init_atmosphere_probe_layout(mut commands: Commands) {
&BindGroupLayoutEntries::with_indices(
ShaderStages::COMPUTE,
(
// uniforms
(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)),
// atmosphere luts and sampler
(8, texture_2d(TextureSampleType::default())), // transmittance
(9, texture_2d(TextureSampleType::default())), // multiscattering
(10, texture_2d(TextureSampleType::default())), // sky view
(11, texture_3d(TextureSampleType::default())), // aerial view
(12, sampler(SamplerBindingType::Filtering)),
// output 2D array texture
(
16,
13,
texture_storage_2d_array(
TextureFormat::Rgba16Float,
StorageTextureAccess::WriteOnly,
Expand All @@ -102,7 +97,7 @@ pub(super) fn prepare_atmosphere_probe_bind_groups(
probes: Query<(Entity, &AtmosphereProbeTextures), With<AtmosphereEnvironmentMap>>,
render_device: Res<RenderDevice>,
layouts: Res<AtmosphereProbeLayouts>,
samplers: Res<AtmosphereSamplers>,
atmosphere_sampler: Res<AtmosphereSampler>,
view_uniforms: Res<ViewUniforms>,
lights_uniforms: Res<LightMeta>,
atmosphere_transforms: Res<AtmosphereTransforms>,
Expand All @@ -116,20 +111,20 @@ pub(super) fn prepare_atmosphere_probe_bind_groups(
"environment_bind_group",
&pipeline_cache.get_bind_group_layout(&layouts.environment),
&BindGroupEntries::with_indices((
// uniforms
(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()),
// atmosphere luts and sampler
(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),
(9, &textures.multiscattering_lut.default_view),
(10, &textures.sky_view_lut.default_view),
(11, &textures.aerial_view_lut.default_view),
(12, &**atmosphere_sampler),
// output 2D array texture
(13, &textures.environment),
)),
);

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/atmosphere/environment.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
utils::sample_cube_dir
}

@group(0) @binding(16) var output: texture_storage_2d_array<rgba16float, write>;
@group(0) @binding(13) var output: texture_storage_2d_array<rgba16float, write>;

@compute @workgroup_size(8, 8, 1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
Expand Down
15 changes: 7 additions & 8 deletions crates/bevy_pbr/src/atmosphere/functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#import bevy_pbr::atmosphere::{
types::Atmosphere,
bindings::{
atmosphere, settings, view, lights, transmittance_lut, transmittance_lut_sampler,
multiscattering_lut, multiscattering_lut_sampler, sky_view_lut, sky_view_lut_sampler,
aerial_view_lut, aerial_view_lut_sampler, atmosphere_transforms, medium_density_lut,
medium_scattering_lut, medium_sampler,
atmosphere, settings, view, lights, transmittance_lut, atmosphere_lut_sampler,
multiscattering_lut, sky_view_lut, aerial_view_lut, atmosphere_transforms,
medium_density_lut, medium_scattering_lut, medium_sampler,
},
bruneton_functions::{
transmittance_lut_r_mu_to_uv, transmittance_lut_uv_to_r_mu,
Expand Down Expand Up @@ -117,7 +116,7 @@ fn sky_view_lut_uv_to_zenith_azimuth(r: f32, uv: vec2<f32>) -> vec2<f32> {

fn sample_transmittance_lut(r: f32, mu: f32) -> vec3<f32> {
let uv = transmittance_lut_r_mu_to_uv(r, mu);
return textureSampleLevel(transmittance_lut, transmittance_lut_sampler, uv, 0.0).rgb;
return textureSampleLevel(transmittance_lut, atmosphere_lut_sampler, uv, 0.0).rgb;
}

// NOTICE: This function is copyrighted by Eric Bruneton and INRIA, and falls
Expand All @@ -143,14 +142,14 @@ fn sample_transmittance_lut_segment(r: f32, mu: f32, t: f32) -> vec3<f32> {

fn sample_multiscattering_lut(r: f32, mu: f32) -> vec3<f32> {
let uv = multiscattering_lut_r_mu_to_uv(r, mu);
return textureSampleLevel(multiscattering_lut, multiscattering_lut_sampler, uv, 0.0).rgb;
return textureSampleLevel(multiscattering_lut, atmosphere_lut_sampler, uv, 0.0).rgb;
}

fn sample_sky_view_lut(r: f32, ray_dir_as: vec3<f32>) -> vec3<f32> {
let mu = ray_dir_as.y;
let azimuth = fast_atan2(ray_dir_as.x, -ray_dir_as.z);
let uv = sky_view_lut_r_mu_azimuth_to_uv(r, mu, azimuth);
return textureSampleLevel(sky_view_lut, sky_view_lut_sampler, uv, 0.0).rgb;
return textureSampleLevel(sky_view_lut, atmosphere_lut_sampler, uv, 0.0).rgb;
}

fn ndc_to_camera_dist(ndc: vec3<f32>) -> f32 {
Expand All @@ -170,7 +169,7 @@ fn sample_aerial_view_lut(uv: vec2<f32>, t: f32) -> vec3<f32> {
// we'd need to sample at the center of the previous slice, and vice-versa for
// sampling in the center of a slice.
let uvw = vec3(uv, saturate(t / t_max - 0.5 / num_slices));
let sample = textureSampleLevel(aerial_view_lut, aerial_view_lut_sampler, uvw, 0.0);
let sample = textureSampleLevel(aerial_view_lut, atmosphere_lut_sampler, uvw, 0.0);
// Since sampling anywhere between w=0 and w=t_slice will clamp to the first slice,
// we need to do a linear step over the first slice towards zero at the camera's
// position to recover the correct integral value.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/atmosphere/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use self::{
node::{AtmosphereLutsNode, AtmosphereNode, RenderSkyNode},
resources::{
prepare_atmosphere_bind_groups, prepare_atmosphere_textures, AtmosphereBindGroupLayouts,
AtmosphereLutPipelines, AtmosphereSamplers,
AtmosphereLutPipelines, AtmosphereSampler,
},
};

Expand Down Expand Up @@ -148,7 +148,7 @@ impl Plugin for AtmospherePlugin {
render_app
.insert_resource(AtmosphereBindGroupLayouts::new())
.init_resource::<RenderSkyBindGroupLayouts>()
.init_resource::<AtmosphereSamplers>()
.init_resource::<AtmosphereSampler>()
.init_resource::<AtmosphereLutPipelines>()
.init_resource::<AtmosphereTransforms>()
.init_resource::<SpecializedRenderPipelines<RenderSkyBindGroupLayouts>>()
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/atmosphere/multiscattering_lut.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

const PHI_2: vec2<f32> = vec2(1.3247179572447460259609088, 1.7548776662466927600495087);

@group(0) @binding(16) var multiscattering_lut_out: texture_storage_2d<rgba16float, write>;
@group(0) @binding(13) var multiscattering_lut_out: texture_storage_2d<rgba16float, write>;

fn s2_sequence(n: u32) -> vec2<f32> {
return fract(0.5 + f32(n) * PHI_2);
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/atmosphere/render_sky.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ enable dual_source_blending;
#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput

#ifdef MULTISAMPLED
@group(0) @binding(16) var depth_texture: texture_depth_multisampled_2d;
@group(0) @binding(13) var depth_texture: texture_depth_multisampled_2d;
#else
@group(0) @binding(16) var depth_texture: texture_depth_2d;
@group(0) @binding(13) var depth_texture: texture_depth_2d;
#endif

struct RenderSkyOutput {
Expand Down
Loading