Enable depth of field on webgpu (#13374)

# Objective

- Depth of field is currently disabled on any wasm targets, but the bug
it's trying to avoid is only an issue in webgl.

## Solution

- Enable dof when compiling for webgpu
- I also remove the msaa check because sampling a depth texture doesn't
work with or without msaa in webgl
- Unfortunately, Bokeh seems to be broken when using webgpu, so default
to Gaussian instead to make sure the defaults have the broadest platform
support

## Testing

- I added dof to the 3d_shapes example and compiled it to webgpu to
confirm it works
- I also tried compiling to webgl to confirm things still works and dof
isn't rendered.

---------

Co-authored-by: James Liu <contact@jamessliu.com>
This commit is contained in:
IceSentry 2024-05-16 02:48:28 -04:00 committed by GitHub
parent f61c55fd90
commit d9993a8092
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -119,16 +119,21 @@ pub enum DepthOfFieldMode {
/// ///
/// For more information, see [Wikipedia's article on *bokeh*]. /// For more information, see [Wikipedia's article on *bokeh*].
/// ///
/// This is the default. /// This doesn't work on WebGPU.
/// ///
/// [Wikipedia's article on *bokeh*]: https://en.wikipedia.org/wiki/Bokeh /// [Wikipedia's article on *bokeh*]: https://en.wikipedia.org/wiki/Bokeh
#[default]
Bokeh, Bokeh,
/// A faster simulation, in which out-of-focus areas are simply blurred. /// A faster simulation, in which out-of-focus areas are simply blurred.
/// ///
/// This is less accurate to actual lens behavior and is generally less /// This is less accurate to actual lens behavior and is generally less
/// aesthetically pleasing but requires less video memory bandwidth. /// aesthetically pleasing but requires less video memory bandwidth.
///
/// This is the default.
///
/// This works on native and WebGPU.
/// If targeting native platforms, consider using [`DepthOfFieldMode::Bokeh`] instead.
#[default]
Gaussian, Gaussian,
} }
@ -790,12 +795,11 @@ impl SpecializedRenderPipeline for DepthOfFieldPipeline {
/// Extracts all [`DepthOfFieldSettings`] components into the render world. /// Extracts all [`DepthOfFieldSettings`] components into the render world.
fn extract_depth_of_field_settings( fn extract_depth_of_field_settings(
mut commands: Commands, mut commands: Commands,
msaa: Extract<Res<Msaa>>,
mut query: Extract<Query<(Entity, &DepthOfFieldSettings, &Projection)>>, mut query: Extract<Query<(Entity, &DepthOfFieldSettings, &Projection)>>,
) { ) {
if **msaa != Msaa::Off && !depth_textures_are_supported() { if !DEPTH_TEXTURE_SAMPLING_SUPPORTED {
info_once!( info_once!(
"Disabling depth of field on this platform because depth textures aren't available" "Disabling depth of field on this platform because depth textures aren't supported correctly"
); );
return; return;
} }
@ -889,10 +893,8 @@ impl DepthOfFieldPipelines {
/// `sampler2DShadow` and will cheerfully generate invalid GLSL that tries to /// `sampler2DShadow` and will cheerfully generate invalid GLSL that tries to
/// perform non-percentage-closer-filtering with such a sampler. Therefore we /// perform non-percentage-closer-filtering with such a sampler. Therefore we
/// disable depth of field entirely on WebGL 2. /// disable depth of field entirely on WebGL 2.
#[cfg(target_arch = "wasm32")] #[cfg(all(feature = "webgl", target_arch = "wasm32", not(feature = "webgpu")))]
fn depth_textures_are_supported() -> bool { const DEPTH_TEXTURE_SAMPLING_SUPPORTED: bool = false;
false
}
/// Returns true if multisampled depth textures are supported on this platform. /// Returns true if multisampled depth textures are supported on this platform.
/// ///
@ -901,7 +903,5 @@ fn depth_textures_are_supported() -> bool {
/// `sampler2DShadow` and will cheerfully generate invalid GLSL that tries to /// `sampler2DShadow` and will cheerfully generate invalid GLSL that tries to
/// perform non-percentage-closer-filtering with such a sampler. Therefore we /// perform non-percentage-closer-filtering with such a sampler. Therefore we
/// disable depth of field entirely on WebGL 2. /// disable depth of field entirely on WebGL 2.
#[cfg(not(target_arch = "wasm32"))] #[cfg(any(feature = "webgpu", not(target_arch = "wasm32")))]
fn depth_textures_are_supported() -> bool { const DEPTH_TEXTURE_SAMPLING_SUPPORTED: bool = true;
true
}