Apply additional feedback on names and comments

This commit is contained in:
Marco Buono 2023-10-08 18:19:34 -03:00
parent 3925745870
commit 5fe0258e79
5 changed files with 43 additions and 37 deletions

View File

@ -31,24 +31,23 @@ pub struct Camera3d {
pub depth_load_op: Camera3dDepthLoadOp,
/// The texture usages for the depth texture created for the main 3d pass.
pub depth_texture_usages: Camera3dDepthTextureUsage,
/// How many individual steps should be performed in the transmissive 3d pass.
/// How many individual steps should be performed in the [`Transmissive3d`](crate::core_3d::Transmissive3d) pass.
///
/// Roughly corresponds to how many “layers of transparency” are rendered for
/// transmissive objects. Each step requires making one additional texture copy,
/// so it's recommended to keep this number to a resonably low value. Defaults to `1`.
/// Roughly corresponds to how many “layers of transparency” are rendered for screen space
/// refractions for specular transmissive objects. Each step requires making one additional
/// texture copy, so it's recommended to keep this number to a resonably low value. Defaults to `1`.
///
/// Setting this to `0` disables the screen-space refraction effect entirely, and falls
/// back to refracting the environment map light's texture.
pub transmissive_steps: usize,
/// The quality of the transmissive blur effect, applied to the whatever's “behind” transmissive
/// objects when their `roughness` is greater than `0.0`.
/// back to refracting only the environment map light's texture.
pub screen_space_transmission_steps: usize,
/// Controls the quality of the blur effect applied to the background refracted through
/// specular transmissive materials. (The blur effect kicks in when a material's `roughness` > `0.0`
/// and `screen_space_transmission_steps` > `0`, producing a "frosted glass" look.)
///
/// Higher qualities are more GPU-intensive.
///
/// **Note:** You can get better-looking results at any quality level by enabling TAA. See: [`TemporalAntiAliasPlugin`](crate::experimental::taa::TemporalAntiAliasPlugin).
pub transmissive_quality: TransmissiveQuality,
pub screen_space_transmission_blur_quality: ScreenSpaceTransmissiveBlurQuality,
}
impl Default for Camera3d {
@ -57,8 +56,8 @@ impl Default for Camera3d {
clear_color: ClearColorConfig::Default,
depth_load_op: Default::default(),
depth_texture_usages: TextureUsages::RENDER_ATTACHMENT.into(),
transmissive_steps: 1,
transmissive_quality: Default::default(),
screen_space_transmission_steps: 1,
screen_space_transmission_blur_quality: Default::default(),
}
}
}
@ -111,7 +110,7 @@ impl From<Camera3dDepthLoadOp> for LoadOp<f32> {
/// **Note:** You can get better-looking results at any quality level by enabling TAA. See: [`TemporalAntiAliasPlugin`](crate::experimental::taa::TemporalAntiAliasPlugin).
#[derive(Resource, Default, Clone, Copy, Reflect, PartialEq, PartialOrd, Debug)]
#[reflect(Resource)]
pub enum TransmissiveQuality {
pub enum ScreenSpaceTransmissiveBlurQuality {
/// Best performance at the cost of quality. Suitable for lower end GPUs. (e.g. Mobile)
///
/// `num_taps` = 4

View File

@ -66,18 +66,21 @@ impl ViewNode for MainTransmissivePass3dNode {
let _main_transmissive_pass_3d_span = info_span!("main_transmissive_pass_3d").entered();
if !transmissive_phase.items.is_empty() {
let transmissive_steps = camera_3d.transmissive_steps;
if transmissive_steps > 0 {
let screen_space_transmission_steps = camera_3d.screen_space_transmission_steps;
if screen_space_transmission_steps > 0 {
let transmission =
transmission.expect("`ViewTransmissionTexture` should exist at this point");
// `transmissive_phase.items` are depth sorted, so we split them into N = `transmissive_steps` ranges,
// rendering them back-to-front in multiple steps, allowing multiple levels of transparency.
// `transmissive_phase.items` are depth sorted, so we split them into N = `screen_space_transmission_steps`
// ranges, rendering them back-to-front in multiple steps, allowing multiple levels of transparency.
//
// Note: For the sake of simplicity, we currently split items evenly among steps. In the future, we
// might want to use a more sophisticated heuristic (e.g. based on view bounds, or with an exponential
// falloff so that nearby objects have more levels of transparency available to them)
for range in split_range(0..transmissive_phase.items.len(), transmissive_steps) {
for range in split_range(
0..transmissive_phase.items.len(),
screen_space_transmission_steps,
) {
// Copy the main texture to the transmission texture, allowing to use the color output of the
// previous step (or of the `Opaque3d` phase, for the first step) as a transmissive color input
render_context.command_encoder().copy_texture_to_texture(

View File

@ -547,7 +547,7 @@ pub fn prepare_core_3d_transmission_textures(
};
// Don't prepare a transmission texture if the number of steps is set to 0
if camera_3d.transmissive_steps == 0 {
if camera_3d.screen_space_transmission_steps == 0 {
continue;
}

View File

@ -7,7 +7,8 @@ use bevy_app::{App, Plugin};
use bevy_asset::{Asset, AssetApp, AssetEvent, AssetId, AssetServer, Assets, Handle};
use bevy_core_pipeline::{
core_3d::{
AlphaMask3d, Camera3d, Opaque3d, Transmissive3d, TransmissiveQuality, Transparent3d,
AlphaMask3d, Camera3d, Opaque3d, ScreenSpaceTransmissiveBlurQuality, Transmissive3d,
Transparent3d,
},
prepass::NormalPrepass,
tonemapping::{DebandDither, Tonemapping},
@ -426,13 +427,13 @@ const fn tonemapping_pipeline_key(tonemapping: Tonemapping) -> MeshPipelineKey {
}
const fn transmissive_quality_pipeline_key(
transmissive_quality: TransmissiveQuality,
transmissive_quality: ScreenSpaceTransmissiveBlurQuality,
) -> MeshPipelineKey {
match transmissive_quality {
TransmissiveQuality::Low => MeshPipelineKey::TRANSMISSIVE_QUALITY_LOW,
TransmissiveQuality::Medium => MeshPipelineKey::TRANSMISSIVE_QUALITY_MEDIUM,
TransmissiveQuality::High => MeshPipelineKey::TRANSMISSIVE_QUALITY_HIGH,
TransmissiveQuality::Ultra => MeshPipelineKey::TRANSMISSIVE_QUALITY_ULTRA,
ScreenSpaceTransmissiveBlurQuality::Low => MeshPipelineKey::TRANSMISSIVE_QUALITY_LOW,
ScreenSpaceTransmissiveBlurQuality::Medium => MeshPipelineKey::TRANSMISSIVE_QUALITY_MEDIUM,
ScreenSpaceTransmissiveBlurQuality::High => MeshPipelineKey::TRANSMISSIVE_QUALITY_HIGH,
ScreenSpaceTransmissiveBlurQuality::Ultra => MeshPipelineKey::TRANSMISSIVE_QUALITY_ULTRA,
}
}
@ -518,7 +519,8 @@ pub fn queue_material_meshes<M: Material>(
view_key |= MeshPipelineKey::SCREEN_SPACE_AMBIENT_OCCLUSION;
}
if let Some(camera_3d) = camera_3d {
view_key |= transmissive_quality_pipeline_key(camera_3d.transmissive_quality);
view_key |=
transmissive_quality_pipeline_key(camera_3d.screen_space_transmission_blur_quality);
}
let rangefinder = view.rangefinder3d();
for visible_entity in &visible_entities.entities {

View File

@ -20,7 +20,7 @@ use std::f32::consts::PI;
use bevy::{
core_pipeline::{
bloom::BloomSettings, core_3d::TransmissiveQuality, prepass::DepthPrepass,
bloom::BloomSettings, core_3d::ScreenSpaceTransmissiveBlurQuality, prepass::DepthPrepass,
tonemapping::Tonemapping,
},
pbr::{NotShadowCaster, NotTransmittedShadowReceiver, PointLightShadowMap},
@ -519,28 +519,30 @@ fn example_control_system(
}
}
if input.just_pressed(KeyCode::O) && camera_3d.transmissive_steps > 0 {
camera_3d.transmissive_steps -= 1;
if input.just_pressed(KeyCode::O) && camera_3d.screen_space_transmission_steps > 0 {
camera_3d.screen_space_transmission_steps -= 1;
}
if input.just_pressed(KeyCode::P) && camera_3d.transmissive_steps < 4 {
camera_3d.transmissive_steps += 1;
if input.just_pressed(KeyCode::P) && camera_3d.screen_space_transmission_steps < 4 {
camera_3d.screen_space_transmission_steps += 1;
}
if input.just_pressed(KeyCode::J) {
camera_3d.transmissive_quality = TransmissiveQuality::Low;
camera_3d.screen_space_transmission_blur_quality = ScreenSpaceTransmissiveBlurQuality::Low;
}
if input.just_pressed(KeyCode::K) {
camera_3d.transmissive_quality = TransmissiveQuality::Medium;
camera_3d.screen_space_transmission_blur_quality =
ScreenSpaceTransmissiveBlurQuality::Medium;
}
if input.just_pressed(KeyCode::L) {
camera_3d.transmissive_quality = TransmissiveQuality::High;
camera_3d.screen_space_transmission_blur_quality = ScreenSpaceTransmissiveBlurQuality::High;
}
if input.just_pressed(KeyCode::Semicolon) {
camera_3d.transmissive_quality = TransmissiveQuality::Ultra;
camera_3d.screen_space_transmission_blur_quality =
ScreenSpaceTransmissiveBlurQuality::Ultra;
}
let rotation = if input.pressed(KeyCode::Right) {
@ -580,7 +582,7 @@ fn example_control_system(
state.thickness,
state.ior,
state.perceptual_roughness,
camera_3d.transmissive_steps,
camera_3d.screen_space_transmission_steps,
);
}