summaryrefslogtreecommitdiffstats
path: root/lighting.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-02-24 17:23:35 -0800
committeryum <yum.food.vr@gmail.com>2026-02-24 17:23:35 -0800
commit7e060334a8af4bb47464903a0c09c76be8f0823a (patch)
treee3e16c60bad34decbd727b4feab7ae8624055ed5 /lighting.cginc
parent3e99a65d8ba63265224ea561a45ee4917a490e7a (diff)
Add brightness clamp, update vrc light volumes
Diffstat (limited to 'lighting.cginc')
-rwxr-xr-xlighting.cginc72
1 files changed, 43 insertions, 29 deletions
diff --git a/lighting.cginc b/lighting.cginc
index 8a60e66..500141b 100755
--- a/lighting.cginc
+++ b/lighting.cginc
@@ -12,11 +12,13 @@
#include "interpolators.cginc"
#include "LightVolumes.cginc"
#include "pbr.cginc"
+#include "poi.cginc"
struct LightCommon {
float3 V;
float3 N;
float NoV;
+ float spec_ao;
#if defined(_CLEARCOAT)
float NoV_cc;
#endif
@@ -162,6 +164,7 @@ float3 yumSH9(float4 n, float3 worldPos, inout LightIndirect light) {
float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightIndirect light) {
float4 diffuse = 0;
+
#if defined(FORWARD_BASE_PASS)
#if defined(_BENT_NORMALS)
diffuse.xyz += max(0, yumSH9(float4(pbr.bent_normal, 1.0), i.worldPos, light));
@@ -170,6 +173,12 @@ float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightIndirect light) {
#endif
#endif
+#if defined(_BRIGHTNESS_CLAMP) && defined(FORWARD_BASE_PASS)
+ float3 diffuse_hsv = RGBtoHSV(diffuse.xyz);
+ diffuse_hsv.z = clamp(diffuse_hsv.z, _Brightness_Clamp_Min, _Brightness_Clamp_Max);
+ diffuse.xyz = HSVtoRGB(diffuse_hsv);
+#endif
+
#if defined(_AMBIENT_OCCLUSION)
diffuse.xyz *= pbr.ao;
#endif
@@ -177,6 +186,39 @@ float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightIndirect light) {
return diffuse;
}
+float getSpecularAO(v2f i, Pbr pbr, LightData data, float3 reflect_dir) {
+ float spec_ao = 1;
+#if defined(_AMBIENT_OCCLUSION) || defined(_BENT_NORMALS)
+ float ao_vis = 1.0;
+#if defined(_AMBIENT_OCCLUSION)
+ ao_vis = pbr.ao;
+#endif
+#if defined(_BENT_NORMALS)
+ float3 spec_ao_normal = pbr.bent_normal;
+#else
+ float3 spec_ao_normal = pbr.normal;
+#endif
+ spec_ao = computeSpecularAO(data.common.NoV, ao_vis, pbr.roughness, spec_ao_normal, -data.indirect.dir);
+#if defined(_BENT_NORMALS)
+ spec_ao = saturate(lerp(1.0, spec_ao, _Bent_Normals_Strength));
+#endif
+#endif
+
+ // Didn't see a big difference in testbed, so commented out.
+ // Bent normals get us most of what we want.
+#if 0
+ // Horizon fading
+ // https://marmosetco.tumblr.com/post/81245981087
+ // The goal is to attenuate anything which points into the mesh.
+ // TODO expose fade strength as a parameter.
+ float horizon_fade_str = 1.3;
+ float horizon_fade = saturate(1.0f + horizon_fade_str * dot(pbr.normal, -reflect_dir));
+ horizon_fade *= horizon_fade;
+ spec_ao *= horizon_fade;
+#endif
+ return spec_ao;
+}
+
void GetLighting(v2f i, Pbr pbr, out LightData data) {
data = (LightData) 0;
@@ -226,36 +268,8 @@ void GetLighting(v2f i, Pbr pbr, out LightData data) {
data.indirect.diffuse = getIndirectDiffuse(i, pbr, data.indirect);
data.indirect.specular = getIndirectSpecular(i, pbr.roughness_perceptual, view_dir, -data.indirect.dir);
-#if defined(_AMBIENT_OCCLUSION) || defined(_BENT_NORMALS)
- float ao_vis = 1.0;
-#if defined(_AMBIENT_OCCLUSION)
- ao_vis = pbr.ao;
-#endif
-#if defined(_BENT_NORMALS)
- float3 spec_ao_normal = pbr.bent_normal;
-#else
- float3 spec_ao_normal = pbr.normal;
-#endif
- //float NoV_geom = saturate(dot(i.normal, data.common.V));
- float spec_ao = computeSpecularAO(data.common.NoV, ao_vis, pbr.roughness, spec_ao_normal, -data.indirect.dir);
-#if defined(_BENT_NORMALS)
- spec_ao = saturate(lerp(1.0, spec_ao, _Bent_Normals_Strength));
-#endif
- data.indirect.specular *= spec_ao;
-#endif
- // Didn't see a big difference in testbed, so commented out.
- // Bent normals get us most of what we want.
-#if 0
- // Horizon fading
- // https://marmosetco.tumblr.com/post/81245981087
- // The goal is to attenuate anything which points into the mesh.
- // TODO expose fade strength as a parameter.
- float horizon_fade_str = 1.3;
- float horizon_fade = saturate(1.0f + horizon_fade_str * dot(pbr.normal, -reflect_dir));
- horizon_fade *= horizon_fade;
- data.indirect.specular *= horizon_fade;
-#endif
+ data.common.spec_ao = getSpecularAO(i, pbr, data, reflect_dir);
#if defined(_CLEARCOAT)
data.indirect.specular_cc = getIndirectSpecular(i, saturate(sqrt(pbr.cc_roughness)), view_dir, dir_cc);