Revert "Make FOG_ENABLED a shader_def instead of material flag (#13783)" (#13803)

This reverts commit 3ced49f672.

Relevant to https://github.com/bevyengine/bevy/issues/13802. This wasn't
done quite right and partially broke fog.

Co-authored-by: Alice Cecile <alice.i.cecil@gmail.com>
This commit is contained in:
Alice Cecile 2024-06-10 19:25:16 -04:00 committed by GitHub
parent 2ccdae7489
commit d659a1f7d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 10 deletions

View file

@ -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;
}
@ -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);
}

View file

@ -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;
@ -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;
}
@ -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;
}
}
@ -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,
@ -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());

View file

@ -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);

View file

@ -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;