mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 14:08:32 +00:00
Remove dependency on the mesh struct in the pbr function (#7597)
# Objective Currently, it is quite awkward to use the `pbr` function in a custom shader without binding a mesh bind group. This is because the `pbr` function depends on the `MESH_FLAGS_SHADOW_RECEIVER_BIT` flag. ## Solution I have removed this dependency by adding the flag as a parameter to the `PbrInput` struct. I am not sure if this is the ideal solution since the mesh flag indicates both `MESH_FLAGS_SIGN_DETERMINANT_MODEL_3X3_BIT` and `MESH_FLAGS_SHADOW_RECEIVER_BIT`. The former seems to be unrelated to PBR. Maybe the flag should be split.
This commit is contained in:
parent
03575aef22
commit
5ea5ec7518
2 changed files with 8 additions and 3 deletions
|
@ -92,6 +92,8 @@ fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
|
|||
pbr_input.V = calculate_view(in.world_position, pbr_input.is_orthographic);
|
||||
pbr_input.occlusion = occlusion;
|
||||
|
||||
pbr_input.flags = mesh.flags;
|
||||
|
||||
output_color = pbr(pbr_input);
|
||||
} else {
|
||||
output_color = alpha_discard(material, output_color);
|
||||
|
|
|
@ -134,6 +134,7 @@ struct PbrInput {
|
|||
// view world position
|
||||
V: vec3<f32>,
|
||||
is_orthographic: bool,
|
||||
flags: u32,
|
||||
};
|
||||
|
||||
// Creates a PbrInput with default values
|
||||
|
@ -152,6 +153,8 @@ fn pbr_input_new() -> PbrInput {
|
|||
pbr_input.N = vec3<f32>(0.0, 0.0, 1.0);
|
||||
pbr_input.V = vec3<f32>(1.0, 0.0, 0.0);
|
||||
|
||||
pbr_input.flags = 0u;
|
||||
|
||||
return pbr_input;
|
||||
}
|
||||
|
||||
|
@ -203,7 +206,7 @@ fn pbr(
|
|||
for (var i: u32 = offset_and_counts[0]; i < offset_and_counts[0] + offset_and_counts[1]; i = i + 1u) {
|
||||
let light_id = get_light_id(i);
|
||||
var shadow: f32 = 1.0;
|
||||
if ((mesh.flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u
|
||||
if ((in.flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u
|
||||
&& (point_lights.data[light_id].flags & POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
|
||||
shadow = fetch_point_shadow(light_id, in.world_position, in.world_normal);
|
||||
}
|
||||
|
@ -215,7 +218,7 @@ fn pbr(
|
|||
for (var i: u32 = offset_and_counts[0] + offset_and_counts[1]; i < offset_and_counts[0] + offset_and_counts[1] + offset_and_counts[2]; i = i + 1u) {
|
||||
let light_id = get_light_id(i);
|
||||
var shadow: f32 = 1.0;
|
||||
if ((mesh.flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u
|
||||
if ((in.flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u
|
||||
&& (point_lights.data[light_id].flags & POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
|
||||
shadow = fetch_spot_shadow(light_id, in.world_position, in.world_normal);
|
||||
}
|
||||
|
@ -227,7 +230,7 @@ fn pbr(
|
|||
let n_directional_lights = lights.n_directional_lights;
|
||||
for (var i: u32 = 0u; i < n_directional_lights; i = i + 1u) {
|
||||
var shadow: f32 = 1.0;
|
||||
if ((mesh.flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u
|
||||
if ((in.flags & MESH_FLAGS_SHADOW_RECEIVER_BIT) != 0u
|
||||
&& (lights.directional_lights[i].flags & DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) {
|
||||
shadow = fetch_directional_shadow(i, in.world_position, in.world_normal, view_z);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue