diff options
| author | yum <yum.food.vr@gmail.com> | 2026-02-25 19:19:55 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-02-25 19:19:55 -0800 |
| commit | 5460dbc62fe6f404cb244410af949864cce286f5 (patch) | |
| tree | 9060baaf132d5b12714e9fc7fc91015050af8624 | |
| parent | 69dded4f94ab2f7e99b4959793a9eaf1f19aef07 (diff) | |
Add second matcap slot
| -rwxr-xr-x | 3ner.shader | 24 | ||||
| -rwxr-xr-x | features.cginc | 6 | ||||
| -rwxr-xr-x | globals.cginc | 14 | ||||
| -rwxr-xr-x | lighting.cginc | 3 | ||||
| -rw-r--r-- | matcap.cginc | 21 |
5 files changed, 64 insertions, 4 deletions
diff --git a/3ner.shader b/3ner.shader index 7386ba7..be4a19b 100755 --- a/3ner.shader +++ b/3ner.shader @@ -80,6 +80,30 @@ Shader "yum_food/3ner" //endex [HideInInspector] m_end_Matcap0("Matcap 0", Float) = 0 //endex + + //ifex _Matcap1_Enabled==0 + [HideInInspector] m_start_Matcap1("Matcap 1", Float) = 0 + [ThryToggle(_MATCAP1)] _Matcap1_Enabled("Enable", Float) = 0 + _Matcap1("Matcap", 2D) = "white" {} + _Matcap1_Strength("Strength", Range(0, 10)) = 1 + [ThryWideEnum(Replace, 0, Add, 1, Multiply, 2, Subtract, 3, Add Product, 4)] _Matcap1_Mode("Mode", Int) = 0 + [Toggle] _Matcap1_Invert("Invert", Float) = 0 + + //ifex _Matcap1_Quantization_Enabled==0 + [HideInInspector] m_start_Matcap1_Quantization("Quantization", Float) = 0 + [ThryToggle(_MATCAP1_QUANTIZATION)] _Matcap1_Quantization_Enabled("Enable", Float) = 0 + [IntRange] _Matcap1_Quantization_Steps("Steps", Range(1, 32)) = 8 + [HideInInspector] m_end_Matcap1_Quantization("Quantization", Float) = 0 + //endex + + //ifex _Matcap1_Mask_Enabled==0 + [HideInInspector] m_start_Matcap1_Mask("Mask", Float) = 0 + [ThryToggle(_MATCAP1_MASK)] _Matcap1_Mask_Enabled("Enable", Float) = 0 + _Matcap1_Mask("Mask", 2D) = "white" {} + [HideInInspector] m_end_Matcap1_Mask("Mask", Float) = 0 + //endex + [HideInInspector] m_end_Matcap1("Matcap 1", Float) = 0 + //endex [HideInInspector] m_end_Matcaps("Matcaps", Float) = 0 [HideInInspector] m_start_Rim_Lightings("Rim Lighting", Float) = 0 diff --git a/features.cginc b/features.cginc index a3be4bc..bd527ba 100755 --- a/features.cginc +++ b/features.cginc @@ -168,6 +168,12 @@ #pragma shader_feature_local _MATCAP0_MASK //endex +//ifex _Matcap1_Enabled==0 +#pragma shader_feature_local _MATCAP1 +#pragma shader_feature_local _MATCAP1_QUANTIZATION +#pragma shader_feature_local _MATCAP1_MASK +//endex + //ifex _Rim_Lighting0_Enabled==0 #pragma shader_feature_local _RIM_LIGHTING0 #pragma shader_feature_local _RIM_LIGHTING0_QUANTIZATION diff --git a/globals.cginc b/globals.cginc index 99afdad..00dd279 100755 --- a/globals.cginc +++ b/globals.cginc @@ -268,6 +268,20 @@ float4 _Matcap0_Mask_ST; #endif // _MATCAP0_MASK #endif // _MATCAP0 +#if defined(_MATCAP1) +texture2D _Matcap1; +float _Matcap1_Strength; +int _Matcap1_Mode; +float _Matcap1_Invert; +#if defined(_MATCAP1_QUANTIZATION) +float _Matcap1_Quantization_Steps; +#endif // _MATCAP1_QUANTIZATION +#if defined(_MATCAP1_MASK) +texture2D _Matcap1_Mask; +float4 _Matcap1_Mask_ST; +#endif // _MATCAP1_MASK +#endif // _MATCAP1 + #if defined(_RIM_LIGHTING0) float4 _Rim_Lighting0_Color; float _Rim_Lighting0_Center; diff --git a/lighting.cginc b/lighting.cginc index f7fae86..2820c12 100755 --- a/lighting.cginc +++ b/lighting.cginc @@ -201,7 +201,6 @@ float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightData light) { #endif #if defined(_SHADOWS) - //diffuse.xyz = lerp(diffuse.xyz, _Shadow_0_Color.rgb, _Shadow_0_Threshold); float3x3 mat = float3x3( light.indirect.L01r, light.indirect.L01g, @@ -209,7 +208,7 @@ float4 getIndirectDiffuse(v2f i, Pbr pbr, inout LightData light) { ); // Multiply unit vector by L1 matrix to get vector pointing in direction of // light. - float3 dom_dir = normalize(mul(mat, float3(1,1,1))); + float3 dom_dir = normalize(mul(float3(1,1,1), mat)); float light_amount = dot(dom_dir, pbr.normal); float3 shadow_color = lerp( _Shadow_0_Color.rgb, diff --git a/matcap.cginc b/matcap.cginc index 55eff5a..d9391af 100644 --- a/matcap.cginc +++ b/matcap.cginc @@ -6,7 +6,7 @@ #include "pbr.cginc" #include "texture_utils.cginc" -#if defined(_MATCAP0) || defined(_RIM_LIGHTING0) +#if defined(_MATCAP0) || defined(_MATCAP1) || defined(_RIM_LIGHTING0) float2 getMatcapUV(v2f i, Pbr 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))); @@ -55,7 +55,7 @@ float2 quantizeMatcapUV(float2 muv, float muv_r, float steps) { #endif // _MATCAP0 || _RIM_LIGHTING0 void applyMatcapsAndRimLighting(v2f i, inout Pbr pbr, inout LightData light_data) { -#if defined(_MATCAP0) || defined(_RIM_LIGHTING0) +#if defined(_MATCAP0) || defined(_MATCAP1) || defined(_RIM_LIGHTING0) float2 muv = getMatcapUV(i, pbr); float2 muv_centered = muv * 2 - 1; float muv_r = length(muv_centered); @@ -78,6 +78,23 @@ void applyMatcapsAndRimLighting(v2f i, inout Pbr pbr, inout LightData light_data applyMatcap(pbr, m0, _Matcap0_Mode, m0_mask); #endif // _MATCAP0 +#if defined(_MATCAP1) +#if defined(_MATCAP1_QUANTIZATION) + float2 m1uv = quantizeMatcapUV(muv, muv_r, _Matcap1_Quantization_Steps); +#else + float2 m1uv = muv; +#endif + float3 m1 = _Matcap1.Sample(linear_repeat_s, m1uv); + m1 = _Matcap1_Invert ? 1 - m1 : m1; + m1 *= _Matcap1_Strength; +#if defined(_MATCAP1_MASK) + float m1_mask = _Matcap1_Mask.Sample(linear_repeat_s, UV_SCOFF(i, _Matcap1_Mask_ST, /*which_channel=*/0)); +#else + float m1_mask = 1; +#endif + applyMatcap(pbr, m1, _Matcap1_Mode, m1_mask); +#endif // _MATCAP1 + #if defined(_RIM_LIGHTING0) // 1 at rim center, 0 outside blur radius. float rl0_inner = smoothstep( |
