summaryrefslogtreecommitdiffstats
path: root/filamented.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-08-06 22:12:15 -0700
committeryum <yum.food.vr@gmail.com>2025-08-06 22:28:53 -0700
commitf13c88295826d439c70cb9dfb4a9dd5d6ae46ff0 (patch)
treeb965fdbb9fa5f866963b36abf59e96847d737dc6 /filamented.cginc
parent4c41d7cd0f4db1c262371fbe6b4db13639d9fc7b (diff)
Switch to independent implementations of D/G terms
Diffstat (limited to 'filamented.cginc')
-rw-r--r--filamented.cginc33
1 files changed, 1 insertions, 32 deletions
diff --git a/filamented.cginc b/filamented.cginc
index 0e27bbc..fb019cb 100644
--- a/filamented.cginc
+++ b/filamented.cginc
@@ -213,37 +213,6 @@
#include "UnityCG.cginc"
#include "UnityImageBasedLightingMinimal.cginc"
-#define MIN_PERCEPTUAL_ROUGHNESS 0.045f
-#define MIN_ROUGHNESS 0.002025f
-
-float D_GGX(float roughness, float NoH, const float3 h) {
- // Walter et al. 2007, "Microfacet Models for Refraction through Rough Surfaces"
-
- // In mediump, there are two problems computing 1.0 - NoH^2
- // 1) 1.0 - NoH^2 suffers floating point cancellation when NoH^2 is close to 1 (highlights)
- // 2) NoH doesn't have enough precision around 1.0
- // Both problem can be fixed by computing 1-NoH^2 in highp and providing NoH in highp as well
-
- // However, we can do better using Lagrange's identity:
- // ||a x b||^2 = ||a||^2 ||b||^2 - (a . b)^2
- // since N and H are unit vectors: ||N x H||^2 = 1.0 - NoH^2
- // This computes 1.0 - NoH^2 directly (which is close to zero in the highlights and has
- // enough precision).
- // Overall this yields better performance, keeping all computations in mediump
- // Not available without reworking to pass NxH to the function
- float oneMinusNoHSquared = 1.0 - NoH * NoH;
- float a = NoH * roughness;
- float k = roughness / (oneMinusNoHSquared + a * a);
- float d = k * k * (1.0 / PI);
- return d;
-}
-
-float V_SmithGGXCorrelated_Fast(float roughness, float NoV, float NoL) {
- // Hammon 2017, "PBR Diffuse Lighting for GGX+Smith Microsurfaces"
- float v = 0.5 / lerp(2.0 * NoL * NoV, NoL + NoV, roughness);
- return v;
-}
-
float normalFiltering(float perceptualRoughness, const float3 worldNormal) {
// Kaplanyan 2016, "Stable specular highlights"
// Tokuyoshi 2017, "Error Reduction and Simplification for Shading Anti-Aliasing"
@@ -275,7 +244,7 @@ half3 Unity_GlossyEnvironment_local (UNITY_ARGS_TEXCUBE(tex), half4 hdr, Unity_G
// Workaround for issue where objects are blurrier than they should be
// due to specular AA.
float roughnessAdjustment = 1-perceptualRoughness;
- roughnessAdjustment = MIN_PERCEPTUAL_ROUGHNESS * roughnessAdjustment * roughnessAdjustment;
+ roughnessAdjustment = 1e-6f * roughnessAdjustment * roughnessAdjustment;
perceptualRoughness = perceptualRoughness - roughnessAdjustment;
// Unity derivation