From 87cb9f51d1e36bad7107b7303d21f048b9068429 Mon Sep 17 00:00:00 2001 From: shadielhajj Date: Thu, 4 Jul 2024 20:05:57 +0100 Subject: [PATCH 1/3] Clean up fresnel.hlsl and bring it in line with fresnel.glsl --- lighting/fresnel.hlsl | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/lighting/fresnel.hlsl b/lighting/fresnel.hlsl index 29e4ed94..731bc653 100644 --- a/lighting/fresnel.hlsl +++ b/lighting/fresnel.hlsl @@ -1,15 +1,10 @@ #include "common/schlick.hlsl" -#include "fakeCube.hlsl" -#include "sphericalHarmonics.hlsl" -#include "../color/tonemap.hlsl" - /* contributors: Patricio Gonzalez Vivo description: Resolve fresnel coeficient use: - - fresnel(const f0, LoH) - - fresnel( _R, _f0, _NoV) + - fresnel(const f0, NoV) license: - Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0 - Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license @@ -18,22 +13,25 @@ license: #ifndef FNC_FRESNEL #define FNC_FRESNEL -float3 fresnel(const float3 f0, float LoH) { +float3 fresnel(const in float3 f0, float3 normal, float3 view) +{ + return schlick(f0, 1.0, dot(view, normal)); +} + +float3 fresnel(const float3 f0, float NoV) +{ #if defined(TARGET_MOBILE) || defined(PLATFORM_RPI) - return schlick(f0, 1.0, LoH); + return schlick(f0, 1.0, NoV); #else float f90 = saturate(dot(f0, float3(50.0, 50.0, 50.0) * 0.33)); - return schlick(f0, f90, LoH); + return schlick(f0, f90, NoV); #endif } -// float fresnelf(float3 V, float3 N, float R0) { -// float cosAngle = 1.0-max(dot(V, N), 0.0); -// float result = cosAngle * cosAngle; -// result = result * result; -// result = result * cosAngle; -// result = clamp(result * (1.0 - R0) + R0, 0.0, 1.0); -// return result; -// } +float fresnel(const in float f0, const in float NoV) +{ + return schlick(f0, 1.0, NoV); +} + #endif \ No newline at end of file From d34470e5fdff1e2c9b265502a251e4791415bced Mon Sep 17 00:00:00 2001 From: shadielhajj Date: Thu, 4 Jul 2024 20:06:36 +0100 Subject: [PATCH 2/3] Added roughness-adjueste fresnel function to fresnel.hlsl. --- lighting/fresnel.hlsl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lighting/fresnel.hlsl b/lighting/fresnel.hlsl index 731bc653..043d17a8 100644 --- a/lighting/fresnel.hlsl +++ b/lighting/fresnel.hlsl @@ -1,10 +1,12 @@ #include "common/schlick.hlsl" +#include "../math/pow5.hlsl" /* contributors: Patricio Gonzalez Vivo description: Resolve fresnel coeficient use: - fresnel(const f0, NoV) + - fresnel(const f0, NoV, float roughness) license: - Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0 - Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license @@ -33,5 +35,12 @@ float fresnel(const in float f0, const in float NoV) return schlick(f0, 1.0, NoV); } +// Roughness-adjusted fresnel function to attenuate high speculars at glancing angles +// Very useful when used with filtered environment maps +// See https://seblagarde.wordpress.com/2011/08/17/hello-world/ +float3 fresnel(float3 f0, float NoV, float roughness) +{ + return f0 + (max(1.0 - roughness, f0) - f0) * pow5(1.0-NoV); +} #endif \ No newline at end of file From f543a307d670674daecf74667ba4869ef0b8de4f Mon Sep 17 00:00:00 2001 From: shadielhajj Date: Thu, 4 Jul 2024 20:09:03 +0100 Subject: [PATCH 3/3] Added roughness-adjusted fresnel to fresnel.glsl. --- lighting/fresnel.glsl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lighting/fresnel.glsl b/lighting/fresnel.glsl index 2ab4858d..f22b434a 100644 --- a/lighting/fresnel.glsl +++ b/lighting/fresnel.glsl @@ -1,5 +1,6 @@ #include "common/schlick.glsl" +#include "../math/pow5.hlsl" #include "../math/const.glsl" #include "../math/saturate.glsl" @@ -8,6 +9,7 @@ contributors: Patricio Gonzalez Vivo description: Resolve fresnel coeficient use: - fresnel(const f0, NoV) + - fresnel(const f0, NoV, float roughness) license: - Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0 - Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license @@ -33,4 +35,12 @@ float fresnel(const in float f0, const in float NoV) { return schlick(f0, 1.0, NoV); } +// Roughness-adjusted fresnel function to attenuate high speculars at glancing angles +// Very useful when used with filtered environment maps +// See https://seblagarde.wordpress.com/2011/08/17/hello-world/ +vec3 fresnel(vec3 f0, float NoV, float roughness) +{ + return f0 + (max(1.0 - roughness, f0) - f0) * pow5(1.0 - NoV); +} + #endif \ No newline at end of file