diff options
| author | yum <yum.food.vr@gmail.com> | 2025-02-26 15:06:36 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-02-26 15:06:36 -0800 |
| commit | d10dca271fd69606bde8e0a0e104db9140bfe52e (patch) | |
| tree | 02f42428ca3e08f986c8253e2804a2359dbdadb8 | |
| parent | 0264f5e767b0b54e82b7c11457b491be555be577 (diff) | |
matcaps/rim lighting can now affect lighting in addition to albedo
| -rw-r--r-- | 2ner.cginc | 4 | ||||
| -rw-r--r-- | 2ner.shader | 10 | ||||
| -rw-r--r-- | globals.cginc | 9 | ||||
| -rw-r--r-- | matcaps.cginc | 59 | ||||
| -rw-r--r-- | yum_lighting.cginc | 1 |
5 files changed, 62 insertions, 21 deletions
@@ -173,8 +173,10 @@ float4 frag(v2f i) : SV_Target { YumLighting l = GetYumLighting(i, pbr);
#if defined(FORWARD_BASE_PASS)
- applyMatcapsAndRimLighting(i, l, pbr);
+ applyMatcapsAndRimLighting(i, pbr, l);
pbr.albedo.rgb = max(0, pbr.albedo.rgb);
+ l.diffuse = max(0, l.diffuse);
+ l.specular = max(0, l.specular);
#endif
float4 lit = YumBRDF(i, l, pbr);
diff --git a/2ner.shader b/2ner.shader index 23cbd74..c1433e7 100644 --- a/2ner.shader +++ b/2ner.shader @@ -93,6 +93,8 @@ Shader "yum_food/2ner" [Toggle(_)]_Matcap0_Invert("Invert", Float) = 0 [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, AddProduct, 4)] _Matcap0_Mode("Mode", Int) = 0 + [ThryWideEnum(_0000b, 0, _0001b, 1, _0010b, 2, _0011b, 3, _0100b, 4, _0101b, 5, _0110b, 6, _0111b, 7, _1000b, 8, _1001b, 9, _1010b, 10, _1011b, 11, _1100b, 12, _1101b, 13, _1110b, 14, _1111b, 15)] + _Matcap0_Target_Mask("Target mask (albedo|diffuse<<1|specular<<2)", Int) = 1 _Matcap0_Strength("Strength", Float) = 1 //ifex _Matcap0_Mask_Enabled==0 [HideInInspector] m_start_Matcap0_Mask("Mask", Float) = 0 @@ -120,6 +122,8 @@ Shader "yum_food/2ner" _Rim_Lighting0_Brightness("Brightness", Float) = 1 [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, AddProduct, 4)] _Rim_Lighting0_Mode("Mode", Int) = 0 + [ThryWideEnum(_0000b, 0, _0001b, 1, _0010b, 2, _0011b, 3, _0100b, 4, _0101b, 5, _0110b, 6, _0111b, 7, _1000b, 8, _1001b, 9, _1010b, 10, _1011b, 11, _1100b, 12, _1101b, 13, _1110b, 14, _1111b, 15)] + _Rim_Lighting0_Target_Mask("Target mask (albedo|diffuse<<1|specular<<2)", Int) = 1 //ifex _Rim_Lighting0_Mask_Enabled==0 [HideInInspector] m_start_Rim_Lighting0_Mask("Mask", Float) = 0 [ThryToggle(_RIM_LIGHTING0_MASK)]_Rim_Lighting0_Mask_Enabled("Enable", Float) = 0 @@ -151,6 +155,8 @@ Shader "yum_food/2ner" _Rim_Lighting1_Brightness("Brightness", Float) = 1 [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, AddProduct, 4)] _Rim_Lighting1_Mode("Mode", Int) = 0 + [ThryWideEnum(_0000b, 0, _0001b, 1, _0010b, 2, _0011b, 3, _0100b, 4, _0101b, 5, _0110b, 6, _0111b, 7, _1000b, 8, _1001b, 9, _1010b, 10, _1011b, 11, _1100b, 12, _1101b, 13, _1110b, 14, _1111b, 15)] + _Rim_Lighting1_Target_Mask("Target mask (albedo|diffuse<<1|specular<<2)", Int) = 1 //ifex _Rim_Lighting1_Mask_Enabled==0 [HideInInspector] m_start_Rim_Lighting1_Mask("Mask", Float) = 0 [ThryToggle(_RIM_LIGHTINg1_MASK)]_Rim_Lighting1_Mask_Enabled("Enable", Float) = 0 @@ -182,6 +188,8 @@ Shader "yum_food/2ner" _Rim_Lighting2_Brightness("Brightness", Float) = 1 [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, AddProduct, 4)] _Rim_Lighting2_Mode("Mode", Int) = 0 + [ThryWideEnum(_0000b, 0, _0001b, 1, _0010b, 2, _0011b, 3, _0100b, 4, _0101b, 5, _0110b, 6, _0111b, 7, _1000b, 8, _1001b, 9, _1010b, 10, _1011b, 11, _1100b, 12, _1101b, 13, _1110b, 14, _1111b, 15)] + _Rim_Lighting2_Target_Mask("Target mask (albedo|diffuse<<1|specular<<2)", Int) = 1 //ifex _Rim_Lighting2_Mask_Enabled==0 [HideInInspector] m_start_Rim_Lighting2_Mask("Mask", Float) = 0 [ThryToggle(_RIM_LIGHTING2_MASK)]_Rim_Lighting2_Mask_Enabled("Enable", Float) = 0 @@ -213,6 +221,8 @@ Shader "yum_food/2ner" _Rim_Lighting3_Brightness("Brightness", Float) = 1 [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, AddProduct, 4)] _Rim_Lighting3_Mode("Mode", Int) = 0 + [ThryWideEnum(_0000b, 0, _0001b, 1, _0010b, 2, _0011b, 3, _0100b, 4, _0101b, 5, _0110b, 6, _0111b, 7, _1000b, 8, _1001b, 9, _1010b, 10, _1011b, 11, _1100b, 12, _1101b, 13, _1110b, 14, _1111b, 15)] + _Rim_Lighting3_Target_Mask("Target mask (albedo|diffuse<<1|specular<<2)", Int) = 1 //ifex _Rim_Lighting3_Mask_Enabled==0 [HideInInspector] m_start_Rim_Lighting3_Mask("Mask", Float) = 0 [ThryToggle(_RIM_LIGHTING3_MASK)]_Rim_Lighting3_Mask_Enabled("Enable", Float) = 0 diff --git a/globals.cginc b/globals.cginc index 6a42a32..83ba8fb 100644 --- a/globals.cginc +++ b/globals.cginc @@ -83,9 +83,14 @@ float _Outline_Mask_Invert; #define MATCAP_MODE_SUBTRACT 3
#define MATCAP_MODE_ADD_PRODUCT 4
+#define MATCAP_TARGET_ALBEDO (1)
+#define MATCAP_TARGET_DIFFUSE (2)
+#define MATCAP_TARGET_SPECULAR (4)
+
#if defined(_MATCAP0)
texture2D _Matcap0;
uint _Matcap0_Mode;
+uint _Matcap0_Target_Mask;
float _Matcap0_Invert;
float _Matcap0_Strength;
#if defined(_MATCAP0_MASK)
@@ -102,6 +107,7 @@ float _Rim_Lighting0_Center; float _Rim_Lighting0_Power;
float3 _Rim_Lighting0_Color;
float _Rim_Lighting0_Brightness;
+uint _Rim_Lighting0_Target_Mask;
#if defined(_RIM_LIGHTING0_MASK)
texture2D _Rim_Lighting0_Mask;
#endif
@@ -120,6 +126,7 @@ float _Rim_Lighting1_Center; float _Rim_Lighting1_Power;
float3 _Rim_Lighting1_Color;
float _Rim_Lighting1_Brightness;
+uint _Rim_Lighting1_Target_Mask;
#if defined(_RIM_LIGHTING1_MASK)
texture2D _Rim_Lighting1_Mask;
#endif
@@ -138,6 +145,7 @@ float _Rim_Lighting2_Center; float _Rim_Lighting2_Power;
float3 _Rim_Lighting2_Color;
float _Rim_Lighting2_Brightness;
+uint _Rim_Lighting2_Target_Mask;
#if defined(_RIM_LIGHTING2_MASK)
texture2D _Rim_Lighting2_Mask;
#endif
@@ -156,6 +164,7 @@ float _Rim_Lighting3_Center; float _Rim_Lighting3_Power;
float3 _Rim_Lighting3_Color;
float _Rim_Lighting3_Brightness;
+uint _Rim_Lighting3_Target_Mask;
#if defined(_RIM_LIGHTING3_MASK)
texture2D _Rim_Lighting3_Mask;
#endif
diff --git a/matcaps.cginc b/matcaps.cginc index 00b1d4f..ceb9918 100644 --- a/matcaps.cginc +++ b/matcaps.cginc @@ -4,9 +4,10 @@ #include "features.cginc" #include "globals.cginc" #include "interpolators.cginc" +#include "yum_lighting.cginc" #include "yum_pbr.cginc" -#if defined(_MATCAP0) || defined(_RIM_LIGHTING0) +#if defined(_MATCAP0) || defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) || defined(_RIM_LIGHTING2) || defined(_RIM_LIGHTING3) float2 getMatcapUV(v2f i, inout YumPbr pbr) { const float3 cam_normal = normalize(mul(UNITY_MATRIX_V, float4(pbr.normal, 0))); const float3 cam_view_dir = normalize(mul(UNITY_MATRIX_V, float4(-i.eyeVec.xyz, 0))); @@ -18,30 +19,47 @@ float2 getMatcapUV(v2f i, inout YumPbr pbr) { return cam_refl.xy / m + 0.5; } -void applyMatcap(inout YumPbr pbr, float3 sample, uint mode, float mask) +void applyMatcapImpl(inout float3 color, float3 sample, uint mode, float mask) { [forcecase] switch(mode) { case MATCAP_MODE_REPLACE: - pbr.albedo.rgb = lerp(pbr.albedo.rgb, sample, mask); + color.rgb = lerp(color.rgb, sample, mask); break; case MATCAP_MODE_ADD: - pbr.albedo.rgb += lerp(0, sample, mask); + color.rgb += lerp(0, sample, mask); break; case MATCAP_MODE_MULTIPLY: - pbr.albedo.rgb *= lerp(1, sample, mask); + color.rgb *= lerp(1, sample, mask); break; case MATCAP_MODE_SUBTRACT: - pbr.albedo.rgb -= lerp(0, sample, mask); + color.rgb -= lerp(0, sample, mask); break; case MATCAP_MODE_ADD_PRODUCT: - pbr.albedo.rgb += lerp(0, sample * pbr.albedo.rgb, mask); + color.rgb += lerp(0, sample * color.rgb, mask); break; default: break; } } -#endif + +void applyMatcap(inout YumPbr pbr, inout YumLighting l, float3 sample, + uint mode, uint target_mask, float mask) +{ + [branch] + if (target_mask & MATCAP_TARGET_ALBEDO) { + applyMatcapImpl(pbr.albedo.rgb, sample, mode, mask); + } + [branch] + if (target_mask & MATCAP_TARGET_DIFFUSE) { + applyMatcapImpl(l.diffuse, sample, mode, mask); + } + [branch] + if (target_mask & MATCAP_TARGET_SPECULAR) { + applyMatcapImpl(l.specular, sample, mode, mask); + } +} +#endif // _MATCAP0 || _RIM_LIGHTING0 || _RIM_LIGHTING1 || _RIM_LIGHTING2 || _RIM_LIGHTING3 float getAngleAttenuation(float2 muv, float2 target_vector, float power) { muv = muv * 2 - 1; @@ -50,7 +68,7 @@ float getAngleAttenuation(float2 muv, float2 target_vector, float power) { return pow(NoL, power); } -void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) { +void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr, inout YumLighting l) { #if defined(_MATCAP0) || defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) float2 muv = getMatcapUV(i, pbr); #endif @@ -72,9 +90,10 @@ void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) { #else float m0_mask = 1; #endif - applyMatcap(pbr, m0, _Matcap0_Mode, m0_mask); -#endif -#if defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) + applyMatcap(pbr, l, m0, _Matcap0_Mode, _Matcap0_Target_Mask, m0_mask); +#endif // _MATCAP0 + +#if defined(_RIM_LIGHTING0) || defined(_RIM_LIGHTING1) || defined(_RIM_LIGHTING2) || defined(_RIM_LIGHTING3) float rl_radius = length(muv - 0.5); #endif @@ -93,8 +112,8 @@ void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) { #else float rl0_mask = 1; #endif - applyMatcap(pbr, rl0, _Rim_Lighting0_Mode, rl0_mask); -#endif + applyMatcap(pbr, l, rl0, _Rim_Lighting0_Mode, _Rim_Lighting0_Target_Mask, rl0_mask); +#endif // _RIM_LIGHTING0 #if defined(_RIM_LIGHTING1) float rl1_dist = exp2(-_Rim_Lighting1_Power * abs(rl_radius - _Rim_Lighting1_Center)); @@ -111,8 +130,8 @@ void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) { #else float rl1_mask = 1; #endif - applyMatcap(pbr, rl1, _Rim_Lighting1_Mode, rl1_mask); -#endif + applyMatcap(pbr, l, rl1, _Rim_Lighting1_Mode, _Rim_Lighting1_Target_Mask, rl1_mask); +#endif // _RIM_LIGHTING1 #if defined(_RIM_LIGHTING2) float rl2_dist = exp2(-_Rim_Lighting2_Power * abs(rl_radius - _Rim_Lighting2_Center)); @@ -129,8 +148,8 @@ void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) { #else float rl2_mask = 1; #endif - applyMatcap(pbr, rl2, _Rim_Lighting2_Mode, rl2_mask); -#endif + applyMatcap(pbr, l, rl2, _Rim_Lighting2_Mode, _Rim_Lighting2_Target_Mask, rl2_mask); +#endif // _RIM_LIGHTING2 #if defined(_RIM_LIGHTING3) float rl3_dist = exp2(-_Rim_Lighting3_Power * abs(rl_radius - _Rim_Lighting3_Center)); @@ -147,8 +166,8 @@ void applyMatcapsAndRimLighting(v2f i, inout YumPbr pbr) { #else float rl3_mask = 1; #endif - applyMatcap(pbr, rl3, _Rim_Lighting3_Mode, rl3_mask); -#endif + applyMatcap(pbr, l, rl3, _Rim_Lighting3_Mode, _Rim_Lighting3_Target_Mask, rl3_mask); +#endif // _RIM_LIGHTING3 } #endif diff --git a/yum_lighting.cginc b/yum_lighting.cginc index 4effd1e..312e4a6 100644 --- a/yum_lighting.cginc +++ b/yum_lighting.cginc @@ -7,6 +7,7 @@ #include "UnityLightingCommon.cginc"
#include "features.cginc"
+#include "poi.cginc"
#include "yum_pbr.cginc"
// fucking kill me
|
