Fix specular envmap in deferred (#11534)

# Objective

- Fixes #11414

## Solution

- Add specular occlusion to g-buffer so PbrInput can be properly
reconstructed for shading with a non-zero value allowing the spec envmap
to be seen


![image](https://github.com/bevyengine/bevy/assets/11307157/84aa8312-7c06-4dc7-92da-5d94b54b133d)

---------

Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
This commit is contained in:
vero 2024-01-29 08:39:49 -08:00 committed by GitHub
parent 70f7d9598a
commit 45967b03b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View file

@ -1,7 +1,7 @@
#define_import_path bevy_pbr::pbr_deferred_functions #define_import_path bevy_pbr::pbr_deferred_functions
#import bevy_pbr::{ #import bevy_pbr::{
pbr_types::{PbrInput, standard_material_new, STANDARD_MATERIAL_FLAGS_UNLIT_BIT}, pbr_types::{PbrInput, pbr_input_new, STANDARD_MATERIAL_FLAGS_UNLIT_BIT},
pbr_deferred_types as deferred_types, pbr_deferred_types as deferred_types,
pbr_functions, pbr_functions,
rgb9e5, rgb9e5,
@ -58,8 +58,7 @@ fn deferred_gbuffer_from_pbr_input(in: PbrInput) -> vec4<u32> {
// Creates a PbrInput from the deferred gbuffer. // Creates a PbrInput from the deferred gbuffer.
fn pbr_input_from_deferred_gbuffer(frag_coord: vec4<f32>, gbuffer: vec4<u32>) -> PbrInput { fn pbr_input_from_deferred_gbuffer(frag_coord: vec4<f32>, gbuffer: vec4<u32>) -> PbrInput {
var pbr: PbrInput; var pbr = pbr_input_new();
pbr.material = standard_material_new();
let flags = deferred_types::unpack_flags(gbuffer.a); let flags = deferred_types::unpack_flags(gbuffer.a);
let deferred_flags = deferred_types::mesh_material_flags_from_deferred_flags(flags); let deferred_flags = deferred_types::mesh_material_flags_from_deferred_flags(flags);

View file

@ -24,7 +24,7 @@ struct StandardMaterial {
}; };
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: if these flags are updated or changed. Be sure to also update // NOTE: if these flags are updated or changed. Be sure to also update
// deferred_flags_from_mesh_material_flags and mesh_material_flags_from_deferred_flags // deferred_flags_from_mesh_material_flags and mesh_material_flags_from_deferred_flags
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
const STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT: u32 = 1u; const STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT: u32 = 1u;
@ -74,13 +74,15 @@ fn standard_material_new() -> StandardMaterial {
material.max_parallax_layer_count = 16.0; material.max_parallax_layer_count = 16.0;
material.max_relief_mapping_search_steps = 5u; material.max_relief_mapping_search_steps = 5u;
material.deferred_lighting_pass_id = 1u; material.deferred_lighting_pass_id = 1u;
return material; return material;
} }
struct PbrInput { struct PbrInput {
material: StandardMaterial, material: StandardMaterial,
// Note: this gets monochromized upon deferred PbrInput reconstruction.
diffuse_occlusion: vec3<f32>, diffuse_occlusion: vec3<f32>,
// Note: this is 1.0 (entirely unoccluded) when SSAO is off.
specular_occlusion: f32, specular_occlusion: f32,
frag_coord: vec4<f32>, frag_coord: vec4<f32>,
world_position: vec4<f32>, world_position: vec4<f32>,
@ -103,6 +105,7 @@ fn pbr_input_new() -> PbrInput {
pbr_input.material = standard_material_new(); pbr_input.material = standard_material_new();
pbr_input.diffuse_occlusion = vec3<f32>(1.0); pbr_input.diffuse_occlusion = vec3<f32>(1.0);
// If SSAO is enabled, then this gets overwritten with proper specular occlusion. If its not, then we get specular environment map unoccluded (we have no data with which to occlude it with).
pbr_input.specular_occlusion = 1.0; pbr_input.specular_occlusion = 1.0;
pbr_input.frag_coord = vec4<f32>(0.0, 0.0, 0.0, 1.0); pbr_input.frag_coord = vec4<f32>(0.0, 0.0, 0.0, 1.0);