Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 0 additions & 19 deletions crates/bevy_pbr/src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,25 +645,6 @@ pub const fn tonemapping_pipeline_key(tonemapping: Tonemapping) -> MeshPipelineK
}
}

pub const fn screen_space_specular_transmission_pipeline_key(
screen_space_transmissive_blur_quality: ScreenSpaceTransmissionQuality,
) -> MeshPipelineKey {
match screen_space_transmissive_blur_quality {
ScreenSpaceTransmissionQuality::Low => {
MeshPipelineKey::SCREEN_SPACE_SPECULAR_TRANSMISSION_LOW
}
ScreenSpaceTransmissionQuality::Medium => {
MeshPipelineKey::SCREEN_SPACE_SPECULAR_TRANSMISSION_MEDIUM
}
ScreenSpaceTransmissionQuality::High => {
MeshPipelineKey::SCREEN_SPACE_SPECULAR_TRANSMISSION_HIGH
}
ScreenSpaceTransmissionQuality::Ultra => {
MeshPipelineKey::SCREEN_SPACE_SPECULAR_TRANSMISSION_ULTRA
}
}
}

/// A system that ensures that
/// [`crate::render::mesh::extract_meshes_for_gpu_building`] re-extracts meshes
/// whose materials changed.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_pbr/src/pbr_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ pub struct StandardMaterial {
/// Specular transmission is implemented as a relatively expensive screen-space effect that allows occluded objects to be seen through the material,
/// with distortion and blur effects.
///
/// - [`crate::ScreenSpaceTransmission::screen_space_specular_transmission_steps`] can be used to enable transmissive objects
/// - [`crate::ScreenSpaceTransmission::steps`] can be used to enable transmissive objects
/// to be seen through other transmissive objects, at the cost of additional draw calls and texture copies; (Use with caution!)
/// - If a simplified approximation of specular transmission using only environment map lighting is sufficient, consider setting
/// [`crate::ScreenSpaceTransmission::screen_space_specular_transmission_steps`] to `0`.
/// [`crate::ScreenSpaceTransmission::steps`] to `0`.
/// - If purely diffuse light transmission is needed, (i.e. “translucency”) consider using [`StandardMaterial::diffuse_transmission`] instead,
/// for a much less expensive effect.
/// - Specular transmission is rendered before alpha blending, so any material with [`AlphaMode::Blend`], [`AlphaMode::Premultiplied`], [`AlphaMode::Add`] or [`AlphaMode::Multiply`]
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ pub fn check_views_need_specialization(
view_key |= MeshPipelineKey::DISTANCE_FOG;
}
if let Some(transmission) = transmission {
view_key |= screen_space_specular_transmission_pipeline_key(
transmission.screen_space_specular_transmission_quality,
);
view_key |= transmission.quality.pipeline_key();
}
if !view_key_cache
.get_mut(&view.retained_view_entity)
Expand Down
29 changes: 24 additions & 5 deletions crates/bevy_pbr/src/transmission/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use texture::ViewTransmissionTexture;

use texture::prepare_core_3d_transmission_textures;

use crate::DrawMaterial;
use crate::{DrawMaterial, MeshPipelineKey};

/// Enables screen-space transmission for cameras.
pub struct ScreenSpaceTransmissionPlugin;
Expand Down Expand Up @@ -82,21 +82,21 @@ pub struct ScreenSpaceTransmission {
/// to still have the environment map show up in your refractions, you can set the clear color's alpha to `0.0`.
/// Keep in mind that depending on the platform and your window settings, this may cause the window to become
/// transparent.
pub screen_space_specular_transmission_steps: usize,
pub steps: usize,
/// The quality of the screen space specular transmission blur effect, applied to whatever's behind transmissive
/// objects when their `roughness` is greater than `0.0`.
///
/// Higher qualities are more GPU-intensive.
///
/// **Note:** You can get better-looking results at any quality level by enabling TAA. See: `TemporalAntiAliasPlugin`
pub screen_space_specular_transmission_quality: ScreenSpaceTransmissionQuality,
pub quality: ScreenSpaceTransmissionQuality,
}

