Convert SSR to use the new pbr_input_to_lighting_input function
This commit is contained in:
parent
939957825a
commit
dbe6479bb0
@ -10,7 +10,6 @@
|
||||
mesh_view_bindings::{view, depth_prepass_texture, deferred_prepass_texture, ssr_settings},
|
||||
pbr_deferred_functions::pbr_input_from_deferred_gbuffer,
|
||||
pbr_deferred_types,
|
||||
pbr_functions,
|
||||
prepass_utils,
|
||||
raymarch::{
|
||||
depth_ray_march_from_cs,
|
||||
@ -99,19 +98,19 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
// Unpack the PBR input.
|
||||
var specular_occlusion = pbr_input.specular_occlusion;
|
||||
let world_position = pbr_input.world_position.xyz;
|
||||
let N = pbr_input.N;
|
||||
let V = pbr_input.V;
|
||||
|
||||
// Calculate the reflection vector.
|
||||
let R = reflect(-V, N);
|
||||
#ifdef ENVIRONMENT_MAP
|
||||
var lighting_input = lighting::pbr_input_to_lighting_input(pbr_input);
|
||||
let R = lighting_input.layers[LAYER_BASE].R;
|
||||
#else // ENVIRONMENT_MAP
|
||||
let R = reflect(-pbr_input.V, pbr_input.N);
|
||||
#endif // ENVIRONMENT_MAP
|
||||
|
||||
// Do the raymarching.
|
||||
let world_position = pbr_input.world_position.xyz;
|
||||
let ssr_specular = evaluate_ssr(R, world_position);
|
||||
var indirect_light = ssr_specular.rgb;
|
||||
specular_occlusion *= ssr_specular.a;
|
||||
|
||||
let specular_occlusion = pbr_input.specular_occlusion * ssr_specular.a;
|
||||
|
||||
// Sample the environment map if necessary.
|
||||
//
|
||||
@ -120,58 +119,6 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
|
||||
//
|
||||
// TODO: Merge this with the duplicated code in `apply_pbr_lighting`.
|
||||
#ifdef ENVIRONMENT_MAP
|
||||
// Unpack values required for environment mapping.
|
||||
let base_color = pbr_input.material.base_color.rgb;
|
||||
let metallic = pbr_input.material.metallic;
|
||||
let reflectance = pbr_input.material.reflectance;
|
||||
let specular_transmission = pbr_input.material.specular_transmission;
|
||||
let diffuse_transmission = pbr_input.material.diffuse_transmission;
|
||||
let diffuse_occlusion = pbr_input.diffuse_occlusion;
|
||||
|
||||
#ifdef STANDARD_MATERIAL_CLEARCOAT
|
||||
// Do the above calculations again for the clearcoat layer. Remember that
|
||||
// the clearcoat can have its own roughness and its own normal.
|
||||
let clearcoat = pbr_input.material.clearcoat;
|
||||
let clearcoat_perceptual_roughness = pbr_input.material.clearcoat_perceptual_roughness;
|
||||
let clearcoat_roughness = lighting::perceptualRoughnessToRoughness(clearcoat_perceptual_roughness);
|
||||
let clearcoat_N = pbr_input.clearcoat_N;
|
||||
let clearcoat_NdotV = max(dot(clearcoat_N, pbr_input.V), 0.0001);
|
||||
let clearcoat_R = reflect(-pbr_input.V, clearcoat_N);
|
||||
#endif // STANDARD_MATERIAL_CLEARCOAT
|
||||
|
||||
// Calculate various other values needed for environment mapping.
|
||||
let roughness = lighting::perceptualRoughnessToRoughness(perceptual_roughness);
|
||||
let diffuse_color = pbr_functions::calculate_diffuse_color(
|
||||
base_color,
|
||||
metallic,
|
||||
specular_transmission,
|
||||
diffuse_transmission
|
||||
);
|
||||
let NdotV = max(dot(N, V), 0.0001);
|
||||
let F_ab = lighting::F_AB(perceptual_roughness, NdotV);
|
||||
let F0 = pbr_functions::calculate_F0(base_color, metallic, reflectance);
|
||||
|
||||
// Pack all the values into a structure.
|
||||
var lighting_input: lighting::LightingInput;
|
||||
lighting_input.layers[LAYER_BASE].NdotV = NdotV;
|
||||
lighting_input.layers[LAYER_BASE].N = N;
|
||||
lighting_input.layers[LAYER_BASE].R = R;
|
||||
lighting_input.layers[LAYER_BASE].perceptual_roughness = perceptual_roughness;
|
||||
lighting_input.layers[LAYER_BASE].roughness = roughness;
|
||||
lighting_input.P = world_position.xyz;
|
||||
lighting_input.V = V;
|
||||
lighting_input.diffuse_color = diffuse_color;
|
||||
lighting_input.F0_ = F0;
|
||||
lighting_input.F_ab = F_ab;
|
||||
#ifdef STANDARD_MATERIAL_CLEARCOAT
|
||||
lighting_input.layers[LAYER_CLEARCOAT].NdotV = clearcoat_NdotV;
|
||||
lighting_input.layers[LAYER_CLEARCOAT].N = clearcoat_N;
|
||||
lighting_input.layers[LAYER_CLEARCOAT].R = clearcoat_R;
|
||||
lighting_input.layers[LAYER_CLEARCOAT].perceptual_roughness = clearcoat_perceptual_roughness;
|
||||
lighting_input.layers[LAYER_CLEARCOAT].roughness = clearcoat_roughness;
|
||||
lighting_input.clearcoat_strength = clearcoat;
|
||||
#endif // STANDARD_MATERIAL_CLEARCOAT
|
||||
|
||||
// Determine which cluster we're in. We'll need this to find the right
|
||||
// reflection probe.
|
||||
let cluster_index = clustered_forward::fragment_cluster_index(
|
||||
@ -185,9 +132,9 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
|
||||
|
||||
// Accumulate the environment map light.
|
||||
indirect_light += view.exposure *
|
||||
(environment_light.diffuse * diffuse_occlusion +
|
||||
(environment_light.diffuse * pbr_input.diffuse_occlusion +
|
||||
environment_light.specular * specular_occlusion);
|
||||
#endif
|
||||
#endif // ENVIRONMENT_MAP
|
||||
|
||||
// Write the results.
|
||||
return vec4(fragment.rgb + indirect_light, 1.0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user