Skip to content

Commit c2ab3a0

Browse files
authored
Do not load prepass normals for transmissive materials (#11140)
Turns out whenever a normal prepass was active (which includes whenever you use SSAO) we were attempting to read the normals from the prepass for the specular transmissive material. Since transmissive materials don't participate in the prepass (unlike opaque materials) we were reading the normals from “behind” the mesh, producing really weird visual results. # Objective - Fixes #11112. ## Solution - We introduce a new `READS_VIEW_TRANSMISSION_TEXTURE` mesh pipeline key; - We set it whenever the material properties has the `reads_view_transmission_texture` flag set; (i.e. the material is transmissive) - If this key is set we prevent the reading of normals from the prepass, by not setting the `LOAD_PREPASS_NORMALS` shader def. --- ## Changelog ### Fixed - Specular transmissive materials no longer attempt to erroneously load prepass normals, and now work correctly even with the normal prepass active (e.g. when using SSAO)
1 parent 17ef731 commit c2ab3a0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

crates/bevy_pbr/src/material.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ pub fn queue_material_meshes<M: Material>(
606606
if mesh.morph_targets.is_some() {
607607
mesh_key |= MeshPipelineKey::MORPH_TARGETS;
608608
}
609+
610+
if material.properties.reads_view_transmission_texture {
611+
mesh_key |= MeshPipelineKey::READS_VIEW_TRANSMISSION_TEXTURE;
612+
}
613+
609614
mesh_key |= alpha_mode_pipeline_key(material.properties.alpha_mode);
610615

611616
let pipeline_id = pipelines.specialize(

crates/bevy_pbr/src/render/mesh.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ bitflags::bitflags! {
491491
const DEPTH_CLAMP_ORTHO = 1 << 10;
492492
const TEMPORAL_JITTER = 1 << 11;
493493
const MORPH_TARGETS = 1 << 12;
494+
const READS_VIEW_TRANSMISSION_TEXTURE = 1 << 13;
494495
const BLEND_RESERVED_BITS = Self::BLEND_MASK_BITS << Self::BLEND_SHIFT_BITS; // ← Bitmask reserving bits for the blend state
495496
const BLEND_OPAQUE = 0 << Self::BLEND_SHIFT_BITS; // ← Values are just sequential within the mask, and can range from 0 to 3
496497
const BLEND_PREMULTIPLIED_ALPHA = 1 << Self::BLEND_SHIFT_BITS; //
@@ -737,7 +738,7 @@ impl SpecializedMeshPipeline for MeshPipeline {
737738
// the current fragment value in the output and the depth is written to the
738739
// depth buffer
739740
depth_write_enabled = true;
740-
is_opaque = true;
741+
is_opaque = !key.contains(MeshPipelineKey::READS_VIEW_TRANSMISSION_TEXTURE);
741742
}
742743

743744
if key.contains(MeshPipelineKey::NORMAL_PREPASS) {

0 commit comments

Comments
 (0)