Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
eed7a5e
Implement irradiance volumes.
pcwalton Oct 25, 2023
98bb888
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 21, 2024
cba53fb
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 21, 2024
b44606b
Large cleanups
pcwalton Jan 22, 2024
fb06e35
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 22, 2024
2a2ad49
Switch to 3D textures
pcwalton Jan 23, 2024
7c45a73
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 23, 2024
a09e905
Update for upstream changes
pcwalton Jan 23, 2024
b52f2c3
Hook up irradiance volumes with the light probe infrastructure
pcwalton Jan 24, 2024
1ba097e
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 24, 2024
d5f03cc
Add fallback when binding arrays aren't supported
pcwalton Jan 24, 2024
97b918c
Use the same 1x1x1 unit cuboid for all light probes
pcwalton Jan 24, 2024
5c098dc
Search through light maps properly; fix up the example
pcwalton Jan 24, 2024
3cd80d1
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 24, 2024
6f52710
Improve the example a lot; make intensity work
pcwalton Jan 25, 2024
3fec44d
Fix irradiance volume interaction with lightmaps, etc.
pcwalton Jan 26, 2024
e6b87d7
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 26, 2024
6828b57
Fix merge fallout
pcwalton Jan 26, 2024
61a218d
Write some docs and refactor a bit
pcwalton Jan 26, 2024
e2ede68
Fix off-by-half-voxel error; improve example
pcwalton Jan 26, 2024
c031ea7
Fix the demo documentation
pcwalton Jan 27, 2024
b213c42
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 27, 2024
04b9b9c
Fix README.md for new example
pcwalton Jan 27, 2024
ca1d55b
Remove needless extra dependencies
pcwalton Jan 27, 2024
526765b
Add a lot more documentation
pcwalton Jan 27, 2024
626a331
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 27, 2024
01614c0
Add a little more documentation
pcwalton Jan 27, 2024
4d94307
Add some more documentation, attempt using LaTeX
pcwalton Jan 27, 2024
8715322
Some more docs
pcwalton Jan 28, 2024
4133486
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 28, 2024
4012944
Add some more docs; minor fixes
pcwalton Jan 28, 2024
3658f09
Unbreak macOS, hopefully
pcwalton Jan 28, 2024
4679047
Fix single-irradiance-volume case
pcwalton Jan 28, 2024
33e04e0
Add a note about the binding array requirement
pcwalton Jan 28, 2024
f11974a
Minor documentation fixes
pcwalton Jan 28, 2024
a1fd586
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 28, 2024
ec66539
Unbreak Android
pcwalton Jan 28, 2024
e154aff
Clippy and rustfmt police
pcwalton Jan 28, 2024
9b3adbe
Clippy police
pcwalton Jan 28, 2024
bd1ad68
Switch to SH1
pcwalton Jan 29, 2024
5aa7d07
Revert "Switch to SH1"
pcwalton Jan 29, 2024
4b93e7a
Address some review comments
pcwalton Jan 29, 2024
58d8ae7
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 29, 2024
b33d265
Address a couple of review comments
pcwalton Jan 29, 2024
e37a2f9
Get rid of the `found` flag per review comments
pcwalton Jan 29, 2024
4bd2a59
Address some review comments
pcwalton Jan 29, 2024
1d68172
Fix off-by-half-voxel error
pcwalton Jan 29, 2024
d41d09d
Show the voxels as a gizmo
pcwalton Jan 29, 2024
802a787
Add more comments
pcwalton Jan 29, 2024
4b14471
rustfmt police; remove ambient when irradiance volumes are on
pcwalton Jan 29, 2024
5601bda
Update the rationale for ambient cubes
pcwalton Jan 29, 2024
6488c9f
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 29, 2024
6327f5a
Fix doc link
pcwalton Jan 29, 2024
19472e1
Visualize voxels
pcwalton Jan 30, 2024
cec1780
rustfmt
pcwalton Jan 30, 2024
52e3e6e
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 30, 2024
ee22f27
Switch from voxel spheres to voxel cubes
pcwalton Jan 30, 2024
b6fa053
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Jan 31, 2024
c849267
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Feb 2, 2024
c2a79f3
Address review comments
pcwalton Feb 2, 2024
11e5379
Update comment
pcwalton Feb 2, 2024
c6c3043
Address review comment
pcwalton Feb 2, 2024
211740d
Use a skybox in the irradiance volumes example
pcwalton Feb 2, 2024
5ca61e7
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Feb 2, 2024
108b931
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Feb 3, 2024
27e4322
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Feb 3, 2024
40c6e22
Create a dummy light probes uniform buffer if there are no light probes
pcwalton Feb 4, 2024
7d213ba
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Feb 4, 2024
9391113
Remove `RenderLightProbes`, simplifying and fixing things.
pcwalton Feb 4, 2024
3405756
Merge remote-tracking branch 'origin/main' into irradiance-volumes
pcwalton Feb 4, 2024
3894285
Address review comments
pcwalton Feb 5, 2024
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
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,17 @@ description = "Showcases wireframe rendering"
category = "3D Rendering"
wasm = false

[[example]]
name = "irradiance_volumes"
path = "examples/3d/irradiance_volumes.rs"
doc-scrape-examples = true

[package.metadata.example.irradiance_volumes]
name = "Irradiance Volumes"
description = "Demonstrates irradiance volumes"
category = "3D Rendering"
wasm = false

[[example]]
name = "lightmaps"
path = "examples/3d/lightmaps.rs"
Expand Down
Binary file added assets/irradiance_volumes/Example.vxgi.ktx2
Binary file not shown.
Binary file not shown.
35 changes: 35 additions & 0 deletions assets/shaders/irradiance_volume_voxel_visualization.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#import bevy_pbr::forward_io::VertexOutput
#import bevy_pbr::irradiance_volume
#import bevy_pbr::mesh_view_bindings