impl Default for ScreenSpaceTransmission {
fn default() -> Self {
Self {
screen_space_specular_transmission_steps: 1,
screen_space_specular_transmission_quality: Default::default(),
steps: 1,
quality: Default::default(),
}
}
}
Expand Down Expand Up @@ -131,3 +131,22 @@ pub enum ScreenSpaceTransmissionQuality {
/// `num_taps` = 32
Ultra,
}

impl ScreenSpaceTransmissionQuality {
pub const fn pipeline_key(self) -> MeshPipelineKey {
match self {
ScreenSpaceTransmissionQuality::Low => {
MeshPipelineKey::SCREEN_SPACE_SPECULAR_TRANSMISSION_LOW
}
ScreenSpaceTransmissionQuality::Medium => {
MeshPipelineKey::SCREEN_SPACE_SPECULAR_TRANSMISSION_MEDIUM
}
ScreenSpaceTransmissionQuality::High => {
MeshPipelineKey::SCREEN_SPACE_SPECULAR_TRANSMISSION_HIGH
}
ScreenSpaceTransmissionQuality::Ultra => {
MeshPipelineKey::SCREEN_SPACE_SPECULAR_TRANSMISSION_ULTRA
}
}
}
}
12 changes: 4 additions & 8 deletions crates/bevy_pbr/src/transmission/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ pub fn main_transmissive_pass_3d(
};

