summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-07-20 01:46:51 -0700
committeryum <yum.food.vr@gmail.com>2024-07-20 01:46:51 -0700
commit6c1e463a846292a55cf10db772741cea657f298f (patch)
treef04f1171ba478adf570094cdb0f16cd2dd393406
parent0592c85cd172369625e084be6b037f8c122cbf16 (diff)
Add second mask to matcaps
Useful for PBR overlay.
-rw-r--r--Editor/tooner.cs15
-rw-r--r--feature_macros.cginc2
-rw-r--r--globals.cginc4
-rw-r--r--pbr.cginc5
-rw-r--r--tooner.shader6
-rw-r--r--tooner_lighting.cginc18
-rw-r--r--tooner_outline_pass.cginc2
7 files changed, 48 insertions, 4 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index bcdc160..89c14e5 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -321,6 +321,21 @@ public class ToonerGUI : ShaderGUI {
bc.floatValue = enabled ? 1.0f : 0.0f;
}
+ bc = FindProperty($"_Matcap{i}_Mask2");
+ editor.TexturePropertySingleLine(
+ MakeLabel(bc, "Mask"),
+ bc);
+ SetKeyword($"_MATCAP{i}_MASK2", bc.textureValue);
+
+ if (bc.textureValue) {
+ bc = FindProperty($"_Matcap{i}_Mask2_Invert");
+ enabled = bc.floatValue > 1E-6;
+ EditorGUI.BeginChangeCheck();
+ enabled = EditorGUILayout.Toggle("Invert mask", enabled);
+ EditorGUI.EndChangeCheck();
+ bc.floatValue = enabled ? 1.0f : 0.0f;
+ }
+
EditorGUI.BeginChangeCheck();
bc = FindProperty($"_Matcap{i}Mode");
MatcapMode mode = (MatcapMode) Math.Round(bc.floatValue);
diff --git a/feature_macros.cginc b/feature_macros.cginc
index 9247d92..af22501 100644
--- a/feature_macros.cginc
+++ b/feature_macros.cginc
@@ -19,8 +19,10 @@
#pragma shader_feature_local _ _UVSCROLL
#pragma shader_feature_local _ _MATCAP0
#pragma shader_feature_local _ _MATCAP0_MASK
+#pragma shader_feature_local _ _MATCAP0_MASK2
#pragma shader_feature_local _ _MATCAP1
#pragma shader_feature_local _ _MATCAP1_MASK
+#pragma shader_feature_local _ _MATCAP1_MASK2
#pragma shader_feature_local _ _RIM_LIGHTING0
#pragma shader_feature_local _ _RIM_LIGHTING0_MASK
#pragma shader_feature_local _ _RIM_LIGHTING0_GLITTER
diff --git a/globals.cginc b/globals.cginc
index 0ed9a54..607e98b 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -234,6 +234,8 @@ float _Enable_Matcap0;
texture2D _Matcap0;
texture2D _Matcap0_Mask;
float _Matcap0_Mask_Invert;
+texture2D _Matcap0_Mask2;
+float _Matcap0_Mask2_Invert;
float _Matcap0Str;
float _Matcap0Quantization;
float _Matcap0Mode;
@@ -245,6 +247,8 @@ float _Enable_Matcap1;
texture2D _Matcap1;
texture2D _Matcap1_Mask;
float _Matcap1_Mask_Invert;
+texture2D _Matcap1_Mask2;
+float _Matcap1_Mask2_Invert;
float _Matcap1Str;
float _Matcap1Quantization;
float _Matcap1Mode;
diff --git a/pbr.cginc b/pbr.cginc
index 9710ff5..d458aca 100644
--- a/pbr.cginc
+++ b/pbr.cginc
@@ -139,11 +139,10 @@ UnityIndirect CreateIndirectLight(float4 vertexLightColor, float3 view_dir, floa
env_data.reflUVW = BoxProjection(
reflect_dir, worldPos,
unity_SpecCube1_ProbePosition,
- unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax
- );
+ unity_SpecCube1_BoxMin.xyz, unity_SpecCube1_BoxMax.xyz);
float3 probe1 = Unity_GlossyEnvironment(
UNITY_PASS_TEXCUBE_SAMPLER(unity_SpecCube1, unity_SpecCube0),
- unity_SpecCube0_HDR, env_data
+ unity_SpecCube1_HDR, env_data
);
indirect.specular = lerp(probe1, probe0, unity_SpecCube0_BoxMin.w);
}
diff --git a/tooner.shader b/tooner.shader
index 47eea22..5904826 100644
--- a/tooner.shader
+++ b/tooner.shader
@@ -158,6 +158,8 @@ Shader "yum_food/tooner"
_Matcap0("Matcap", 2D) = "black" {}
_Matcap0_Mask("Matcap mask", 2D) = "white" {}
_Matcap0_Mask_Invert("Invert mask", Float) = 0.0
+ _Matcap0_Mask2("Matcap mask 2", 2D) = "white" {}
+ _Matcap0_Mask2_Invert("Invert mask", Float) = 0.0
_Matcap0Mode("Matcap mode", Float) = 0
_Matcap0Str("Matcap strength", Float) = 1
_Matcap0Emission("Matcap emission", Float) = 0
@@ -167,6 +169,8 @@ Shader "yum_food/tooner"
_Matcap1("Matcap", 2D) = "black" {}
_Matcap1_Mask("Matcap mask", 2D) = "white" {}
_Matcap1_Mask_Invert("Invert mask", Float) = 0.0
+ _Matcap1_Mask2("Matcap mask 2", 2D) = "white" {}
+ _Matcap1_Mask2_Invert("Invert mask", Float) = 0.0
_Matcap1Mode("Matcap mode", Float) = 0
_Matcap1Str("Matcap strength", Float) = 1
_Matcap1Emission("Matcap emission", Float) = 0
@@ -352,6 +356,7 @@ Shader "yum_food/tooner"
#include "tooner_lighting.cginc"
ENDCG
}
+ /*
Pass {
Tags {
"RenderType" = "Opaque"
@@ -420,6 +425,7 @@ Shader "yum_food/tooner"
#include "mochie_shadow_caster.cginc"
ENDCG
}
+ */
}
CustomEditor "ToonerGUI"
}
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index 68cfa57..650e66e 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -966,6 +966,15 @@ float4 effect(inout v2f i)
#else
float matcap_mask = 1;
#endif
+#if defined(_MATCAP0_MASK2)
+ {
+ float4 matcap_mask2_raw = _Matcap0_Mask2.SampleGrad(linear_repeat_s, i.uv.xy, iddx, iddy);
+ float matcap_mask2 = matcap_mask2_raw.r;
+ matcap_mask2 = (bool) round(_Matcap0_Mask2_Invert) ? 1 - matcap_mask2 : matcap_mask2;
+ matcap_mask2 *= matcap_mask2_raw.a;
+ matcap_mask *= matcap_mask2;
+ }
+#endif
int mode = round(_Matcap0Mode);
switch (mode) {
@@ -1019,6 +1028,15 @@ float4 effect(inout v2f i)
#else
float matcap_mask = 1;
#endif
+#if defined(_MATCAP1_MASK2)
+ {
+ float4 matcap_mask2_raw = _Matcap1_Mask2.SampleGrad(linear_repeat_s, i.uv.xy, iddx, iddy);
+ float matcap_mask2 = matcap_mask2_raw.r;
+ matcap_mask2 = (bool) round(_Matcap1_Mask2_Invert) ? 1 - matcap_mask2 : matcap_mask2;
+ matcap_mask2 *= matcap_mask2_raw.a;
+ matcap_mask *= matcap_mask2;
+ }
+#endif
int mode = round(_Matcap1Mode);
switch (mode) {
diff --git a/tooner_outline_pass.cginc b/tooner_outline_pass.cginc
index d225dc9..f2ea2b2 100644
--- a/tooner_outline_pass.cginc
+++ b/tooner_outline_pass.cginc
@@ -71,7 +71,7 @@ v2f vert(appdata v)
#endif
v2f o;
- o.worldPos = mul(unity_ObjectToWorld, float4(objPos.xyz, 1));
+ o.worldPos = mul(unity_ObjectToWorld, objPos);
o.objPos = objPos;
o.pos = UnityObjectToClipPos(objPos);
o.normal = UnityObjectToWorldNormal(v.normal);