struct VoxelVisualizationIrradianceVolumeInfo {
transform: mat4x4<f32>,
inverse_transform: mat4x4<f32>,
resolution: vec3<u32>,
// A scale factor that's applied to the diffuse and specular light from the
// light probe. This is in units of cd/m² (candela per square meter).
intensity: f32,
}

@group(2) @binding(100)
var<uniform> irradiance_volume_info: VoxelVisualizationIrradianceVolumeInfo;

@fragment
fn fragment(mesh: VertexOutput) -> @location(0) vec4<f32> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do the cubes appear to be gray+shaded? I was thinking we would want to show essentially an "unlit" solid-color cube the color of the probe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are doing what you suggested, I'm fairly sure. I don't see any shading.

I believe the gray comes from the grayish background color, which is roughly the same in Blender so the indirect light from it is captured in the probe. The sides of the cubes will be a mix of the gray from the background with the colors of the floor visible from that cube side. The relative mix of gray vs. floor color is based on how much that side of the cube can "see".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the irradiance volumes are sampling the clear color/background? Seems strange. ClearColor shouldn't be used for lighting. Only a Skybox if specified, but not the clear color itself.

Copy link
Contributor Author

@pcwalton pcwalton Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In reality it's sampling the "world" in Blender which happens to be dark gray by default. Would you prefer that I change it to black? Or would you rather the world reflect the colors of the floor? (It can't be transparent because we don't have alpha here.)

From a physical perspective it's kind of arbitrary what we pick since the concept of "empty space with no color" doesn't exist in the real world.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that would be better. Or drop in a skybox and use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I added a skybox and re-baked the irradiance volume. It looks right to my eyes.

// Snap the world position we provide to `irradiance_volume_light()` to the
// middle of the nearest texel.
var unit_pos = (irradiance_volume_info.inverse_transform *
vec4(mesh.world_position.xyz, 1.0f)).xyz;
let resolution = vec3<f32>(irradiance_volume_info.resolution);
let stp = clamp((unit_pos + 0.5) * resolution, vec3(0.5f), resolution - vec3(0.5f));
let stp_rounded = round(stp - 0.5f) + 0.5f;
let rounded_world_pos = (irradiance_volume_info.transform * vec4(stp_rounded, 1.0f)).xyz;

// `irradiance_volume_light()` multiplies by intensity, so cancel it out.
// If we take intensity into account, the cubes will be way too bright.
let rgb = irradiance_volume::irradiance_volume_light(
mesh.world_position.xyz,
mesh.world_normal) / irradiance_volume_info.intensity;

return vec4<f32>(rgb, 1.0f);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@group(0) @binding(3) var dt_lut_texture: texture_3d<f32>;
@group(0) @binding(4) var dt_lut_sampler: sampler;
#else
@group(0) @binding(16) var dt_lut_texture: texture_3d<f32>;
@group(0) @binding(17) var dt_lut_sampler: sampler;
@group(0) @binding(18) var dt_lut_texture: texture_3d<f32>;
@group(0) @binding(19) var dt_lut_sampler: sampler;
#endif

fn sample_current_lut(p: vec3<f32>) -> vec3<f32> {
Expand Down
17 changes: 14 additions & 3 deletions crates/bevy_pbr/src/deferred/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
environment_map::RenderViewEnvironmentMaps, graph::LabelsPbr, MeshPipeline, MeshViewBindGroup,
ScreenSpaceAmbientOcclusionSettings, ViewLightProbesUniformOffset,
graph::LabelsPbr, irradiance_volume::IrradianceVolume, prelude::EnvironmentMapLight,
MeshPipeline, MeshViewBindGroup, RenderViewLightProbes, ScreenSpaceAmbientOcclusionSettings,
ViewLightProbesUniformOffset,
};
use bevy_app::prelude::*;
use bevy_asset::{load_internal_asset, Handle};
Expand Down Expand Up @@ -284,6 +285,10 @@ impl SpecializedRenderPipeline for DeferredLightingLayout {
shader_defs.push("ENVIRONMENT_MAP".into());
}

if key.contains(MeshPipelineKey::IRRADIANCE_VOLUME) {
shader_defs.push("IRRADIANCE_VOLUME".into());
}

if key.contains(MeshPipelineKey::NORMAL_PREPASS) {
shader_defs.push("NORMAL_PREPASS".into());
}
Expand Down Expand Up @@ -407,7 +412,8 @@ pub fn prepare_deferred_lighting_pipelines(
Has<DepthPrepass>,
Has<MotionVectorPrepass>,
),
Has<RenderViewEnvironmentMaps>,
Has<RenderViewLightProbes<EnvironmentMapLight>>,
Has<RenderViewLightProbes<IrradianceVolume>>,
),
With<DeferredPrepass>,
>,
Expand All @@ -421,6 +427,7 @@ pub fn prepare_deferred_lighting_pipelines(
ssao,
(normal_prepass, depth_prepass, motion_vector_prepass),
has_environment_maps,
has_irradiance_volumes,
) in &views
{
let mut view_key = MeshPipelineKey::from_hdr(view.hdr);
Expand Down Expand Up @@ -474,6 +481,10 @@ pub fn prepare_deferred_lighting_pipelines(
view_key |= MeshPipelineKey::ENVIRONMENT_MAP;
}

if has_irradiance_volumes {
view_key |= MeshPipelineKey::IRRADIANCE_VOLUME;
}

match shadow_filter_method.unwrap_or(&ShadowFilteringMethod::default()) {
ShadowFilteringMethod::Hardware2x2 => {
view_key |= MeshPipelineKey::SHADOW_FILTER_METHOD_HARDWARE_2X2;
Expand Down
Loading