if !transmissive_phase.items.is_empty() {
let screen_space_specular_transmission_steps =
transmission_settings.screen_space_specular_transmission_steps;
if screen_space_specular_transmission_steps > 0 {
let steps = transmission_settings.steps;
if steps > 0 {
let transmission =
transmission.expect("`ViewTransmissionTexture` should exist at this point");

// `transmissive_phase.items` are depth sorted, so we split them into N = `screen_space_specular_transmission_steps`
// `transmissive_phase.items` are depth sorted, so we split them into N = `steps`
// ranges, rendering them back-to-front in multiple steps, allowing multiple levels of transparency.
for range in split_range(
0..transmissive_phase.items.len(),
screen_space_specular_transmission_steps,
) {
for range in split_range(0..transmissive_phase.items.len(), steps) {
// Copy the main texture to the transmission texture
ctx.command_encoder().copy_texture_to_texture(
target.main_texture().as_image_copy(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/transmission/phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Transmissive3d {

impl PhaseItem for Transmissive3d {
/// For now, automatic batching is disabled for transmissive items because their rendering is
/// split into multiple steps depending on [`crate::ScreenSpaceTransmission::screen_space_specular_transmission_steps`],
/// split into multiple steps depending on [`crate::ScreenSpaceTransmission::steps`],
/// which the batching system doesn't currently know about.
///
/// Having batching enabled would cause the same item to be drawn multiple times across different
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/transmission/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn prepare_core_3d_transmission_textures(
};

// Don't prepare a transmission texture if the number of steps is set to 0
if transmission.screen_space_specular_transmission_steps == 0 {
if transmission.steps == 0 {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/transmission/transmission.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn fetch_transmissive_background(offset_position: vec2<f32>, frag_coord: vec3<f3
let blur_intensity = (perceptual_roughness * perceptual_roughness) / view_z;

#ifdef SCREEN_SPACE_SPECULAR_TRANSMISSION_BLUR_TAPS
let num_taps = #{SCREEN_SPACE_SPECULAR_TRANSMISSION_BLUR_TAPS}; // Controlled by the `Camera3d::screen_space_specular_transmission_quality` property
let num_taps = #{SCREEN_SPACE_SPECULAR_TRANSMISSION_BLUR_TAPS}; // Controlled by the `ScreenSpaceTransmission::quality` property
#else
let num_taps = 8; // Fallback to 8 taps, if not specified
#endif
Expand Down
28 changes: 10 additions & 18 deletions examples/3d/transmission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,36 +489,28 @@ fn example_control_system(
}
}

if input.just_pressed(KeyCode::KeyO)
&& transmission.screen_space_specular_transmission_steps > 0
{
transmission.screen_space_specular_transmission_steps -= 1;
if input.just_pressed(KeyCode::KeyO) && transmission.steps > 0 {
transmission.steps -= 1;
}

if input.just_pressed(KeyCode::KeyP)
&& transmission.screen_space_specular_transmission_steps < 4
{
transmission.screen_space_specular_transmission_steps += 1;
if input.just_pressed(KeyCode::KeyP) && transmission.steps < 4 {
transmission.steps += 1;
}

if input.just_pressed(KeyCode::KeyJ) {
transmission.screen_space_specular_transmission_quality =
ScreenSpaceTransmissionQuality::Low;
transmission.quality = ScreenSpaceTransmissionQuality::Low;
}

if input.just_pressed(KeyCode::KeyK) {
transmission.screen_space_specular_transmission_quality =
ScreenSpaceTransmissionQuality::Medium;
transmission.quality = ScreenSpaceTransmissionQuality::Medium;
}

if input.just_pressed(KeyCode::KeyL) {
transmission.screen_space_specular_transmission_quality =
ScreenSpaceTransmissionQuality::High;
transmission.quality = ScreenSpaceTransmissionQuality::High;
}

if input.just_pressed(KeyCode::Semicolon) {
transmission.screen_space_specular_transmission_quality =
ScreenSpaceTransmissionQuality::Ultra;
transmission.quality = ScreenSpaceTransmissionQuality::Ultra;
}

let rotation = if input.pressed(KeyCode::ArrowRight) {
Expand Down Expand Up @@ -565,8 +557,8 @@ fn example_control_system(
" D Depth Prepass: {}\n",
" T TAA: {}\n",
),
transmission.screen_space_specular_transmission_quality,
transmission.screen_space_specular_transmission_steps,
transmission.quality,
transmission.steps,
state.diffuse_transmission,
state.specular_transmission,
state.thickness,
Expand Down
4 changes: 2 additions & 2 deletions examples/large_scenes/bistro/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>, args: Res<A
Msaa::Off,
Camera3d::default(),
ScreenSpaceTransmission {
screen_space_specular_transmission_steps: 0,
screen_space_specular_transmission_quality: ScreenSpaceTransmissionQuality::Low,
steps: 0,
quality: ScreenSpaceTransmissionQuality::Low,
},
Hdr,
Transform::from_xyz(-10.5, 1.7, -1.0).looking_at(Vec3::new(0.0, 3.5, 0.0), Vec3::Y),
Expand Down
6 changes: 4 additions & 2 deletions release-content/migration-guides/transmission.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: "Transmission has been moved to `bevy_pbr`"
pull_requests: [22687, 22706]
pull_requests: [22687, 22706, 22763]
---

`Camera3d::screen_space_specular_transmission_steps` and `Camera3d::screen_space_specular_transmission_quality` have been pulled out into a separate component, `ScreenSpaceTransmission`, and put in `bevy_pbr`.
`Camera3d::screen_space_specular_transmission_steps` and `Camera3d::screen_space_specular_transmission_quality` have been pulled out into a separate component, `ScreenSpaceTransmission`, and put in `bevy_pbr`. The field names have been shortened to `steps` and `quality`.

`ScreenSpaceTransmissionQuality` has been moved from `bevy_camera` to `bevy_pbr`.

Expand All @@ -12,3 +12,5 @@ pull_requests: [22687, 22706]
`ViewTransmissionTexture` and `Transmissive3d` has been moved from `bevy_core_pipelines` to `bevy_pbr`.

`Node3d::MainTransmissivePass` is now initialized by `PbrPlugin`.

`screen_space_specular_transmission_pipeline_key` has become `ScreenSpaceTransmissionQuality::pipeline_key`.