mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 13:13:49 +00:00
Use depth prepass data to reject values that are in front of the current fragment
This commit is contained in:
parent
adf2f0fa07
commit
b1db977176
3 changed files with 17 additions and 9 deletions
|
@ -988,6 +988,7 @@ pub fn queue_prepass_material_meshes<M: Material>(
|
||||||
rangefinder.distance(&mesh_uniform.transform) + material.properties.depth_bias;
|
rangefinder.distance(&mesh_uniform.transform) + material.properties.depth_bias;
|
||||||
match alpha_mode {
|
match alpha_mode {
|
||||||
AlphaMode::Opaque => {
|
AlphaMode::Opaque => {
|
||||||
|
if !material.properties.is_transmissive {
|
||||||
opaque_phase.add(Opaque3dPrepass {
|
opaque_phase.add(Opaque3dPrepass {
|
||||||
entity: *visible_entity,
|
entity: *visible_entity,
|
||||||
draw_function: opaque_draw_prepass,
|
draw_function: opaque_draw_prepass,
|
||||||
|
@ -995,6 +996,7 @@ pub fn queue_prepass_material_meshes<M: Material>(
|
||||||
distance,
|
distance,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
AlphaMode::Mask(_) => {
|
AlphaMode::Mask(_) => {
|
||||||
alpha_mask_phase.add(AlphaMask3dPrepass {
|
alpha_mask_phase.add(AlphaMask3dPrepass {
|
||||||
entity: *visible_entity,
|
entity: *visible_entity,
|
||||||
|
|
|
@ -336,13 +336,18 @@ fn fetch_transmissive_background(offset_position: vec2<f32>, frag_coord: vec3<f3
|
||||||
// Magic numbers have been empirically chosen to produce blurry results that look “smooth”
|
// Magic numbers have been empirically chosen to produce blurry results that look “smooth”
|
||||||
let dither = screen_space_dither(frag_coord.xy + vec2<f32>(f32(i) * 4773.0, f32(i) * 1472.0));
|
let dither = screen_space_dither(frag_coord.xy + vec2<f32>(f32(i) * 4773.0, f32(i) * 1472.0));
|
||||||
let dither_offset = (blur_intensity * 7.0) * (blur_intensity * 7.0) * (30.0 * dither.yz + 0.03 * normalize(dither).xy) * vec2<f32>(1.0, -aspect);
|
let dither_offset = (blur_intensity * 7.0) * (blur_intensity * 7.0) * (30.0 * dither.yz + 0.03 * normalize(dither).xy) * vec2<f32>(1.0, -aspect);
|
||||||
|
let offset_position_with_dither = offset_position + dither_offset;
|
||||||
|
|
||||||
|
// Use depth prepass data to reject values that are in front of the current fragment
|
||||||
|
if (prepass_depth(vec4<f32>(offset_position_with_dither * view.viewport.zw, 0.0, 0.0), 0u) > frag_coord.z) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Sample the view transmission texture at the offset position + dither offset, to get the background color
|
// Sample the view transmission texture at the offset position + dither offset, to get the background color
|
||||||
// TODO: Use depth prepass data to reject values that are in front of the current fragment
|
|
||||||
result += textureSample(
|
result += textureSample(
|
||||||
view_transmission_texture,
|
view_transmission_texture,
|
||||||
view_transmission_sampler,
|
view_transmission_sampler,
|
||||||
offset_position + dither_offset,
|
offset_position_with_dither,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
core_pipeline::{bloom::BloomSettings, tonemapping::Tonemapping},
|
core_pipeline::{bloom::BloomSettings, prepass::DepthPrepass, tonemapping::Tonemapping},
|
||||||
pbr::{NotShadowCaster, NotTransmittedShadowReceiver, PointLightShadowMap},
|
pbr::{NotShadowCaster, NotTransmittedShadowReceiver, PointLightShadowMap},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::view::ColorGrading,
|
render::view::ColorGrading,
|
||||||
|
@ -343,6 +343,7 @@ fn setup(
|
||||||
tonemapping: Tonemapping::TonyMcMapface,
|
tonemapping: Tonemapping::TonyMcMapface,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
DepthPrepass,
|
||||||
EnvironmentMapLight {
|
EnvironmentMapLight {
|
||||||
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
|
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
|
||||||
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
|
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
|
||||||
|
|
Loading…
Reference in a new issue