Skip to content
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

Stop copying the light probe array to the stack in the shader. #11805

Merged
merged 1 commit into from
Feb 10, 2024
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
5 changes: 1 addition & 4 deletions crates/bevy_pbr/src/light_probe/environment_map.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ fn compute_radiances(
var radiances: EnvironmentMapRadiances;

// Search for a reflection probe that contains the fragment.
var query_result = query_light_probe(
light_probes.reflection_probes,
light_probes.reflection_probe_count,
world_position);
var query_result = query_light_probe(world_position, /*is_irradiance_volume=*/ false);

// If we didn't find a reflection probe, use the view environment map if applicable.
if (query_result.texture_index < 0) {
Expand Down
5 changes: 1 addition & 4 deletions crates/bevy_pbr/src/light_probe/irradiance_volume.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
// Slide 28, "Ambient Cube Basis"
fn irradiance_volume_light(world_position: vec3<f32>, N: vec3<f32>) -> vec3<f32> {
// Search for an irradiance volume that contains the fragment.
let query_result = query_light_probe(
light_probes.irradiance_volumes,
light_probes.irradiance_volume_count,
world_position);
let query_result = query_light_probe(world_position, /*is_irradiance_volume=*/ true);

// If there was no irradiance volume found, bail out.
if (query_result.texture_index < 0) {
Expand Down
21 changes: 15 additions & 6 deletions crates/bevy_pbr/src/light_probe/light_probe.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define_import_path bevy_pbr::light_probe

#import bevy_pbr::mesh_view_bindings::light_probes
#import bevy_pbr::mesh_view_types::LightProbe

// The result of searching for a light probe.
Expand Down Expand Up @@ -28,20 +29,28 @@ fn transpose_affine_matrix(matrix: mat3x4<f32>) -> mat4x4<f32> {
//
// TODO: Interpolate between multiple light probes.
fn query_light_probe(
in_light_probes: array<LightProbe, 8u>,
light_probe_count: i32,
world_position: vec3<f32>,
is_irradiance_volume: bool,
) -> LightProbeQueryResult {
// This is needed to index into the array with a non-constant expression.
var light_probes = in_light_probes;

var result: LightProbeQueryResult;
result.texture_index = -1;

var light_probe_count: i32;
if is_irradiance_volume {
light_probe_count = light_probes.irradiance_volume_count;
} else {
light_probe_count = light_probes.reflection_probe_count;
}

for (var light_probe_index: i32 = 0;
light_probe_index < light_probe_count && result.texture_index < 0;
light_probe_index += 1) {
let light_probe = light_probes[light_probe_index];
var light_probe: LightProbe;
if is_irradiance_volume {
light_probe = light_probes.irradiance_volumes[light_probe_index];
} else {
light_probe = light_probes.reflection_probes[light_probe_index];
}

// Unpack the inverse transform.
let inverse_transform =
Expand Down