summaryrefslogtreecommitdiffstats
path: root/poi.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-03-14 18:36:01 -0700
committeryum <yum.food.vr@gmail.com>2025-03-14 18:36:03 -0700
commitdf77089d90024f229e4dd27a25a9b97645b614d1 (patch)
treea813b1174ec18a75721b581e5335e618e6d64186 /poi.cginc
parent55bbace0f35ca86b4c8f36bbf2ce7d2f1e50bfac (diff)
Simplify spherical harmonics
Implement standard SH9 as a learning exercise. Drop poi's fancy SH9 code. Realize that we just want diffuse and lock everything else away behind a ui-inaccessible #define.
Diffstat (limited to 'poi.cginc')
-rw-r--r--poi.cginc61
1 files changed, 0 insertions, 61 deletions
diff --git a/poi.cginc b/poi.cginc
index df89bbf..cc12b1a 100644
--- a/poi.cginc
+++ b/poi.cginc
@@ -57,72 +57,11 @@ float3 HSVtoRGB(in float3 HSV)
return ((RGB - 1) * HSV.y + 1) * HSV.z;
}
-float shEvaluateDiffuseL1Geomerics_local(float L0, float3 L1, float3 n)
-{
- // average energy
- float R0 = max(0, L0);
-
- // avg direction of incoming light
- float3 R1 = 0.5f * L1;
-
- // directional brightness
- float lenR1 = length(R1);
-
- // linear angle between normal and direction 0-1
- //float q = 0.5f * (1.0f + dot(R1 / lenR1, n));
- //float q = dot(R1 / lenR1, n) * 0.5 + 0.5;
- float q = dot(normalize(R1), n) * 0.5 + 0.5;
- q = saturate(q); // Thanks to ScruffyRuffles for the bug identity.
-
- // power for q
- // lerps from 1 (linear) to 3 (cubic) based on directionality
- float p = 1.0f + 2.0f * lenR1 / R0;
-
- // dynamic range constant
- // should vary between 4 (highly directional) and 0 (ambient)
- float a = (1.0f - lenR1 / R0) / (1.0f + lenR1 / R0);
-
- return R0 * (a + (1.0f - a) * (p + 1.0f) * pow(q, p));
-}
-
-half3 BetterSH9(half4 normal)
-{
- float3 indirect;
- float3 L0 = float3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w) + float3(unity_SHBr.z, unity_SHBg.z, unity_SHBb.z) / 3.0;
- indirect.r = shEvaluateDiffuseL1Geomerics_local(L0.r, unity_SHAr.xyz, normal.xyz);
- indirect.g = shEvaluateDiffuseL1Geomerics_local(L0.g, unity_SHAg.xyz, normal.xyz);
- indirect.b = shEvaluateDiffuseL1Geomerics_local(L0.b, unity_SHAb.xyz, normal.xyz);
- indirect = max(0, indirect);
- indirect += SHEvalLinearL2(normal);
- return indirect;
-}
-
float calculateluminance(float3 color)
{
return color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
}
-float3 getPoiLightingDirect(float3 normal) {
- float3 magic = max(BetterSH9(normalize(unity_SHAr + unity_SHAg + unity_SHAb)), 0);
- float3 normalLight = _LightColor0.rgb + BetterSH9(float4(0, 0, 0, 1));
-
- float magiLumi = calculateluminance(magic);
- float normaLumi = calculateluminance(normalLight);
- float maginormalumi = magiLumi + normaLumi;
-
- float magiratio = magiLumi / maginormalumi;
- float normaRatio = normaLumi / maginormalumi;
-
- float target = calculateluminance(magic * magiratio + normalLight * normaRatio);
- float3 properLightColor = magic + normalLight;
- float properLuminance = calculateluminance(magic + normalLight);
- return properLightColor * max(0.0001, (target / properLuminance));
-}
-
-float3 getPoiLightingIndirect() {
- return BetterSH9(float4(0, 0, 0, 1));
-}
-
bool SceneHasReflections()
{
float width, height;