summaryrefslogtreecommitdiffstats
path: root/yum_brdf.cginc
diff options
context:
space:
mode:
Diffstat (limited to 'yum_brdf.cginc')
-rw-r--r--yum_brdf.cginc42
1 files changed, 18 insertions, 24 deletions
diff --git a/yum_brdf.cginc b/yum_brdf.cginc
index c7424d0..7a4639f 100644
--- a/yum_brdf.cginc
+++ b/yum_brdf.cginc
@@ -7,6 +7,7 @@
#include "filamented.cginc"
#include "math.cginc"
+#include "pema99.cginc"
#include "yum_pbr.cginc"
#include "yum_lighting.cginc"
@@ -76,10 +77,6 @@ float computeDielectricF0(float reflectance) {
return 0.16 * reflectance * reflectance;
}
-float3 computeDiffuseColor(float3 baseColor, float metallic) {
- return baseColor * (1.0 - metallic);
-}
-
float computeSpecularAO(float NoV, float visibility, float roughness) {
// Lagarde and de Rousiers 2014, "Moving Frostbite to PBR"
return saturate(pow(NoV + visibility, exp2(-16.0 * roughness - 1.0)) - 1.0 + visibility);
@@ -144,6 +141,17 @@ float4 YumBRDF(v2f i, f2f f, const YumLighting light, YumPbr pbr) {
}
#endif
+ const float dielectric_f0 = computeDielectricF0(_reflectance);
+ const float3 f0 = lerp(dielectric_f0, pbr.albedo, pbr.metallic);
+ float2 dfg_uv = float2(NoV, pbr.roughness_perceptual);
+ float3 dfg;
+ [branch]
+ if (textureExists(_DFG_LUT)) {
+ dfg = _DFG_LUT.SampleLevel(bilinear_clamp_s, dfg_uv, 0).rgb;
+ } else {
+ dfg = float3(1, 1, 1);
+ }
+
float3 direct_standard;
{
float remainder = 1.0f;
@@ -163,18 +171,10 @@ float4 YumBRDF(v2f i, f2f f, const YumLighting light, YumPbr pbr) {
remainder -= Fcc;
remainder = max(0, remainder);
#endif
-
- const float dielectric_f0 = computeDielectricF0(_reflectance);
- const float3 f0 = lerp(dielectric_f0, pbr.albedo, pbr.metallic);
- const float3 dfg = PrefilteredDFG_LUT(pbr.roughness_perceptual, NoV);
const float3 E = specularDFG(dfg, f0);
const float3 energy_compensation = energyCompensation(dfg, f0);
- // Compute proper diffuse color with metallic blending
- float3 diffuseColor = computeDiffuseColor(pbr.albedo, pbr.metallic);
-
- // Fd_Burley already includes 1/PI, so multiply by PI to match Unity intensities
- float3 Fd = diffuseColor * Fd_Burley(pbr.roughness, NoV, NoL_wrapped_d, LoH) * PI;
+ float3 Fd = pbr.albedo.xyz * (1.0f - pbr.metallic) * Fd_Burley(pbr.roughness, NoV, NoL_wrapped_d, LoH) * PI;
Fd *= light.attenuation * pbr.ao * remainder;
// Multiply by PI to match Unity intensities (same as Filament's implementation)
@@ -187,6 +187,7 @@ float4 YumBRDF(v2f i, f2f f, const YumLighting light, YumPbr pbr) {
#endif
direct_standard = color * light.direct;
}
+ direct_standard = 0;
#if defined(_MATERIAL_TYPE_CLOTH)
float3 indirect_cloth;
@@ -256,8 +257,6 @@ float4 YumBRDF(v2f i, f2f f, const YumLighting light, YumPbr pbr) {
#if defined(_BRIGHTNESS_CONTROL)
cc_env_refl *= _Brightness_Multiplier;
#endif
-
- // Clearcoat Fresnel for view angle
float Fcc = F_Schlick(cc_f0, NoV_cc).x * cc_mask * _Clearcoat_Strength;
float3 indirect_specular_cc = Fcc * cc_env_refl;
@@ -266,19 +265,14 @@ float4 YumBRDF(v2f i, f2f f, const YumLighting light, YumPbr pbr) {
remainder = saturate(remainder - Fcc);
#endif
- const float dielectric_f0 = computeDielectricF0(_reflectance);
- const float3 f0 = lerp(dielectric_f0, pbr.albedo, pbr.metallic);
- const float3 dfg = PrefilteredDFG_LUT(pbr.roughness_perceptual, NoV);
- const float3 E = specularDFG(dfg, f0);
-
+ const float3 f0_spec = lerp(dielectric_f0, pbr.albedo.xyz, pbr.metallic);
+ const float3 ibl_specular_reflectance = lerp(dfg.xxx, dfg.yyy, f0_spec);
float diffuseAO = pbr.ao;
- float3 diffuseColor = computeDiffuseColor(pbr.albedo, pbr.metallic);
- float3 Fr = E * light.specular * remainder;
+ float3 Fr = ibl_specular_reflectance * light.specular * remainder;
remainder = saturate(remainder - Fr);
- float3 Fd = diffuseColor * light.diffuse * pbr.ao * remainder;
-
+ float3 Fd = pbr.albedo.xyz * (1.0f - pbr.metallic) * light.diffuse * pbr.ao * remainder;
indirect_standard += Fr + Fd;
}