From 94f37fa8dd94137a910df4ebc80f98db2d685f08 Mon Sep 17 00:00:00 2001 From: yum Date: Fri, 25 Oct 2024 15:05:56 -0700 Subject: Add features for constant rim lighting view direction Add vector to control rim lighting view dir (y does nothing) and toggle to enable doing reflection calculation in world space. --- tooner_lighting.cginc | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'tooner_lighting.cginc') diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index bcad86a..1b306ce 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -1708,10 +1708,18 @@ float4 effect(inout v2f i, out float depth) #if defined(_RIM_LIGHTING0) { float3 rl_view_dir = VIEW_DIR(_Rim_Lighting0_Center_Eye_Fix); +#if defined(_RIM_LIGHTING0_CUSTOM_VIEW_VECTOR) + rl_view_dir.xz = normalize(_Rim_Lighting0_Custom_View_Vector).xz; +#endif float2 rl_uv; { +#if defined(_RIM_LIGHTING0_REFLECT_IN_WORLD) + const float3 cam_normal = normal; + const float3 cam_view_dir = rl_view_dir; +#else const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 0))); const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(rl_view_dir, 0))); +#endif const float3 cam_refl = -reflect(cam_view_dir, cam_normal); float m = 2.0 * sqrt( cam_refl.x * cam_refl.x + @@ -1723,7 +1731,7 @@ float4 effect(inout v2f i, out float depth) float rl = length(rl_uv - 0.5); rl = pow(2, -_Rim_Lighting0_Power * abs(rl - _Rim_Lighting0_Center)); float q = _Rim_Lighting0_Quantization; - if (q > -1) { + if (q > 0) { rl = floor(rl * q) / q; } float3 matcap = rl * _Rim_Lighting0_Color * _Rim_Lighting0_Strength; @@ -1798,11 +1806,19 @@ float4 effect(inout v2f i, out float depth) #endif // _RIM_LIGHTING0 #if defined(_RIM_LIGHTING1) { - float3 rl_view_dir = VIEW_DIR(_Rim_Lighting0_Center_Eye_Fix); + float3 rl_view_dir = VIEW_DIR(_Rim_Lighting1_Center_Eye_Fix); +#if defined(_RIM_LIGHTING1_CUSTOM_VIEW_VECTOR) + rl_view_dir.xz = normalize(_Rim_Lighting1_Custom_View_Vector).xz; +#endif float2 rl_uv; { +#if defined(_RIM_LIGHTING1_REFLECT_IN_WORLD) + const float3 cam_normal = normal; + const float3 cam_view_dir = rl_view_dir; +#else const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 0))); const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(rl_view_dir, 0))); +#endif const float3 cam_refl = -reflect(cam_view_dir, cam_normal); float m = 2.0 * sqrt( cam_refl.x * cam_refl.x + @@ -1889,11 +1905,19 @@ float4 effect(inout v2f i, out float depth) #endif // _RIM_LIGHTING1 #if defined(_RIM_LIGHTING2) { - float3 rl_view_dir = VIEW_DIR(_Rim_Lighting0_Center_Eye_Fix); + float3 rl_view_dir = VIEW_DIR(_Rim_Lighting2_Center_Eye_Fix); +#if defined(_RIM_LIGHTING2_CUSTOM_VIEW_VECTOR) + rl_view_dir.xz = normalize(_Rim_Lighting2_Custom_View_Vector).xz; +#endif float2 rl_uv; { +#if defined(_RIM_LIGHTING2_REFLECT_IN_WORLD) + const float3 cam_normal = normal; + const float3 cam_view_dir = rl_view_dir; +#else const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 0))); const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(rl_view_dir, 0))); +#endif const float3 cam_refl = -reflect(cam_view_dir, cam_normal); float m = 2.0 * sqrt( cam_refl.x * cam_refl.x + @@ -1980,11 +2004,19 @@ float4 effect(inout v2f i, out float depth) #endif // _RIM_LIGHTING2 #if defined(_RIM_LIGHTING3) { - float3 rl_view_dir = VIEW_DIR(_Rim_Lighting0_Center_Eye_Fix); + float3 rl_view_dir = VIEW_DIR(_Rim_Lighting3_Center_Eye_Fix); +#if defined(_RIM_LIGHTING3_CUSTOM_VIEW_VECTOR) + rl_view_dir.xz = normalize(_Rim_Lighting3_Custom_View_Vector).xz; +#endif float2 rl_uv; { +#if defined(_RIM_LIGHTING3_REFLECT_IN_WORLD) + const float3 cam_normal = normal; + const float3 cam_view_dir = rl_view_dir; +#else const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(normal, 0))); const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(rl_view_dir, 0))); +#endif const float3 cam_refl = -reflect(cam_view_dir, cam_normal); float m = 2.0 * sqrt( cam_refl.x * cam_refl.x + -- cgit v1.2.3