diff options
| author | yum <yum.food.vr@gmail.com> | 2024-11-03 15:25:08 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-11-03 15:25:54 -0800 |
| commit | b7d3cb5d759feab1e44f4cdb01a0c8922bf4f1cb (patch) | |
| tree | cc10c40ac2e632dd07a0ac0fe515048b354af7f9 | |
| parent | cb55e813456480a036673d1d32608e10b10c8f87 (diff) | |
Misc
* Add third HSV slot
* Add ZTest enum
* Fix bug where SSR mask keyword can be set when SSR is disabled
| -rw-r--r-- | Editor/tooner.cs | 27 | ||||
| -rw-r--r-- | MochieStandardBRDF.cginc | 1 | ||||
| -rw-r--r-- | feature_macros.cginc | 1 | ||||
| -rw-r--r-- | globals.cginc | 9 | ||||
| -rw-r--r-- | pbr.cginc | 2 | ||||
| -rw-r--r-- | tooner.shader | 14 | ||||
| -rw-r--r-- | tooner_lighting.cginc | 21 |
7 files changed, 69 insertions, 6 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index fdd81b0..f6f3da8 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -1082,7 +1082,7 @@ public class ToonerGUI : ShaderGUI { MaterialProperty bc; - for (int i = 0; i < 2; i++) { + for (int i = 0; i < 3; i++) { bc = FindProperty($"_HSV{i}_Enabled"); bool enabled = bc.floatValue > 1E-6; EditorGUI.BeginChangeCheck(); @@ -2347,6 +2347,8 @@ public class ToonerGUI : ShaderGUI { SetKeyword("SSR_MASK", bc.textureValue); EditorGUI.indentLevel -= 1; + } else { + SetKeyword("SSR_MASK", false); } EditorGUI.indentLevel -= 1; @@ -2366,6 +2368,21 @@ public class ToonerGUI : ShaderGUI { Stochastic } + // unity is made by fucking morons and they don't expose this so i'm + // reimplementing it + // ref: https://docs.unity3d.com/6000.0/Documentation/Manual/SL-ZTest.html + enum ZTestMode { + Disabled, + Never, + Less, + Equal, + LEqual, + Greater, + NotEqual, + GEqual, + Always + } + void DoRendering() { show_ui.Add(AddCollapsibleMenu("Rendering", "_Rendering")); EditorGUI.indentLevel += 1; @@ -2479,6 +2496,14 @@ public class ToonerGUI : ShaderGUI { bc.floatValue = (float) cull_mode; } + EditorGUI.BeginChangeCheck(); + bc = FindProperty("_ZTest"); + ZTestMode zmode = (ZTestMode) Math.Round(bc.floatValue); + zmode = (ZTestMode) EnumPopup( + MakeLabel("ZTest"), zmode); + EditorGUI.EndChangeCheck(); + bc.floatValue = (float) zmode; + bc = FindProperty("_Discard_Enable_Static"); bool enabled = bc.floatValue > 1E-6; EditorGUI.BeginChangeCheck(); diff --git a/MochieStandardBRDF.cginc b/MochieStandardBRDF.cginc index fbf6b66..867904a 100644 --- a/MochieStandardBRDF.cginc +++ b/MochieStandardBRDF.cginc @@ -138,6 +138,7 @@ half4 BRDF1_Mochie_PBS ( diffCol = diffColor * (gi.diffuse + light.color * lerp(diffuseTerm, wrappedDiffuse, thickness)); half3 specCol = specularTerm * light.color * FresnelTerm (specColor, lh) * _SpecularStrength; + half3 reflCol = surfaceReduction * gi.specular * FresnelLerp (specColor, grazingTerm, lerp(1, nv, _FresnelStrength*_UseFresnel)) * reflection_strength; #if SSR_ENABLED half4 ssrCol = GetSSR(worldPos, viewDir, reflect(-viewDir, normal), normal, smoothness, diffColor, metallic, screenUVs, screenPos); diff --git a/feature_macros.cginc b/feature_macros.cginc index 6865208..1bcb217 100644 --- a/feature_macros.cginc +++ b/feature_macros.cginc @@ -86,6 +86,7 @@ #pragma shader_feature_local _ _OKLAB #pragma shader_feature_local _ _HSV0 #pragma shader_feature_local _ _HSV1 +#pragma shader_feature_local _ _HSV2 #pragma shader_feature_local _ _CLONES #pragma shader_feature_local _ _PBR_OVERLAY0 #pragma shader_feature_local _ _PBR_OVERLAY0_BASECOLOR_MAP diff --git a/globals.cginc b/globals.cginc index 76f6fa0..4b032c9 100644 --- a/globals.cginc +++ b/globals.cginc @@ -564,6 +564,15 @@ float _HSV1_Sat_Shift; float _HSV1_Val_Shift; #endif +#if defined(_HSV2) +float _HSV2_Enabled; +texture2D _HSV2_Mask; +float _HSV2_Mask_Invert; +float _HSV2_Hue_Shift; +float _HSV2_Sat_Shift; +float _HSV2_Val_Shift; +#endif + #if defined(_CLONES) float _Clones_Enabled; float _Clones_Count; @@ -233,8 +233,6 @@ float4 getLitColor( #endif UnityLight direct_light; - direct_light.dir = getDirectLightDirection(i); - direct_light.ndotl = DotClamped(normal, direct_light.dir); direct_light.color = 0; { direct_light.dir = getDirectLightDirection(i); diff --git a/tooner.shader b/tooner.shader index 05ea499..a21a52f 100644 --- a/tooner.shader +++ b/tooner.shader @@ -3,7 +3,7 @@ Shader "yum_food/tooner" // Unity fucking sucks ass and sometimes incorrectly uses an old cached // version of the shader. Bump the nonce below to encourage it to use the // current version. - // Build nonce: 32 + // Build nonce: 34 Properties { _Color("Base color", Color) = (0.8, 0.8, 0.8, 1) @@ -274,6 +274,7 @@ Shader "yum_food/tooner" [HideInInspector] _SrcBlend ("_SrcBlend", Float) = 1 [HideInInspector] _DstBlend ("_SrcBlend", Float) = 0 [HideInInspector] _ZWrite ("_ZWrite", Float) = 1 + [HideInInspector] _ZTest ("_ZTest", Float) = 4 // LEqual _Matcap0("Matcap", 2D) = "black" {} _Matcap0_Mask("Matcap mask", 2D) = "white" {} @@ -448,6 +449,13 @@ Shader "yum_food/tooner" _HSV1_Sat_Shift("HSV saturation shift", Range(-1.0, 1.0)) = 0.0 _HSV1_Val_Shift("HSV value shift", Range(-1.0, 1.0)) = 0.0 + _HSV2_Enabled("Enable HSV", Float) = 0.0 + _HSV2_Mask("Mask", 2D) = "white" {} + _HSV2_Mask_Invert("Mask invert", Float) = 0.0 + _HSV2_Hue_Shift("HSV hue shift", Range(0.0, 1.0)) = 0.0 + _HSV2_Sat_Shift("HSV saturation shift", Range(-1.0, 1.0)) = 0.0 + _HSV2_Val_Shift("HSV value shift", Range(-1.0, 1.0)) = 0.0 + _Clones_Enabled("Enable clones", Float) = 0.0 _Clones_Count("Clones count", Range(0,16)) = 0.0 _Clones_Dist_Cutoff("distance cutoff", Float) = -1.0 @@ -711,7 +719,7 @@ Shader "yum_food/tooner" } Blend [_SrcBlend] [_DstBlend] ZWrite [_ZWrite] - ZTest LEqual + ZTest [_ZTest] Cull [_Cull] Stencil { @@ -775,7 +783,7 @@ Shader "yum_food/tooner" Cull [_OutlinesCull] ZWrite [_ZWrite] - ZTest LEqual + ZTest [_ZTest] Stencil { Ref [_Stencil_Ref_Outline] diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc index e79681a..2952f29 100644 --- a/tooner_lighting.cginc +++ b/tooner_lighting.cginc @@ -2345,6 +2345,27 @@ float4 effect(inout v2f i, out float depth) } #endif +#if defined(_HSV2) + { + float hsv_mask = _HSV2_Mask.SampleBias(linear_repeat_s, i.uv0, _Global_Sample_Bias); + if (_HSV2_Mask_Invert) { + hsv_mask = 1 - hsv_mask; + } + if (hsv_mask > 0.01 && + (_HSV2_Hue_Shift > 1E-6 || + abs(_HSV2_Sat_Shift) > 1E-6 || + abs(_HSV2_Val_Shift) > 1E-6)) { + float3 c = albedo.rgb; + c = RGBtoHSV(c); + c += float3(_HSV2_Hue_Shift, _HSV2_Sat_Shift, _HSV2_Val_Shift); + c.x = glsl_mod(c.x, 1.0); + c.yz = saturate(c.yz); + c = HSVtoRGB(c); + albedo.rgb = c; + } + } +#endif + #if defined(_AMBIENT_OCCLUSION) float ao = _Ambient_Occlusion.SampleBias(linear_repeat_s, UV_SCOFF(i, _Ambient_Occlusion_ST, /*uv_channel=*/0), |
