Skip to content

Commit

Permalink
ShaderGUI, Property naming
Browse files Browse the repository at this point in the history
Added first iteration of shader gui for the unlit TMP3D shader
Renamed some shader keywords for better reflecting their usage
  • Loading branch information
Ikaroon committed May 10, 2022
1 parent b5b840d commit 0a1ec6b
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 126 deletions.
8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Editor/Ikaroon.TMP3D.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Ikaroon.TMP3D.Editor",
"rootNamespace": "",
"references": [
"GUID:6546d7765b4165b40850b3667f981c26",
"GUID:6055be8ebefd69e48b49212b09b47b2f"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/Ikaroon.TMP3D.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

155 changes: 155 additions & 0 deletions Editor/Scripts/TMP3D_UnlitShaderGUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using UnityEngine;
using UnityEditor;
using TMPro.EditorUtilities;
using TMPro;

namespace Ikaroon.TMP3DEditor
{
public class TMP3D_UnlitShaderGUI : TMP_BaseShaderGUI
{
public enum VolumeMode
{
Surface,
Full
}

static ShaderFeature s_OutlineFeature;

static bool s_Face = true;
static bool s_Outline = true;
static bool s_Raymarch = true;

const string c_volumeModeSurface = "_VOLUMEMODE_SURFACE";
const string c_volumeModeFull = "_VOLUMEMODE_FULL";

static TMP3D_UnlitShaderGUI()
{
s_OutlineFeature = new ShaderFeature()
{
undoLabel = "Outline",
keywords = new[] { "OUTLINE_ON" }
};
}

VolumeMode GetVolumeMode(Material material)
{
if (material.IsKeywordEnabled(c_volumeModeSurface))
return VolumeMode.Surface;

if (material.IsKeywordEnabled(c_volumeModeFull))
return VolumeMode.Full;

material.EnableKeyword(c_volumeModeSurface);
return VolumeMode.Surface;
}

protected override void DoGUI()
{
s_Face = BeginPanel("Face", s_Face);
if (s_Face)
{
DoFacePanel();
}

EndPanel();

s_Outline = BeginPanel("Outline", s_OutlineFeature, s_Outline);
if (s_Outline)
{
DoOutlinePanel();
}

EndPanel();

s_Raymarch = BeginPanel("Raymarch", s_Raymarch);
if (s_Raymarch)
{
DoRaymarchPanel();
}

EndPanel();

s_DebugExtended = BeginPanel("Debug Settings", s_DebugExtended);
if (s_DebugExtended)
{
DoDebugPanel();
}

EndPanel();
}

void DoFacePanel()
{
EditorGUI.indentLevel += 1;

DoColor("_FaceColor", "Color");

EditorGUI.indentLevel -= 1;
EditorGUILayout.Space();
}

void DoOutlinePanel()
{
EditorGUI.indentLevel += 1;
DoColor("_OutlineColor", "Color");
DoSlider("_OutlineWidth", "Thickness");

EditorGUI.indentLevel -= 1;
EditorGUILayout.Space();
}

void DoRaymarchPanel()
{
EditorGUI.indentLevel += 1;

var mode = GetVolumeMode(m_Material);
var targetMode = (VolumeMode)EditorGUILayout.EnumPopup(new GUIContent("Volume Mode"), mode);
if (targetMode != mode)
{
switch (targetMode)
{
case VolumeMode.Surface:
m_Material.EnableKeyword(c_volumeModeSurface);
m_Material.DisableKeyword(c_volumeModeFull);
break;
case VolumeMode.Full:
m_Material.EnableKeyword(c_volumeModeFull);
m_Material.DisableKeyword(c_volumeModeSurface);
break;
}
}

DoSlider("_RaymarchMinStep", "Min Step");

EditorGUI.indentLevel -= 1;
EditorGUILayout.Space();
}

void DoDebugPanel()
{
EditorGUI.indentLevel += 1;
DoTexture2D("_MainTex", "Font Atlas");
DoFloat("_GradientScale", "Gradient Scale");
DoFloat("_TextureWidth", "Texture Width");
DoFloat("_TextureHeight", "Texture Height");
EditorGUILayout.Space();
DoFloat("_ScaleX", "Scale X");
DoFloat("_ScaleY", "Scale Y");

DoSlider("_PerspectiveFilter", "Perspective Filter");
EditorGUILayout.Space();
DoFloat("_VertexOffsetX", "Offset X");
DoFloat("_VertexOffsetY", "Offset Y");

EditorGUILayout.Space();

EditorGUI.BeginDisabledGroup(true);
DoFloat("_ScaleRatioA", "Scale Ratio A");
DoFloat("_ScaleRatioB", "Scale Ratio B");
DoFloat("_ScaleRatioC", "Scale Ratio C");
EditorGUI.EndDisabledGroup();
EditorGUI.indentLevel -= 1;
EditorGUILayout.Space();
}
}
}
11 changes: 11 additions & 0 deletions Editor/Scripts/TMP3D_UnlitShaderGUI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a1ec6b

Please sign in to comment.