Convert apply_pbr_lighting to use the new pbr_input_to_lighting_input function

This commit is contained in:
William Rose 2025-03-22 11:48:06 +00:00
parent dbe6479bb0
commit 1111a6aa5a

View File

@ -288,10 +288,8 @@ fn apply_pbr_lighting(
// calculate non-linear roughness from linear perceptualRoughness
let metallic = in.material.metallic;
let perceptual_roughness = in.material.perceptual_roughness;
let roughness = lighting::perceptualRoughnessToRoughness(perceptual_roughness);
let ior = in.material.ior;
let thickness = in.material.thickness;
let reflectance = in.material.reflectance;
let diffuse_transmission = in.material.diffuse_transmission;
let specular_transmission = in.material.specular_transmission;
@ -300,67 +298,25 @@ fn apply_pbr_lighting(
let diffuse_occlusion = in.diffuse_occlusion;
let specular_occlusion = in.specular_occlusion;
// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
let NdotV = max(dot(in.N, in.V), 0.0001);
let R = reflect(-in.V, in.N);
#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 = in.material.clearcoat;
let clearcoat_perceptual_roughness = in.material.clearcoat_perceptual_roughness;
let clearcoat_roughness = lighting::perceptualRoughnessToRoughness(clearcoat_perceptual_roughness);
let clearcoat_N = in.clearcoat_N;
let clearcoat_NdotV = max(dot(clearcoat_N, in.V), 0.0001);
let clearcoat_R = reflect(-in.V, clearcoat_N);
#endif // STANDARD_MATERIAL_CLEARCOAT
let diffuse_color = calculate_diffuse_color(
output_color.rgb,
metallic,
specular_transmission,
diffuse_transmission
);
// Diffuse transmissive strength is inversely related to metallicity and specular transmission, but directly related to diffuse transmission
let diffuse_transmissive_color = output_color.rgb * (1.0 - metallic) * (1.0 - specular_transmission) * diffuse_transmission;
// Calculate the world position of the second Lambertian lobe used for diffuse transmission, by subtracting material thickness
let diffuse_transmissive_lobe_world_position = in.world_position - vec4<f32>(in.world_normal, 0.0) * thickness;
let F0 = calculate_F0(output_color.rgb, metallic, reflectance);
let F_ab = lighting::F_AB(perceptual_roughness, NdotV);
var direct_light: vec3<f32> = vec3<f32>(0.0);
// Transmitted Light (Specular and Diffuse)
var transmitted_light: vec3<f32> = vec3<f32>(0.0);
// 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 = in.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 = in.world_position.xyz;
lighting_input.V = in.V;
lighting_input.diffuse_color = diffuse_color;
lighting_input.F0_ = F0;
lighting_input.F_ab = F_ab;
var lighting_input = lighting::pbr_input_to_lighting_input(in);
let diffuse_color = lighting_input.diffuse_color;
let F0 = lighting_input.F0_;
let NdotV = lighting_input.layers[LAYER_BASE].NdotV;
#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
#ifdef STANDARD_MATERIAL_ANISOTROPY
lighting_input.anisotropy = in.anisotropy_strength;
lighting_input.Ta = in.anisotropy_T;
lighting_input.Ba = in.anisotropy_B;
#endif // STANDARD_MATERIAL_ANISOTROPY
let clearcoat_NdotV = lighting_input.layers[LAYER_CLEARCOAT].NdotV;
#endif // STANDARD_MATERIAL_CLEARCOAT
// And do the same for transmissive if we need to.
#ifdef STANDARD_MATERIAL_DIFFUSE_TRANSMISSION