summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-09-23 01:46:23 -0700
committeryum <yum.food.vr@gmail.com>2024-09-23 13:41:42 -0700
commit88a524d71bf46bca1c65c3f7ed5fcd3f6edd1d5e (patch)
treeffc25a73064e9014921eecd08c2f76d453bb84ae
parent8bcfe9a6a31e4c4400cb0be4fb1823748ec7fcb2 (diff)
Begin refactoring c#
I want all the SetKeyword stuff to run whether or not the UI is shown.
-rw-r--r--Editor/tooner.cs56
-rw-r--r--tooner_lighting.cginc18
2 files changed, 58 insertions, 16 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs
index 1ee5135..29ff40b 100644
--- a/Editor/tooner.cs
+++ b/Editor/tooner.cs
@@ -47,7 +47,11 @@ public class ToonerGUI : ShaderGUI {
}
}
- void DoBaseColor() {
+ void DoBaseColorLogic() {
+ MaterialProperty bct = FindProperty("_MainTex");
+ SetKeyword("_BASECOLOR_MAP", bct.textureValue);
+ }
+ void DoBaseColorUI() {
MaterialProperty bc = FindProperty("_Color");
MaterialProperty bct = FindProperty("_MainTex");
editor.TexturePropertySingleLine(
@@ -57,10 +61,13 @@ public class ToonerGUI : ShaderGUI {
if (bct.textureValue) {
editor.TextureScaleOffsetProperty(bct);
}
- SetKeyword("_BASECOLOR_MAP", bct.textureValue);
}
- void DoNormal() {
+ void DoNormalLogic() {
+ MaterialProperty bct = FindProperty("_NormalTex");
+ SetKeyword("_NORMAL_MAP", bct.textureValue);
+ }
+ void DoNormalUI() {
MaterialProperty bct = FindProperty("_NormalTex");
editor.TexturePropertySingleLine(
MakeLabel(bct, "Normal"),
@@ -69,10 +76,13 @@ public class ToonerGUI : ShaderGUI {
if (bct.textureValue) {
editor.TextureScaleOffsetProperty(bct);
}
- SetKeyword("_NORMAL_MAP", bct.textureValue);
}
- void DoMetallic() {
+ void DoMetallicLogic() {
+ MaterialProperty bct = FindProperty("_MetallicTex");
+ SetKeyword("_METALLIC_MAP", bct.textureValue);
+ }
+ void DoMetallicUI() {
MaterialProperty bc = FindProperty("_Metallic");
MaterialProperty bct = FindProperty("_MetallicTex");
editor.TexturePropertySingleLine(
@@ -82,10 +92,13 @@ public class ToonerGUI : ShaderGUI {
if (bct.textureValue) {
editor.TextureScaleOffsetProperty(bct);
}
- SetKeyword("_METALLIC_MAP", bct.textureValue);
}
- void DoRoughness() {
+ void DoRoughnessLogic() {
+ MaterialProperty bct = FindProperty("_RoughnessTex");
+ SetKeyword("_ROUGHNESS_MAP", bct.textureValue);
+ }
+ void DoRoughnessUI() {
MaterialProperty bc = FindProperty("_Roughness");
MaterialProperty bct = FindProperty("_RoughnessTex");
editor.TexturePropertySingleLine(
@@ -102,8 +115,6 @@ public class ToonerGUI : ShaderGUI {
EditorGUI.EndChangeCheck();
bc.floatValue = enabled ? 1.0f : 0.0f;
}
-
- SetKeyword("_ROUGHNESS_MAP", bct.textureValue);
}
bool AddCollapsibleMenu(string name, string matprop) {
@@ -124,16 +135,27 @@ public class ToonerGUI : ShaderGUI {
Repeat,
Clamp,
};
- void DoPBR() {
+ void DoPBRLogic() {
+ DoBaseColorLogic();
+ DoNormalLogic();
+ DoMetallicLogic();
+ DoRoughnessLogic();
+
+ MaterialProperty bc = FindProperty($"_PBR_Sampler_Mode");
+ SamplerMode sampler_mode = (SamplerMode) Math.Round(bc.floatValue);
+ SetKeyword($"_PBR_SAMPLER_REPEAT", sampler_mode == SamplerMode.Repeat);
+ SetKeyword($"_PBR_SAMPLER_CLAMP", sampler_mode == SamplerMode.Clamp);
+ }
+ void DoPBRUI() {
if (!AddCollapsibleMenu("PBR", "_PBR")) {
return;
}
EditorGUI.indentLevel += 1;
{
- DoBaseColor();
- DoNormal();
- DoMetallic();
- DoRoughness();
+ DoBaseColorUI();
+ DoNormalUI();
+ DoMetallicUI();
+ DoRoughnessUI();
EditorGUI.BeginChangeCheck();
MaterialProperty bc = FindProperty($"_PBR_Sampler_Mode");
@@ -142,11 +164,13 @@ public class ToonerGUI : ShaderGUI {
MakeLabel("Sampler mode"), sampler_mode);
EditorGUI.EndChangeCheck();
bc.floatValue = (int) sampler_mode;
- SetKeyword($"_PBR_SAMPLER_REPEAT", sampler_mode == SamplerMode.Repeat);
- SetKeyword($"_PBR_SAMPLER_CLAMP", sampler_mode == SamplerMode.Clamp);
}
EditorGUI.indentLevel -= 1;
}
+ void DoPBR() {
+ DoPBRLogic();
+ DoPBRUI();
+ }
void DoClearcoat() {
if (!AddCollapsibleMenu($"Clearcoat", $"_Clearcoat")) {
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index 970a965..24d240b 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -580,46 +580,64 @@ float2 get_uv_by_channel(v2f i, uint which_channel) {
#define GET_SAMPLER_PBR linear_repeat_s
#elif defined(_PBR_SAMPLER_CLAMP)
#define GET_SAMPLER_PBR linear_clamp_s
+#else
+#define GET_SAMPLER_PBR linear_clamp_s
#endif
#if defined(_PBR_OVERLAY0_SAMPLER_REPEAT)
#define GET_SAMPLER_OV0 linear_repeat_s
#elif defined(_PBR_OVERLAY0_SAMPLER_CLAMP)
#define GET_SAMPLER_OV0 linear_clamp_s
+#else
+#define GET_SAMPLER_OV0 linear_clamp_s
#endif
#if defined(_PBR_OVERLAY1_SAMPLER_REPEAT)
#define GET_SAMPLER_OV1 linear_repeat_s
#elif defined(_PBR_OVERLAY1_SAMPLER_CLAMP)
#define GET_SAMPLER_OV1 linear_clamp_s
+#else
+#define GET_SAMPLER_OV1 linear_clamp_s
#endif
#if defined(_PBR_OVERLAY2_SAMPLER_REPEAT)
#define GET_SAMPLER_OV2 linear_repeat_s
#elif defined(_PBR_OVERLAY2_SAMPLER_CLAMP)
#define GET_SAMPLER_OV2 linear_clamp_s
+#else
+#define GET_SAMPLER_OV2 linear_clamp_s
#endif
#if defined(_PBR_OVERLAY3_SAMPLER_REPEAT)
#define GET_SAMPLER_OV3 linear_repeat_s
#elif defined(_PBR_OVERLAY3_SAMPLER_CLAMP)
#define GET_SAMPLER_OV3 linear_clamp_s
+#else
+#define GET_SAMPLER_OV3 linear_clamp_s
#endif
#if defined(_RIM_LIGHTING0_SAMPLER_REPEAT)
#define GET_SAMPLER_RL0 linear_repeat_s
#elif defined(_RIM_LIGHTING0_SAMPLER_CLAMP)
#define GET_SAMPLER_RL0 linear_clamp_s
+#else
+#define GET_SAMPLER_RL0 linear_clamp_s
#endif
#if defined(_RIM_LIGHTING1_SAMPLER_REPEAT)
#define GET_SAMPLER_RL1 linear_repeat_s
#elif defined(_RIM_LIGHTING1_SAMPLER_CLAMP)
#define GET_SAMPLER_RL1 linear_clamp_s
+#else
+#define GET_SAMPLER_RL1 linear_clamp_s
#endif
#if defined(_RIM_LIGHTING2_SAMPLER_REPEAT)
#define GET_SAMPLER_RL2 linear_repeat_s
#elif defined(_RIM_LIGHTING2_SAMPLER_CLAMP)
#define GET_SAMPLER_RL2 linear_clamp_s
+#else
+#define GET_SAMPLER_RL2 linear_clamp_s
#endif
#if defined(_RIM_LIGHTING3_SAMPLER_REPEAT)
#define GET_SAMPLER_RL3 linear_repeat_s
#elif defined(_RIM_LIGHTING3_SAMPLER_CLAMP)
#define GET_SAMPLER_RL3 linear_clamp_s
+#else
+#define GET_SAMPLER_RL3 linear_clamp_s
#endif
struct PbrOverlay {