Skip to content

Commit

Permalink
Merge pull request #19 from cubedparadox/development
Browse files Browse the repository at this point in the history
Merge inspector changes from development into master.
  • Loading branch information
TCL987 authored Dec 10, 2017
2 parents 33ed123 + 1e6a824 commit 7c40be0
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 67 deletions.
156 changes: 89 additions & 67 deletions Assets/Cubed's Unity Shaders/Editor/FlatLitToonInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class FlatLitToonInspector : ShaderGUI
{

enum OutlineMode
public enum OutlineMode
{
None,
Tinted,
Expand All @@ -27,13 +27,13 @@ public enum BlendMode
MaterialProperty color;
MaterialProperty colorMask;
MaterialProperty shadow;
MaterialProperty outlineMode;
MaterialProperty outlineWidth;
MaterialProperty outlineColor;
MaterialProperty emissionMap;
MaterialProperty emissionColor;
MaterialProperty normalMap;
MaterialProperty alphaCutoff;
OutlineMode outlineMode = OutlineMode.Tinted;

public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
{
Expand All @@ -43,6 +43,7 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
color = FindProperty("_Color", props);
colorMask = FindProperty("_ColorMask", props);
shadow = FindProperty("_Shadow", props);
outlineMode = FindProperty("_OutlineMode", props);
outlineWidth = FindProperty("_outline_width", props);
outlineColor = FindProperty("_outline_color", props);
emissionMap = FindProperty("_EmissionMap", props);
Expand All @@ -59,57 +60,18 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
EditorGUI.BeginChangeCheck();
{
EditorGUI.showMixedValue = blendMode.hasMixedValue;
var mode = (BlendMode)blendMode.floatValue;
var bMode = (BlendMode)blendMode.floatValue;

EditorGUI.BeginChangeCheck();
mode = (BlendMode)EditorGUILayout.Popup("Rendering Mode", (int)mode, Enum.GetNames(typeof(BlendMode)));
bMode = (BlendMode)EditorGUILayout.Popup("Rendering Mode", (int)bMode, Enum.GetNames(typeof(BlendMode)));
if (EditorGUI.EndChangeCheck())
{
materialEditor.RegisterPropertyChangeUndo("Rendering Mode");
blendMode.floatValue = (float)mode;
blendMode.floatValue = (float)bMode;

switch ((BlendMode)material.GetFloat("_Mode"))
foreach (var obj in blendMode.targets)
{
case BlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = -1;
break;
case BlendMode.Cutout:
material.SetOverrideTag("RenderType", "TransparentCutout");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
break;
case BlendMode.Fade:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
case BlendMode.Transparent:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
SetupMaterialWithBlendMode((Material)obj, (BlendMode)material.GetFloat("_Mode"));
}
}

Expand All @@ -132,33 +94,23 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
EditorGUILayout.Space();
materialEditor.ShaderProperty(shadow, "Shadow");

var oMode = (OutlineMode)outlineMode.floatValue;

EditorGUI.BeginChangeCheck();
outlineMode = (OutlineMode)EditorGUILayout.EnumPopup("Outline", outlineMode);
oMode = (OutlineMode)EditorGUILayout.Popup("Outline Mode", (int)oMode, Enum.GetNames(typeof(OutlineMode)));

if (EditorGUI.EndChangeCheck())
{
switch (outlineMode)
materialEditor.RegisterPropertyChangeUndo("Outline Mode");
outlineMode.floatValue = (float)oMode;

foreach (var obj in outlineMode.targets)
{
case OutlineMode.None:
material.EnableKeyword("NO_OUTLINE");
material.DisableKeyword("TINTED_OUTLINE");
material.DisableKeyword("COLORED_OUTLINE");
break;
case OutlineMode.Tinted:
material.DisableKeyword("NO_OUTLINE");
material.EnableKeyword("TINTED_OUTLINE");
material.DisableKeyword("COLORED_OUTLINE");
break;
case OutlineMode.Colored:
material.DisableKeyword("NO_OUTLINE");
material.DisableKeyword("TINTED_OUTLINE");
material.EnableKeyword("COLORED_OUTLINE");
break;
default:
break;
SetupMaterialWithOutlineMode((Material)obj, (OutlineMode)material.GetFloat("_OutlineMode"));
}

}
switch (outlineMode)
switch (oMode)
{
case OutlineMode.Tinted:
case OutlineMode.Colored:
Expand All @@ -174,5 +126,75 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
}

}


public static void SetupMaterialWithBlendMode(Material material, BlendMode blendMode)
{
switch ((BlendMode)material.GetFloat("_Mode"))
{
case BlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = -1;
break;
case BlendMode.Cutout:
material.SetOverrideTag("RenderType", "TransparentCutout");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
break;
case BlendMode.Fade:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
case BlendMode.Transparent:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
}
}

public static void SetupMaterialWithOutlineMode(Material material, OutlineMode outlineMode)
{
switch ((OutlineMode)material.GetFloat("_OutlineMode"))
{
case OutlineMode.None:
material.EnableKeyword("NO_OUTLINE");
material.DisableKeyword("TINTED_OUTLINE");
material.DisableKeyword("COLORED_OUTLINE");
break;
case OutlineMode.Tinted:
material.DisableKeyword("NO_OUTLINE");
material.EnableKeyword("TINTED_OUTLINE");
material.DisableKeyword("COLORED_OUTLINE");
break;
case OutlineMode.Colored:
material.DisableKeyword("NO_OUTLINE");
material.DisableKeyword("TINTED_OUTLINE");
material.EnableKeyword("COLORED_OUTLINE");
break;
default:
break;
}
}
}
1 change: 1 addition & 0 deletions Assets/Cubed's Unity Shaders/Shaders/Flat Lit Toon.shader
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Shader "CubedParadox/Flat Lit Toon"

// Blending state
[HideInInspector] _Mode ("__mode", Float) = 0.0
[HideInInspector] _OutlineMode("__outline_mode", Float) = 0.0
[HideInInspector] _SrcBlend ("__src", Float) = 1.0
[HideInInspector] _DstBlend ("__dst", Float) = 0.0
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
Expand Down

0 comments on commit 7c40be0

Please sign in to comment.