Use depth prepass data to reject values that are in front of the current fragment

This commit is contained in:
Marco Buono 2023-04-19 02:08:50 -03:00
parent adf2f0fa07
commit b1db977176
3 changed files with 17 additions and 9 deletions

View file

@ -988,12 +988,14 @@ pub fn queue_prepass_material_meshes<M: Material>(
rangefinder.distance(&mesh_uniform.transform) + material.properties.depth_bias;
match alpha_mode {
AlphaMode::Opaque => {
opaque_phase.add(Opaque3dPrepass {
entity: *visible_entity,
draw_function: opaque_draw_prepass,
pipeline_id,
distance,
});
if !material.properties.is_transmissive {
opaque_phase.add(Opaque3dPrepass {
entity: *visible_entity,
draw_function: opaque_draw_prepass,
pipeline_id,
distance,
});
}
}
AlphaMode::Mask(_) => {
alpha_mask_phase.add(AlphaMask3dPrepass {

View file

@ -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
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 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
// TODO: Use depth prepass data to reject values that are in front of the current fragment
result += textureSample(
view_transmission_texture,
view_transmission_sampler,
offset_position + dither_offset,
offset_position_with_dither,
);
}

View file

@ -17,7 +17,7 @@
use std::f32::consts::PI;
use bevy::{
core_pipeline::{bloom::BloomSettings, tonemapping::Tonemapping},
core_pipeline::{bloom::BloomSettings, prepass::DepthPrepass, tonemapping::Tonemapping},
pbr::{NotShadowCaster, NotTransmittedShadowReceiver, PointLightShadowMap},
prelude::*,
render::view::ColorGrading,
@ -343,6 +343,7 @@ fn setup(
tonemapping: Tonemapping::TonyMcMapface,
..default()
},
DepthPrepass,
EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),