Skip to content

Commit

Permalink
Revert "Make FOG_ENABLED a shader_def instead of material flag (bevye…
Browse files Browse the repository at this point in the history
…ngine#13783)" (bevyengine#13803)

This reverts commit 3ced49f.

Relevant to bevyengine#13802. This wasn't
done quite right and partially broke fog.

Co-authored-by: Alice Cecile <[email protected]>
  • Loading branch information
alice-i-cecile and Alice Cecile authored Jun 10, 2024
1 parent 2ccdae7 commit d659a1f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
7 changes: 5 additions & 2 deletions crates/bevy_pbr/src/deferred/pbr_deferred_types.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

#import bevy_pbr::{
mesh_types::MESH_FLAGS_SHADOW_RECEIVER_BIT,
pbr_types::{STANDARD_MATERIAL_FLAGS_UNLIT_BIT},
pbr_types::{STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT, STANDARD_MATERIAL_FLAGS_UNLIT_BIT},
}

// Maximum of 8 bits available
const DEFERRED_FLAGS_UNLIT_BIT: u32 = 1u;
const DEFERRED_MESH_FLAGS_SHADOW_RECEIVER_BIT: u32 = 2u;
const DEFERRED_FLAGS_FOG_ENABLED_BIT: u32 = 2u;
const DEFERRED_MESH_FLAGS_SHADOW_RECEIVER_BIT: u32 = 4u;

fn deferred_flags_from_mesh_material_flags(mesh_flags: u32, mat_flags: u32) -> u32 {
var flags = 0u;
flags |= u32((mesh_flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u) * DEFERRED_MESH_FLAGS_SHADOW_RECEIVER_BIT;
flags |= u32((mat_flags & STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT) != 0u) * DEFERRED_FLAGS_FOG_ENABLED_BIT;
flags |= u32((mat_flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) != 0u) * DEFERRED_FLAGS_UNLIT_BIT;
return flags;
}
Expand All @@ -20,6 +22,7 @@ fn mesh_material_flags_from_deferred_flags(deferred_flags: u32) -> vec2<u32> {
var mat_flags = 0u;
var mesh_flags = 0u;
mesh_flags |= u32((deferred_flags & DEFERRED_MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u) * MESH_FLAGS_SHADOW_RECEIVER_BIT;
mat_flags |= u32((deferred_flags & DEFERRED_FLAGS_FOG_ENABLED_BIT) != 0u) * STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT;
mat_flags |= u32((deferred_flags & DEFERRED_FLAGS_UNLIT_BIT) != 0u) * STANDARD_MATERIAL_FLAGS_UNLIT_BIT;
return vec2(mesh_flags, mat_flags);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_pbr/src/pbr_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ bitflags::bitflags! {
const UNLIT = 1 << 5;
const TWO_COMPONENT_NORMAL_MAP = 1 << 6;
const FLIP_NORMAL_MAP_Y = 1 << 7;
// const UNUSED = 1 << 8; // USE THIS IF YOU ADD A NEW FLAG
const FOG_ENABLED = 1 << 8;
const DEPTH_MAP = 1 << 9; // Used for parallax mapping
const SPECULAR_TRANSMISSION_TEXTURE = 1 << 10;
const THICKNESS_TEXTURE = 1 << 11;
Expand Down Expand Up @@ -980,6 +980,9 @@ impl AsBindGroupShaderType<StandardMaterialUniform> for StandardMaterial {
if self.unlit {
flags |= StandardMaterialFlags::UNLIT;
}
if self.fog_enabled {
flags |= StandardMaterialFlags::FOG_ENABLED;
}
if self.depth_map.is_some() {
flags |= StandardMaterialFlags::DEPTH_MAP;
}
Expand Down Expand Up @@ -1117,7 +1120,6 @@ bitflags! {
const CLEARCOAT_UV = 0x040000;
const CLEARCOAT_ROUGHNESS_UV = 0x080000;
const CLEARCOAT_NORMAL_UV = 0x100000;
const FOG_ENABLED = 0x200000;
const DEPTH_BIAS = 0xffffffff_00000000;
}
}
Expand Down Expand Up @@ -1225,7 +1227,6 @@ impl From<&StandardMaterial> for StandardMaterialKey {
material.clearcoat_normal_channel != UvChannel::Uv0,
);
}
key.set(StandardMaterialKey::FOG_ENABLED, material.fog_enabled);

key.insert(StandardMaterialKey::from_bits_retain(
(material.depth_bias as u64) << STANDARD_MATERIAL_KEY_DEPTH_BIAS_SHIFT,
Expand Down Expand Up @@ -1382,7 +1383,6 @@ impl Material for StandardMaterial {
StandardMaterialKey::ANISOTROPY_UV,
"STANDARD_MATERIAL_ANISOTROPY_UV",
),
(StandardMaterialKey::FOG_ENABLED, "FOG_ENABLED"),
] {
if key.bind_group_data.intersects(flags) {
shader_defs.push(shader_def.into());
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_pbr/src/render/pbr_functions.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,9 @@ fn main_pass_post_lighting_processing(
var output_color = input_color;

// fog
#ifdef FOG_ENABLED
if (view_bindings::fog.mode != mesh_view_types::FOG_MODE_OFF) {
if (view_bindings::fog.mode != mesh_view_types::FOG_MODE_OFF && (pbr_input.material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT) != 0u) {
output_color = apply_fog(view_bindings::fog, output_color, pbr_input.world_position.xyz, view_bindings::view.world_position.xyz);
}
#endif // FOG_ENABLED

#ifdef TONEMAP_IN_SHADER
output_color = tone_mapping(output_color, view_bindings::view.color_grading);
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/render/pbr_types.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT: u32 = 16u;
const STANDARD_MATERIAL_FLAGS_UNLIT_BIT: u32 = 32u;
const STANDARD_MATERIAL_FLAGS_TWO_COMPONENT_NORMAL_MAP: u32 = 64u;
const STANDARD_MATERIAL_FLAGS_FLIP_NORMAL_MAP_Y: u32 = 128u;
// const STANDARD_MATERIAL_FLAGS_UNUSED_BIT: u32 = 256u;
const STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT: u32 = 256u;
const STANDARD_MATERIAL_FLAGS_DEPTH_MAP_BIT: u32 = 512u;
const STANDARD_MATERIAL_FLAGS_SPECULAR_TRANSMISSION_TEXTURE_BIT: u32 = 1024u;
const STANDARD_MATERIAL_FLAGS_THICKNESS_TEXTURE_BIT: u32 = 2048u;
Expand Down

0 comments on commit d659a1f

Please sign in to comment.