summaryrefslogtreecommitdiffstats
path: root/matcaps.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-02-20 00:07:46 -0800
committeryum <yum.food.vr@gmail.com>2025-02-20 00:07:46 -0800
commit65ed0c23335b10a266d76257eeb3e7ecfd23cfb5 (patch)
tree998424873ee3389894ee085ea6464b59a71474fb /matcaps.cginc
parentcba7e1ab0bfa89b228955e18b47cf7aca2a84c9f (diff)
Add directionality and quantization to rim lighting
Diffstat (limited to 'matcaps.cginc')
-rw-r--r--matcaps.cginc21
1 files changed, 21 insertions, 0 deletions
diff --git a/matcaps.cginc b/matcaps.cginc
index 555dcc7..78f2cce 100644
--- a/matcaps.cginc
+++ b/matcaps.cginc
@@ -43,6 +43,13 @@ void applyMatcap(inout YumPbr pbr, float3 sample, uint mode, float mask)
}
#endif
+float getAngleAttenuation(float2 muv, float2 target_vector, float power) {
+ muv = muv * 2 - 1;
+ float NoL = dot(muv, target_vector);
+ NoL = halfLambertianNoL(NoL);
+ return pow(NoL, power);
+}
+
void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) {
#if defined(_MATCAP0) || defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1)
float2 muv = getMatcapUV(i, pbr);
@@ -69,6 +76,13 @@ void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) {
#else
float rl0_mask = 1;
#endif
+#if defined(_RIM_LIGHTING0_ANGLE_LIMIT)
+ rl0 *= getAngleAttenuation(muv, _Rim_Lighting0_Angle_Limit_Target_Vector,
+ _Rim_Lighting0_Angle_Limit_Power);
+#endif
+#if defined(_RIM_LIGHTING0_QUANTIZATION)
+ rl0 = floor(rl0 * _Rim_Lighting0_Quantization_Steps) / _Rim_Lighting0_Quantization_Steps;
+#endif
applyMatcap(pbr, rl0, _Rim_Lighting0_Mode, rl0_mask);
#endif
#if defined(_RIM_LIGHTING1)
@@ -79,6 +93,13 @@ void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) {
#else
float rl1_mask = 1;
#endif
+#if defined(_RIM_LIGHTING1_ANGLE_LIMIT)
+ rl1 *= getAngleAttenuation(muv, _Rim_Lighting1_Angle_Limit_Target_Vector,
+ _Rim_Lighting1_Angle_Limit_Power);
+#endif
+#if defined(_RIM_LIGHTING1_QUANTIZATION)
+ rl1 = floor(rl1 * _Rim_Lighting1_Quantization_Steps) / _Rim_Lighting1_Quantization_Steps;
+#endif
applyMatcap(pbr, rl1, _Rim_Lighting1_Mode, rl1_mask);
#endif
}