Import art/VFX asset packs + game-feel systems; normalize texture extensions to lowercase for LFS
Add BefourStudios SciFi environment packs, Gabriel Aguiar VFX, and the ShaderCrew Toon Shader embedded packages, plus combat/enemy/wave/death gameplay systems and supporting vault docs/screenshots. Rename 11 vendor textures from uppercase .PNG/.HDR to lowercase so the case-sensitive Git LFS filters (*.png/*.hdr) match on case-sensitive filesystems (Linux CI, case-sensitive macOS), not just locally where core.ignorecase=true masks the gap. Each .meta moved with its asset so GUID references are preserved. All ~1000 binaries tracked via LFS. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e699416d0943b3b4583dd66e5cda09b6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,396 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public static class EditorUtils
|
||||
{
|
||||
public static void usualStart(string name)
|
||||
{
|
||||
LogoOnlyStart(name);
|
||||
|
||||
Rect rect = EditorGUILayout.BeginVertical();
|
||||
GUI.Box(rect, GUIContent.none);
|
||||
|
||||
}
|
||||
|
||||
public static void LogoOnlyStart(string name)
|
||||
{
|
||||
Rect screenRect = GUILayoutUtility.GetRect(1, 1);
|
||||
|
||||
Rect vertRect = EditorGUILayout.BeginVertical();
|
||||
|
||||
Color backgroundColor = new Color(0.4f, 0.4f, 0.4f);
|
||||
EditorGUI.DrawRect(new Rect(screenRect.x - 20, screenRect.y - 5, screenRect.width + 25, vertRect.height + 9), backgroundColor);
|
||||
|
||||
Sprite test = Resources.Load<Sprite>("logo-the-toon-shader-small");
|
||||
|
||||
GUIStyle headStyle = new GUIStyle();
|
||||
headStyle.normal.textColor = Color.white;
|
||||
headStyle.fontSize = 13;
|
||||
headStyle.alignment = TextAnchor.MiddleCenter;
|
||||
headStyle.fontStyle = FontStyle.Italic;
|
||||
|
||||
|
||||
//GUILayout.Label(Strings.THE_TOON_SHADER_TITLE, headStyle);
|
||||
//GUILayout.Label(Strings.SHADER_CREW_TITLE, headStyle);
|
||||
headStyle.fontStyle = FontStyle.Bold;
|
||||
headStyle.fontSize = 14;
|
||||
GUILayout.Label(name, headStyle);
|
||||
|
||||
if (test != null)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
//GUILayout.Label(test.texture, GUILayout.Width(250), GUILayout.Height(150));
|
||||
GUILayout.Label(test.texture, GUILayout.Width(300), GUILayout.Height(200));
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
//EditorGUILayout.Space(30);
|
||||
|
||||
}
|
||||
|
||||
public static bool LogoOnlyStartWithDescription(string name, string description, bool showDescription)
|
||||
{
|
||||
LogoOnlyStart(name);
|
||||
|
||||
if (description != null && description != "")
|
||||
{
|
||||
Rect rectt = EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUI.Box(rectt, GUIContent.none);
|
||||
string title = " Description:";
|
||||
|
||||
GUIStyle style = EditorStyles.foldout;
|
||||
FontStyle previousStyle = style.fontStyle;
|
||||
style.fontStyle = FontStyle.Bold;
|
||||
|
||||
showDescription = EditorGUILayout.Foldout(showDescription, title, style); //, EditorStyles.boldLabel);
|
||||
style.fontStyle = previousStyle;
|
||||
|
||||
|
||||
//showDescription = EditorGUILayout.Foldout(showDescription, title);
|
||||
if (showDescription)
|
||||
{
|
||||
GUIStyle textStyle = EditorStyles.label;
|
||||
textStyle.wordWrap = true;
|
||||
textStyle.richText = true;
|
||||
textStyle.fontStyle = FontStyle.Normal;
|
||||
GUILayout.Space(10);
|
||||
GUILayout.Label(description, textStyle);
|
||||
GUILayout.Space(10);
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorUtils.makeHorizontalSeparation();
|
||||
return showDescription;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static bool usualStartWithDescription(string name, string description, bool showDescription)
|
||||
{
|
||||
usualStart(name);
|
||||
if (description != null && description != "")
|
||||
{
|
||||
string title = " Description:";
|
||||
|
||||
GUIStyle style = EditorStyles.foldout;
|
||||
FontStyle previousStyle = style.fontStyle;
|
||||
style.fontStyle = FontStyle.Bold;
|
||||
|
||||
showDescription = EditorGUILayout.Foldout(showDescription, title, style); //, EditorStyles.boldLabel);
|
||||
style.fontStyle = previousStyle;
|
||||
|
||||
|
||||
//showDescription = EditorGUILayout.Foldout(showDescription, title);
|
||||
if (showDescription)
|
||||
{
|
||||
GUIStyle textStyle = EditorStyles.label;
|
||||
textStyle.wordWrap = true;
|
||||
textStyle.richText = true;
|
||||
textStyle.fontStyle = FontStyle.Normal;
|
||||
GUILayout.Space(10);
|
||||
GUILayout.Label(description, textStyle);
|
||||
GUILayout.Space(10);
|
||||
}
|
||||
return showDescription;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void usualEnd()
|
||||
{
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
public static void LogoOnlyEnd()
|
||||
{
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
|
||||
public static void Header(string title, GUIStyle style)
|
||||
{
|
||||
|
||||
Rect rectt = EditorGUILayout.BeginVertical();
|
||||
//rectt.y = rectt.y - 2f;
|
||||
//rectt.width = rectt.width + 6;
|
||||
//rectt.x = rectt.x - 3;
|
||||
rectt.width = rectt.width + 20;
|
||||
rectt.x = 0;
|
||||
//EditorUtils.DrawUILineFullWidth(Color.black, thickness: 1, padding: -3);
|
||||
|
||||
Color lightBlue = new Color(1.5f, 1.6f, 1.7f, 2);
|
||||
EditorUtils.DrawUILineBottom(rectt, new Color(0.25f, 0.25f, 0.25f, 1f));
|
||||
|
||||
|
||||
|
||||
var c = GUI.color;
|
||||
if (EditorGUIUtility.isProSkin)
|
||||
{
|
||||
GUI.color = new Color(0.5f, 1.5f, 2.5f, 1f);
|
||||
GUI.color = new Color(1.5f, 1.6f, 1.7f, 2);
|
||||
GUI.color = Color.black;
|
||||
GUI.color = new Color(0.5f, 1.5f, 2.5f, 1.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.color = new Color(0.5f, 0.7f, 0.9f, 1f);
|
||||
}
|
||||
|
||||
|
||||
Color myStyleColor = new Color(0.8f, 0.95f, 1f, 1f);// *0.9f;
|
||||
myStyleColor = Color.white;
|
||||
style.fontStyle = FontStyle.BoldAndItalic;
|
||||
style.fontSize = 14;
|
||||
|
||||
style.normal.textColor = myStyleColor;
|
||||
style.onNormal.textColor = myStyleColor;
|
||||
style.hover.textColor = myStyleColor;
|
||||
style.onHover.textColor = myStyleColor;
|
||||
style.focused.textColor = myStyleColor;
|
||||
style.onFocused.textColor = myStyleColor;
|
||||
style.active.textColor = myStyleColor;
|
||||
style.onActive.textColor = myStyleColor;
|
||||
|
||||
GUI.Box(rectt, GUIContent.none);
|
||||
GUI.color = c;
|
||||
GUILayout.Space(5);
|
||||
GUILayout.Label(title, style);
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
//Color color = Color.black;
|
||||
//Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(1));
|
||||
//r.y = r.y - 4f;
|
||||
//r.width = r.width + 6;
|
||||
//r.x = r.x - 3;
|
||||
//EditorGUI.DrawRect(r, color);
|
||||
|
||||
lightBlue = new Color(1.1f, 1.2f, 1.7f, 0.5f);
|
||||
EditorUtils.DrawUILineBottom(rectt, lightBlue, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void DrawUILine(int thickness = 1, int padding = 10)
|
||||
{
|
||||
Color color = Color.black;
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
public static void DrawUILineFull(int thickness = 1, int padding = 10)
|
||||
{
|
||||
Color color = Color.black;
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.width = Screen.width;
|
||||
r.x = 0;
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
public static void DrawUILineFull(Color color, int thickness = 1, int padding = 10)
|
||||
{
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.width = Screen.width;
|
||||
r.x = 0;
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
public static void DrawUILineGray(int thickness = 2, int padding = 10)
|
||||
{
|
||||
Color color = new Color(0.2f, 0.2f, 0.2f, 1);
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
public static void DrawUILineLightBlue(int thickness = 1, int padding = 0)
|
||||
{
|
||||
Color color = new Color(0.5f, 0.6f, 0.7f, 1);
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
public static void DrawUILineFullWidth(Color color, int thickness = 2, int padding = -1)
|
||||
{
|
||||
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.x = 0;
|
||||
r.width += 30;
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
public static void DrawUILine(Color color, int thickness = 2, int padding = -1)
|
||||
{
|
||||
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
public static void DrawUILineBottom(Rect rect, Color color, int thickness = 2, int padding = -1)
|
||||
{
|
||||
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
r.x = rect.x;
|
||||
r.width = rect.width;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
public static void DrawUILine(Rect rect, Color color, int thickness = 2, int padding = -1)
|
||||
{
|
||||
|
||||
Rect r = rect;
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
public static void DrawSubMenuSeparation()
|
||||
{
|
||||
//EditorGUILayout.Space();
|
||||
EditorUtils.DrawUILineSubMenu(1, -1, 10);
|
||||
EditorUtils.DrawUILineSubMenu(Color.gray, 1, 2, 10);
|
||||
}
|
||||
|
||||
public static void DrawSubMenuSeparation2()
|
||||
{
|
||||
//EditorGUILayout.Space();
|
||||
//Color color = new Color(0.28f, 0.28f, 0.28f, 1);
|
||||
//EditorUtils.DrawUILineSubMenu(color, 1, -2, 10);
|
||||
EditorUtils.DrawUILineSubMenu(4, -1, 0);
|
||||
EditorUtils.DrawUILineSubMenu(Color.gray, 1, 2, 0);
|
||||
}
|
||||
|
||||
public static void DrawUILineSubMenu(int thickness = 2, int padding = 1)
|
||||
{
|
||||
Color color = new Color(0.28f, 0.28f, 0.28f, 1);
|
||||
|
||||
|
||||
|
||||
DrawUILineSubMenu(color, thickness, padding);
|
||||
}
|
||||
|
||||
public static void DrawUILineSubMenu(int thickness = 2, int padding = 1, float margin = 20)
|
||||
{
|
||||
Color color = new Color(0.28f, 0.28f, 0.28f, 1);
|
||||
|
||||
|
||||
|
||||
DrawUILineSubMenu(color, thickness, padding, margin);
|
||||
}
|
||||
|
||||
public static void DrawUILineSubMenu(Color color, int thickness = 2, int padding = 1)
|
||||
{
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
//r.y += padding / 2;
|
||||
float marginLeft = 20;
|
||||
r.width = r.width - marginLeft;
|
||||
r.x += marginLeft;
|
||||
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
public static void DrawUILineSubMenu(Color color, int thickness = 2, int padding = 1, float margin = 20)
|
||||
{
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
//r.y += padding / 2;
|
||||
float marginLeft = margin;
|
||||
r.width = r.width - marginLeft;
|
||||
r.x += marginLeft;
|
||||
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
public static void DrawUILineCenter(Color color, int thickness = 2, int padding = 1)
|
||||
{
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
//r.y += padding / 2;
|
||||
float marginLeft = 20;
|
||||
r.width = r.width - marginLeft * 2;
|
||||
r.x += marginLeft;
|
||||
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
|
||||
public static void makeHorizontalSeparation(Color color)
|
||||
{
|
||||
GUIStyle horizontalLine;
|
||||
horizontalLine = new GUIStyle();
|
||||
horizontalLine.normal.background = EditorGUIUtility.whiteTexture;
|
||||
horizontalLine.margin = new RectOffset(0, 0, 4, 4);
|
||||
horizontalLine.fixedHeight = 10;
|
||||
|
||||
var c = GUI.color;
|
||||
GUI.color = color;
|
||||
GUILayout.Box(GUIContent.none, horizontalLine);
|
||||
GUI.color = c;
|
||||
}
|
||||
|
||||
public static void makeHorizontalSeparation()
|
||||
{
|
||||
makeHorizontalSeparation(new Color(0.4f, 0.4f, 0.4f));
|
||||
}
|
||||
|
||||
public static void DrawBox(Rect position, Color color)
|
||||
{
|
||||
Color oldColor = GUI.color;
|
||||
GUI.color = color;
|
||||
GUI.Box(position, GUIContent.none);
|
||||
GUI.color = oldColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2751e2e41ac5ec2468893425195204b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/Common/EditorUtils.cs
|
||||
uploadId: 919972
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public class GradientSO : ScriptableObject
|
||||
{
|
||||
[SerializeField]
|
||||
public Gradient gradient;
|
||||
|
||||
[SerializeField]
|
||||
public bool isBakedToTexture = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abb55f1f10b566340bf309a09598fc57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/Common/GradientSO.cs
|
||||
uploadId: 919972
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
|
||||
// Source: https://discussions.unity.com/t/how-to-get-shader-source-code-from-script/839046/5
|
||||
public static class ShaderGraphToShaderExporterUtil
|
||||
{
|
||||
private static object GetGraphData(string shaderAssetPath)
|
||||
{
|
||||
var importer = AssetImporter.GetAtPath(shaderAssetPath);
|
||||
|
||||
var textGraph = File.ReadAllText(importer.assetPath, Encoding.UTF8);
|
||||
var graphObjectType = Type.GetType("UnityEditor.Graphing.GraphObject, Unity.ShaderGraph.Editor")!;
|
||||
|
||||
// var graphObject = CreateInstance<GraphObject>();
|
||||
var graphObject = ScriptableObject.CreateInstance(graphObjectType);
|
||||
|
||||
graphObject.hideFlags = HideFlags.HideAndDontSave;
|
||||
bool isSubGraph;
|
||||
var extension = Path.GetExtension(importer.assetPath).Replace(".", "");
|
||||
switch (extension)
|
||||
{
|
||||
case "shadergraph":
|
||||
isSubGraph = false;
|
||||
break;
|
||||
case "ShaderGraph":
|
||||
isSubGraph = false;
|
||||
break;
|
||||
case "shadersubgraph":
|
||||
isSubGraph = true;
|
||||
break;
|
||||
default:
|
||||
throw new Exception($"Invalid file extension {extension}");
|
||||
}
|
||||
var assetGuid = AssetDatabase.AssetPathToGUID(importer.assetPath);
|
||||
|
||||
// graphObject.graph = new GraphData { assetGuid = assetGuid, isSubGraph = isSubGraph, messageManager = null };
|
||||
var graphObject_graphProperty = graphObjectType.GetProperty("graph")!;
|
||||
var graphDataType = Type.GetType("UnityEditor.ShaderGraph.GraphData, Unity.ShaderGraph.Editor")!;
|
||||
var graphDataInstance = Activator.CreateInstance(graphDataType);
|
||||
graphDataType.GetProperty("assetGuid")!.SetValue(graphDataInstance, assetGuid);
|
||||
graphDataType.GetProperty("isSubGraph")!.SetValue(graphDataInstance, isSubGraph);
|
||||
graphDataType.GetProperty("messageManager")!.SetValue(graphDataInstance, null);
|
||||
graphObject_graphProperty.SetValue(graphObject, graphDataInstance);
|
||||
|
||||
// MultiJson.Deserialize(graphObject.graph, textGraph);
|
||||
// = MultiJson.Deserialize<JsonObject>(graphObject.graph, textGraph, null, false);
|
||||
var multiJsonType = Type.GetType("UnityEditor.ShaderGraph.Serialization.MultiJson, Unity.ShaderGraph.Editor")!;
|
||||
var deserializeMethod = multiJsonType.GetMethod("Deserialize")!;
|
||||
var descrializeGenericMethod = deserializeMethod.MakeGenericMethod(graphDataType);
|
||||
descrializeGenericMethod.Invoke(null, new object[] { graphDataInstance, textGraph, null, false });
|
||||
|
||||
// graphObject.graph.OnEnable();
|
||||
graphDataType.GetMethod("OnEnable")!.Invoke(graphDataInstance, null);
|
||||
|
||||
// graphObject.graph.ValidateGraph();
|
||||
graphDataType.GetMethod("ValidateGraph")!.Invoke(graphDataInstance, null);
|
||||
|
||||
// return graphData.graph
|
||||
return graphDataInstance;
|
||||
}
|
||||
|
||||
public static string GenerateShaderCode(string shaderAssetPath, string shaderName = null)
|
||||
{
|
||||
Type generatorType =
|
||||
Type.GetType("UnityEditor.ShaderGraph.Generator, Unity.ShaderGraph.Editor")!;
|
||||
Type modeType =
|
||||
Type.GetType("UnityEditor.ShaderGraph.GenerationMode, Unity.ShaderGraph.Editor")!;
|
||||
|
||||
shaderName ??= Path.GetFileNameWithoutExtension(shaderAssetPath);
|
||||
|
||||
object graphData = GetGraphData(shaderAssetPath);
|
||||
|
||||
// new Generator(graphData, null, GenerationMode.ForReals, assetName, target:null, assetCollection:null, humanReadable: true);
|
||||
object forReals = ((FieldInfo)modeType.GetMember("ForReals")[0]).GetValue(null);
|
||||
object generator = Activator.CreateInstance(
|
||||
generatorType,
|
||||
new object[] { graphData, null, forReals, shaderName, null, null, true }
|
||||
);
|
||||
object shaderCode = generatorType
|
||||
.GetProperty("generatedShader", BindingFlags.Public | BindingFlags.Instance)!
|
||||
.GetValue(generator);
|
||||
|
||||
return (string)shaderCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5cda48d5367852448bb16514360fc9f
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/Common/ShaderGraphToShaderExporterUtil.cs
|
||||
uploadId: 919972
|
||||
+386
@@ -0,0 +1,386 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static ShaderCrew.TheToonShader.ShaderUtils;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public class TheToonShaderGenerator
|
||||
{
|
||||
|
||||
public TheToonShaderGenerator() { }
|
||||
|
||||
//public bool _USE_OPTIMIZATION_DEFINES;
|
||||
public bool _ENABLE_TOON_SHADING;
|
||||
|
||||
public int _LIGHT_SOURCE = -1;
|
||||
|
||||
public int _SHADING_FUNCTION;
|
||||
public bool _SHADING_TERMINATORPOSITION;
|
||||
public bool _ENABLE_SHADOWS;
|
||||
public bool _ENABLE_CAST_SHADOWS;
|
||||
|
||||
public bool _ENABLE_SPECULAR;
|
||||
public int _SPECULAR_BLENDING = -1;
|
||||
|
||||
public bool _ENABLE_RIM;
|
||||
public int _RIM_BLENDING = -1;
|
||||
|
||||
public bool _SUM_LIGHTS_BEFORE_POSTERIZATION;
|
||||
public bool _SHADING_USE_LIGHT_COLORS;
|
||||
public bool _SPECULAR_USE_LIGHT_COLORS;
|
||||
public bool _STYLING_SPECULAR_USE_LIGHT_COLORS;
|
||||
|
||||
|
||||
public bool _ENABLE_STYLING;
|
||||
|
||||
public int _STYLING_CASTSHADOWS_SYNC_WITH_OTHER_STYLING = -1;
|
||||
|
||||
public bool _ENABLE_STYLING_DISTANCEFADE;
|
||||
|
||||
public bool _ENABLE_SHADING_STYLING;
|
||||
public bool _SHADING_STYLING_TERMINATORPOSITION;
|
||||
public int _SHADING_STYLING_BLENDING = -1;
|
||||
public int _SHADING_STYLING_DRAWSPACE = -1;
|
||||
public int _SHADING_STYLING_UVSET = -1;
|
||||
public int _SHADING_STYLING_COORDINATESYSTEM = -1;
|
||||
public int _SHADING_STYLE = -1;
|
||||
public int _SHADING_STYLING_NUMBER_OF_CELLS_HATCHING = -1;
|
||||
public bool _SHADING_STYLING_RANDOMIZER;
|
||||
public bool _SHADING_STYLING_RANDOMIZER_PERLIN;
|
||||
public bool _SHADING_STYLING_RANDOMIZER_PERLIN_FLOORED;
|
||||
public bool _SHADING_STYLING_RANDOMIZER_WHITE;
|
||||
public bool _SHADING_STYLING_RANDOMIZER_WHITE_FLOORED;
|
||||
|
||||
public bool _SHADING_STYLING_ENABLE_DASHES;
|
||||
public int _SHADING_STYLING_DASHES_TYPE = -1;
|
||||
|
||||
|
||||
public bool _ENABLE_CASTSHADOWS_STYLING;
|
||||
public int _CASTSHADOWS_STYLING_BLENDING = -1;
|
||||
public int _CASTSHADOWS_STYLING_DRAWSPACE = -1;
|
||||
public int _CASTSHADOWS_STYLING_UVSET = -1;
|
||||
public int _CASTSHADOWS_STYLING_COORDINATESYSTEM = -1;
|
||||
public int _CASTSHADOWS_STYLE = -1;
|
||||
public int _CASTSHADOWS_STYLING_NUMBER_OF_CELLS_HATCHING = -1;
|
||||
public bool _CASTSHADOWS_STYLING_RANDOMIZER;
|
||||
public bool _CASTSHADOWS_STYLING_RANDOMIZER_PERLIN;
|
||||
public bool _CASTSHADOWS_STYLING_RANDOMIZER_PERLIN_FLOORED;
|
||||
public bool _CASTSHADOWS_STYLING_RANDOMIZER_WHITE;
|
||||
public bool _CASTSHADOWS_STYLING_RANDOMIZER_WHITE_FLOORED;
|
||||
|
||||
public bool _CASTSHADOWS_STYLING_ENABLE_DASHES;
|
||||
public int _CASTSHADOWS_STYLING_DASHES_TYPE = -1;
|
||||
|
||||
|
||||
public bool _ENABLE_SPECULAR_STYLING;
|
||||
public int _SPECULAR_STYLING_BLENDING = -1;
|
||||
public int _SPECULAR_STYLING_DRAWSPACE = -1;
|
||||
public int _SPECULAR_STYLING_UVSET = -1;
|
||||
public int _SPECULAR_STYLING_COORDINATESYSTEM = -1;
|
||||
public int _SPECULAR_STYLE = -1;
|
||||
public bool _SPECULAR_STYLING_RANDOMIZER;
|
||||
public bool _SPECULAR_STYLING_RANDOMIZER_PERLIN;
|
||||
public bool _SPECULAR_STYLING_RANDOMIZER_PERLIN_FLOORED;
|
||||
public bool _SPECULAR_STYLING_RANDOMIZER_WHITE;
|
||||
public bool _SPECULAR_STYLING_RANDOMIZER_WHITE_FLOORED;
|
||||
|
||||
public bool _SPECULAR_STYLING_ENABLE_DASHES;
|
||||
public int _SPECULAR_STYLING_DASHES_TYPE = -1;
|
||||
|
||||
public bool _ENABLE_RIM_STYLING;
|
||||
public int _RIM_STYLING_BLENDING = -1;
|
||||
public int _RIM_STYLING_DRAWSPACE = -1;
|
||||
public int _RIM_STYLING_UVSET = -1;
|
||||
public int _RIM_STYLING_COORDINATESYSTEM = -1;
|
||||
public int _RIM_STYLE = -1;
|
||||
public bool _RIM_STYLING_RANDOMIZER;
|
||||
public bool _RIM_STYLING_RANDOMIZER_PERLIN;
|
||||
public bool _RIM_STYLING_RANDOMIZER_PERLIN_FLOORED;
|
||||
public bool _RIM_STYLING_RANDOMIZER_WHITE;
|
||||
public bool _RIM_STYLING_RANDOMIZER_WHITE_FLOORED;
|
||||
|
||||
public bool _RIM_STYLING_ENABLE_DASHES;
|
||||
public int _RIM_STYLING_DASHES_TYPE = -1;
|
||||
|
||||
|
||||
#if USING_URP2D
|
||||
public int _MAX_LIGHT_COUNT = -1;
|
||||
public int _CELL_METHOD = -1;
|
||||
public bool _ENABLE_MAINTEX_POSTERIZATION;
|
||||
|
||||
public bool _EMISSION;
|
||||
public bool _NORMALMAP;
|
||||
|
||||
public bool _USE_MAINTEX;
|
||||
public bool _CONVERT_NORMAL_TO_ALBEDO;
|
||||
|
||||
public bool _USE_CORE_SHADOW_COLOR;
|
||||
public bool _ENABLE_LIGHT_PARTITIONING;
|
||||
public int _ROUND_METHOD = -1;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
public bool _ENABLE_OUTLINE;
|
||||
|
||||
|
||||
public static bool CheckIfShaderIsAlreadyOptimized(Material material)
|
||||
{
|
||||
if (material != null && material.shader != null)
|
||||
{
|
||||
string dataPathWithoutAssets = Application.dataPath;
|
||||
if (dataPathWithoutAssets.EndsWith("/Assets"))
|
||||
{
|
||||
dataPathWithoutAssets = dataPathWithoutAssets.Substring(0, dataPathWithoutAssets.LastIndexOf("/Assets"));
|
||||
}
|
||||
string realPath = null;
|
||||
|
||||
string shaderAssetPath = UnityEditor.AssetDatabase.GetAssetPath(material.shader);
|
||||
string fileName = Path.GetFileName(shaderAssetPath);
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(shaderAssetPath);
|
||||
string extension = Path.GetExtension(shaderAssetPath);
|
||||
|
||||
if (fileName != null && !fileName.Equals("") && extension != null && extension.Equals(".shader"))
|
||||
{
|
||||
realPath = dataPathWithoutAssets + "/" + shaderAssetPath;
|
||||
}
|
||||
|
||||
//if (material.shader.name == "Dev/TheToonShaderDev")
|
||||
//{
|
||||
// realPath = dataPathWithoutAssets + "/Packages/com.shadercrew.the-toon-shader.core/Scripts/Shaders/Native/URP/TheToonShader_URP2020.shader";
|
||||
//}
|
||||
//else // remove in final
|
||||
//{
|
||||
// Debug.Log("Remove me in final");
|
||||
// return false;
|
||||
//}
|
||||
|
||||
|
||||
//Debug.Log(realPath);
|
||||
|
||||
string fileContent = File.ReadAllText(realPath);
|
||||
//Debug.Log(fileContent);
|
||||
|
||||
//string pattern = @"\b#define\s+_USE_OPTIMIZATION_DEFINES\s+1\b";
|
||||
string pattern = @"#\bdefine\s+_USE_OPTIMIZATION_DEFINES\s+1\b";
|
||||
Regex regex = new Regex(pattern);
|
||||
|
||||
bool lineFound = regex.IsMatch(fileContent);
|
||||
|
||||
|
||||
return lineFound;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static bool CheckIfShaderIsAlreadyOptimizedPropertyBased(Material material)
|
||||
{
|
||||
if (material != null && material.shader != null)
|
||||
{
|
||||
return material.HasProperty("_IsOptimized");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Shader GenerateOptimizedShaderFile(Material material) // return generated shader
|
||||
{
|
||||
if(material != null && material.shader != null)
|
||||
{
|
||||
|
||||
RenderPipelineOptions rp = getCurrentRenderPipeline();
|
||||
|
||||
|
||||
string shaderAssetPath = UnityEditor.AssetDatabase.GetAssetPath(material.shader);
|
||||
string fileName = Path.GetFileName(shaderAssetPath);
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(shaderAssetPath);
|
||||
string extension = Path.GetExtension(shaderAssetPath);
|
||||
|
||||
|
||||
string dataPathWithoutAssets = Application.dataPath;
|
||||
if (dataPathWithoutAssets.EndsWith("/Assets"))
|
||||
{
|
||||
dataPathWithoutAssets = dataPathWithoutAssets.Substring(0, dataPathWithoutAssets.LastIndexOf("/Assets"));
|
||||
}
|
||||
|
||||
string realPath = null;
|
||||
|
||||
|
||||
if (fileName != null && !fileName.Equals("") && extension != null && (extension.Equals(".shader") || extension.Equals(".shadergraph")))
|
||||
{
|
||||
realPath = dataPathWithoutAssets + "/" + shaderAssetPath;
|
||||
}
|
||||
|
||||
|
||||
////cause debug:
|
||||
|
||||
////realPath = dataPathWithoutAssets + "/Packages/com.shadercrew.the-toon-shader.core/Scripts/Shaders/Native/URP/TheToonShader_URP2020.shader";
|
||||
//if(material.shader.name == "Dev/TheToonShaderDev")
|
||||
//{
|
||||
// realPath = dataPathWithoutAssets + "/Packages/com.shadercrew.the-toon-shader.core/Scripts/Shaders/Native/URP/TheToonShader_URP2020.shader";
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
if (realPath != null && !realPath.Equals(""))
|
||||
{
|
||||
string content = null;
|
||||
|
||||
if (rp == RenderPipelineOptions.URP2D)
|
||||
{
|
||||
content = ShaderGraphToShaderExporterUtil.GenerateShaderCode(shaderAssetPath, fileNameWithoutExtension);
|
||||
}
|
||||
else
|
||||
{
|
||||
content = File.ReadAllText(realPath);
|
||||
}
|
||||
string optimizedShaderName = "";
|
||||
|
||||
//string patternShaderName = @"Shader\s*""([^""]+)""";
|
||||
//string patternShaderName = @"(\r\n|\r|\n)\s*Shader\s*""([^""]+)""";
|
||||
//Regex regex = new Regex(patternShaderName);
|
||||
Regex regex = new Regex(@"^\s*Shader\s*""([^""]+)""", RegexOptions.Multiline);
|
||||
|
||||
Match matchShaderName = regex.Match(content);
|
||||
if (matchShaderName.Success)
|
||||
{
|
||||
string shaderName = matchShaderName.Groups[1].Value;
|
||||
string modifiedShaderName = shaderName + "_" + material.name + "_Optimized";
|
||||
|
||||
optimizedShaderName = modifiedShaderName;
|
||||
//Debug.Log("optimizedShaderName: " + optimizedShaderName);
|
||||
List<string> parts = optimizedShaderName.Split('/').ToList();
|
||||
parts.Insert(1, "Optimized");
|
||||
optimizedShaderName = string.Join("/", parts);
|
||||
|
||||
content = regex.Replace(content, matchShaderName.Value.Replace(shaderName, optimizedShaderName));
|
||||
|
||||
}
|
||||
|
||||
string patternProperties = @"Properties\s*\{\s*";
|
||||
Match matchProperties = Regex.Match(content, patternProperties);
|
||||
|
||||
if (matchProperties.Success)
|
||||
{
|
||||
int insertPosition = matchProperties.Index + matchProperties.Length;
|
||||
|
||||
content = content.Insert(insertPosition, "[HideInInspector] _IsOptimized(\"_IsOptimized\", Float) = 1.0" + "\n");
|
||||
}
|
||||
|
||||
string pattern = @"SubShader\s*\{\s*";
|
||||
|
||||
Match match = Regex.Match(content, pattern);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
int insertPosition = match.Index + match.Length;
|
||||
|
||||
StringBuilder defineDefinitions = new StringBuilder(2000);
|
||||
|
||||
if (rp == RenderPipelineOptions.BiRP)
|
||||
{
|
||||
defineDefinitions.AppendLine("\tCGINCLUDE");
|
||||
}
|
||||
else
|
||||
{
|
||||
defineDefinitions.AppendLine("\tHLSLINCLUDE");
|
||||
}
|
||||
|
||||
defineDefinitions.AppendLine("\t\t#define _USE_OPTIMIZATION_DEFINES 1");
|
||||
|
||||
Type type = this.GetType();
|
||||
FieldInfo[] properties = type.GetFields();
|
||||
|
||||
foreach (FieldInfo property in properties)
|
||||
{
|
||||
//if(!property.Name.Equals("_ENABLE_OUTLINE"))
|
||||
//{
|
||||
|
||||
if (property.GetValue(this).GetType() == typeof(bool))
|
||||
{
|
||||
//Debug.Log("name: " + property.Name + " - " + (bool)property.GetValue(this));
|
||||
if ((bool)property.GetValue(this) == true)
|
||||
{
|
||||
defineDefinitions.AppendLine("\t\t#define " + property.Name + " 1");
|
||||
}
|
||||
}
|
||||
else if (property.GetValue(this).GetType() == typeof(int))
|
||||
{
|
||||
if ((int)property.GetValue(this) != -1)
|
||||
{
|
||||
defineDefinitions.AppendLine("\t\t#define " + property.Name + " " + (int)property.GetValue(this));
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (rp == RenderPipelineOptions.BiRP)
|
||||
{
|
||||
defineDefinitions.AppendLine("\tENDCG");
|
||||
}
|
||||
else
|
||||
{
|
||||
defineDefinitions.AppendLine("\tENDHLSL");
|
||||
}
|
||||
|
||||
string modifiedContent = content.Insert(insertPosition, "\n" + defineDefinitions.ToString() + "\n");
|
||||
|
||||
|
||||
//if (_ENABLE_OUTLINE == false)
|
||||
//{
|
||||
// string outlinePassPattern = @"Pass\s*\{\s*Name\s*""Outline""[\s\S]*?ENDCG[\s\S]*?\}";
|
||||
// modifiedContent = Regex.Replace(modifiedContent, outlinePassPattern, "", RegexOptions.Singleline);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//string filePathModfied = Application.dataPath + "/ToonShaderBuilder/ShaderCreatorTest/ShaderCreatorPlain_URP2020Optimized.shader";
|
||||
|
||||
string filePathModfied;
|
||||
|
||||
if (rp == RenderPipelineOptions.URP2D && material.HasProperty(TheToonShaderConstants.THETOONSHADER2D_IDENTIFIER_PROPERTY))
|
||||
{
|
||||
filePathModfied = dataPathWithoutAssets + "/Packages/com.shadercrew.the-toon-shader.2d/Scripts/Resources/OptimizedShaders/";
|
||||
}
|
||||
else
|
||||
{
|
||||
filePathModfied = dataPathWithoutAssets + "/Packages/com.shadercrew.the-toon-shader.3d/Scripts/Resources/OptimizedShaders/";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(filePathModfied))
|
||||
{
|
||||
Directory.CreateDirectory(filePathModfied);
|
||||
}
|
||||
|
||||
filePathModfied += fileNameWithoutExtension + "_" + material.name + "_Optimized";
|
||||
filePathModfied += ".shader";
|
||||
|
||||
File.WriteAllText(filePathModfied, modifiedContent);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
Shader optimizedShader = Shader.Find(optimizedShaderName);
|
||||
//Debug.Log(optimizedShaderName);
|
||||
return optimizedShader;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4ccf604a3bf34b4982530526b1d037a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/Common/TheToonShaderGenerator.cs
|
||||
uploadId: 919972
|
||||
+1312
File diff suppressed because it is too large
Load Diff
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf2c77cd8430cac489c071ca03240422
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/Common/ToonEditorUtils.cs
|
||||
uploadId: 919972
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c477a66f7a67ad4c82a60786cea2a4c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/Resources/logo-the-toon-shader-small.png
LFS
BIN
Binary file not shown.
+134
@@ -0,0 +1,134 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74b696f19defb14429d09ca2ccaed00e
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 13
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
flipGreenChannel: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMipmapLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 0
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
swizzle: 50462976
|
||||
cookieLightType: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 512
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: 5e97eb03825dee720800000000000000
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/Resources/logo-the-toon-shader-small.png
|
||||
uploadId: 919972
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"name": "ShaderCrew.TheToonShader.Core.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:78bd2ddd6e276394a9615c203e574844",
|
||||
"GUID:3eae0364be2026648bf74846acb8a731",
|
||||
"GUID:be0903cd8e1546f498710afdc59db5eb",
|
||||
"GUID:457756d89b35d2941b3e7b37b4ece6f1",
|
||||
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
|
||||
"GUID:c579267770062bf448e75eb160330b7f",
|
||||
"GUID:83e2004185752be4684414733d22e0e7",
|
||||
"GUID:6a37219044b169f4fa7e60a15e3e8279",
|
||||
"GUID:7072132f216016e47a05cb60e25c2c9b",
|
||||
"GUID:516a5277b8c3b4f4c8cc86b77b1591ff",
|
||||
"GUID:1e1df38bdb063c04fb8d144480b35d37"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.render-pipelines.universal",
|
||||
"expression": "",
|
||||
"define": "USING_URP"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.high-definition",
|
||||
"expression": "",
|
||||
"define": "USING_HDRP"
|
||||
},
|
||||
{
|
||||
"name": "com.shadercrew.seethroughshader.core",
|
||||
"expression": "",
|
||||
"define": "USING_SEE_THROUGH_SHADER"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.2d.sprite",
|
||||
"expression": "",
|
||||
"define": "USING_URP2D"
|
||||
},
|
||||
{
|
||||
"name": "com.shadercrew.the-toon-shader.2d",
|
||||
"expression": "",
|
||||
"define": "USING_TOON2D"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 771e886dc8ff2624f9fb1e98ab52afc2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderCrew.TheToonShader.Core.Editor.asmdef
|
||||
uploadId: 919972
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6319f07d59873194cb4548a0d67da792
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+389
@@ -0,0 +1,389 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static ShaderCrew.TheToonShader.TheToonShaderGUIEditor;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public class BiRPLightingGUI
|
||||
{
|
||||
public MaterialEditor m_MaterialEditor;
|
||||
|
||||
public Color textColor;
|
||||
Color originalColor;
|
||||
|
||||
public enum BlendMode
|
||||
{
|
||||
Opaque,
|
||||
Cutout,
|
||||
//Transparent
|
||||
}
|
||||
public enum AlphaModes
|
||||
{
|
||||
Opaque,
|
||||
Blend,
|
||||
Add,
|
||||
PreMultiply
|
||||
}
|
||||
|
||||
public enum SmoothnessMapChannel
|
||||
{
|
||||
SpecularMetallicAlpha,
|
||||
AlbedoAlpha,
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Standard
|
||||
public MaterialProperty blendMode = null;
|
||||
public MaterialProperty cullMode = null;
|
||||
|
||||
public MaterialProperty albedoMap = null;
|
||||
public MaterialProperty albedoColor = null;
|
||||
public MaterialProperty alphaCutoff = null;
|
||||
public MaterialProperty metallic = null;
|
||||
public MaterialProperty metallicMap = null;
|
||||
|
||||
public MaterialProperty smoothness = null;
|
||||
public MaterialProperty smoothnessScale = null;
|
||||
public MaterialProperty smoothnessMapChannel = null;
|
||||
|
||||
public MaterialProperty bumpScale = null;
|
||||
public MaterialProperty bumpMap = null;
|
||||
|
||||
public MaterialProperty emissionMap = null;
|
||||
public MaterialProperty emissionColor = null;
|
||||
|
||||
public MaterialProperty occlusionMap = null;
|
||||
public MaterialProperty occlusionStrength = null;
|
||||
|
||||
public MaterialProperty heigtMapScale = null;
|
||||
public MaterialProperty heightMap = null;
|
||||
|
||||
public MaterialProperty detailMask = null;
|
||||
public MaterialProperty detailAlbedoMap = null;
|
||||
public MaterialProperty detailNormalMap = null;
|
||||
public MaterialProperty detailNormalMapScale = null;
|
||||
|
||||
|
||||
public MaterialProperty uvSetSecondary = null;
|
||||
|
||||
|
||||
|
||||
private static class StandardLitStyles
|
||||
{
|
||||
// Standard
|
||||
public static GUIContent albedoText = EditorGUIUtility.TrTextContent("Albedo", "Albedo (RGB) and Transparency (A)");
|
||||
public static GUIContent alphaCutoffText = EditorGUIUtility.TrTextContent("Alpha Cutoff", "Threshold for alpha cutoff");
|
||||
public static GUIContent metallicMapText = EditorGUIUtility.TrTextContent("Metallic", "Metallic (R) and Smoothness (A)");
|
||||
|
||||
public static GUIContent smoothnessText = EditorGUIUtility.TrTextContent("Smoothness", "Smoothness value");
|
||||
public static GUIContent smoothnessScaleText = EditorGUIUtility.TrTextContent("Smoothness", "Smoothness scale factor");
|
||||
public static GUIContent smoothnessMapChannelText = EditorGUIUtility.TrTextContent("Source", "Smoothness texture and channel");
|
||||
|
||||
public static GUIContent normalMapText = EditorGUIUtility.TrTextContent("Normal Map", "Normal Map");
|
||||
|
||||
public static GUIContent heightMapText = EditorGUIUtility.TrTextContent("Height Map", "Height Map (G)");
|
||||
|
||||
public static GUIContent emissionText = EditorGUIUtility.TrTextContent("Emission", "Emission (RGB)");
|
||||
public static GUIContent occlusionMapText = EditorGUIUtility.TrTextContent("Occlusion", "Occlusion (G)");
|
||||
|
||||
public static GUIContent detailMaskText = EditorGUIUtility.TrTextContent("Detail Mask", "Mask for Secondary Maps (A)");
|
||||
public static GUIContent detailAlbedoText = EditorGUIUtility.TrTextContent("Detail Albedo x2", "Albedo (RGB) multiplied by 2");
|
||||
public static GUIContent detailNormalMapText = EditorGUIUtility.TrTextContent("Normal Map", "Normal Map");
|
||||
public static GUIContent uvSetLabel = EditorGUIUtility.TrTextContent("UV Set");
|
||||
|
||||
|
||||
public static string secondaryMapsText = "Secondary Maps";
|
||||
public static string advancedText = "Advanced Options";
|
||||
public static string renderingMode = "Rendering Mode";
|
||||
|
||||
public static readonly string[] blendNames = System.Enum.GetNames(typeof(BlendMode));
|
||||
|
||||
}
|
||||
|
||||
public void DoSetup(MaterialEditor materialEditor)
|
||||
{
|
||||
m_MaterialEditor = materialEditor;
|
||||
MaterialChanged(materialEditor.target as Material);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void DrawUILine(int thickness = 1, int padding = 10)
|
||||
{
|
||||
Color color = Color.black;
|
||||
Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
|
||||
r.height = thickness;
|
||||
r.y += padding / 2;
|
||||
EditorGUI.DrawRect(r, color);
|
||||
}
|
||||
|
||||
public void BiRPShaderPropertiesGUI(Material material, GeneralShadingMode shadingMode, LightFunction lightFunction)
|
||||
{
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
{
|
||||
BlendModePopup();
|
||||
m_MaterialEditor.ShaderProperty(cullMode, "Cull Mode");
|
||||
|
||||
DoAlbedoArea(material);
|
||||
if(shadingMode == GeneralShadingMode.LightBased)
|
||||
{
|
||||
DoSpecularMetallicArea(material);
|
||||
}
|
||||
|
||||
DoNormalArea();
|
||||
|
||||
if (shadingMode == GeneralShadingMode.LightBased)
|
||||
{
|
||||
DoHeightMapArea();
|
||||
DoOcclusionArea();
|
||||
DoDetailMaskArea();
|
||||
}
|
||||
DoEmissionArea();
|
||||
|
||||
bool shouldEmissionBeEnabled = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0;
|
||||
|
||||
bool showTextureScaleOffset = (albedoMap.textureValue != null ||
|
||||
bumpMap.textureValue != null ||
|
||||
(emissionMap.textureValue != null && shouldEmissionBeEnabled));
|
||||
|
||||
if (shadingMode == GeneralShadingMode.LightBased)
|
||||
{
|
||||
showTextureScaleOffset = showTextureScaleOffset || occlusionMap.textureValue != null ||
|
||||
heightMap.textureValue != null ||
|
||||
metallicMap.textureValue != null ||
|
||||
detailMask.textureValue != null; }
|
||||
|
||||
if (showTextureScaleOffset)
|
||||
{
|
||||
EditorGUI.indentLevel += 2;
|
||||
m_MaterialEditor.TextureScaleOffsetProperty(albedoMap);
|
||||
EditorGUI.indentLevel -= 2;
|
||||
}
|
||||
if (shadingMode == GeneralShadingMode.LightBased)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
DoSecondaryArea();
|
||||
}
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
//MaterialChanged(material);
|
||||
foreach (var obj in blendMode.targets)
|
||||
MaterialChanged((Material)obj);
|
||||
}
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void OnlyBlendModeAndCullModeGUI()
|
||||
{
|
||||
BlendModePopup();
|
||||
m_MaterialEditor.ShaderProperty(cullMode, "Cull Mode");
|
||||
}
|
||||
|
||||
public void OnlyCullModeGUI()
|
||||
{
|
||||
m_MaterialEditor.ShaderProperty(cullMode, "Cull Mode");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BlendModePopup()
|
||||
{
|
||||
EditorGUI.showMixedValue = blendMode.hasMixedValue;
|
||||
var mode = (BlendMode)blendMode.floatValue;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
mode = (BlendMode)EditorGUILayout.Popup(StandardLitStyles.renderingMode, (int)mode, StandardLitStyles.blendNames);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
m_MaterialEditor.RegisterPropertyChangeUndo("Rendering Mode");
|
||||
blendMode.floatValue = (float)mode;
|
||||
}
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
|
||||
static void MaterialChanged(Material material)
|
||||
{
|
||||
SetMaterialKeywords(material);
|
||||
}
|
||||
|
||||
static void SetMaterialKeywords(Material material)
|
||||
{
|
||||
SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap") || material.GetTexture("_DetailNormalMap"));
|
||||
SetKeyword(material, "_METALLICGLOSSMAP", material.GetTexture("_MetallicGlossMap"));
|
||||
SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap"));
|
||||
SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap"));
|
||||
|
||||
MaterialEditor.FixupEmissiveFlag(material);
|
||||
bool shouldEmissionBeEnabled = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0;
|
||||
SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled);
|
||||
if (material.HasProperty("_SmoothnessTextureChannel"))
|
||||
{
|
||||
SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", GetSmoothnessMapChannel(material) == SmoothnessMapChannel.AlbedoAlpha);
|
||||
}
|
||||
|
||||
}
|
||||
static void SetKeyword(Material m, string keyword, bool state)
|
||||
{
|
||||
if (state)
|
||||
m.EnableKeyword(keyword);
|
||||
else
|
||||
m.DisableKeyword(keyword);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void DoAlbedoArea(Material material)
|
||||
{
|
||||
float oriLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = EditorGUIUtility.currentViewWidth - 94;
|
||||
m_MaterialEditor.TexturePropertySingleLine(StandardLitStyles.albedoText, albedoMap, albedoColor);
|
||||
EditorGUIUtility.labelWidth = oriLabelWidth;
|
||||
|
||||
if (((BlendMode)material.GetFloat("_Mode") == BlendMode.Cutout))
|
||||
{
|
||||
m_MaterialEditor.ShaderProperty(alphaCutoff, StandardLitStyles.alphaCutoffText.text, MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DoDetailMaskArea()
|
||||
{
|
||||
m_MaterialEditor.TexturePropertySingleLine(StandardLitStyles.detailMaskText, detailMask);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DoSecondaryArea()
|
||||
{
|
||||
GUILayout.Label(StandardLitStyles.secondaryMapsText, EditorStyles.boldLabel);
|
||||
m_MaterialEditor.TexturePropertySingleLine(StandardLitStyles.detailAlbedoText, detailAlbedoMap);
|
||||
m_MaterialEditor.TexturePropertySingleLine(StandardLitStyles.detailNormalMapText, detailNormalMap, detailNormalMapScale);
|
||||
m_MaterialEditor.TextureScaleOffsetProperty(detailAlbedoMap);
|
||||
m_MaterialEditor.ShaderProperty(uvSetSecondary, StandardLitStyles.uvSetLabel.text);
|
||||
|
||||
}
|
||||
|
||||
void DoNormalArea()
|
||||
{
|
||||
m_MaterialEditor.TexturePropertySingleLine(StandardLitStyles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpScale : null);
|
||||
}
|
||||
|
||||
void DoHeightMapArea()
|
||||
{
|
||||
m_MaterialEditor.TexturePropertySingleLine(StandardLitStyles.heightMapText, heightMap, heightMap.textureValue != null ? heigtMapScale : null);
|
||||
}
|
||||
void DoSpecularMetallicArea(Material material)
|
||||
{
|
||||
bool hasGlossMap = metallicMap.textureValue != null;
|
||||
m_MaterialEditor.TexturePropertySingleLine(StandardLitStyles.metallicMapText, metallicMap, hasGlossMap ? null : metallic);
|
||||
|
||||
bool showSmoothnessScale = hasGlossMap;
|
||||
if (smoothnessMapChannel != null)
|
||||
{
|
||||
int smoothnessChannel = (int)smoothnessMapChannel.floatValue;
|
||||
if (smoothnessChannel == (int)SmoothnessMapChannel.AlbedoAlpha)
|
||||
showSmoothnessScale = true;
|
||||
}
|
||||
|
||||
int indentation = 2;
|
||||
m_MaterialEditor.ShaderProperty(showSmoothnessScale ? smoothnessScale : smoothness, showSmoothnessScale ? StandardLitStyles.smoothnessScaleText : StandardLitStyles.smoothnessText, indentation);
|
||||
|
||||
++indentation;
|
||||
if (smoothnessMapChannel != null)
|
||||
m_MaterialEditor.ShaderProperty(smoothnessMapChannel, StandardLitStyles.smoothnessMapChannelText, indentation);
|
||||
}
|
||||
|
||||
|
||||
void DoOcclusionArea()
|
||||
{
|
||||
m_MaterialEditor.TexturePropertySingleLine(StandardLitStyles.occlusionMapText, occlusionMap, occlusionMap.textureValue != null ? occlusionStrength : null);
|
||||
}
|
||||
|
||||
|
||||
void DoEmissionArea()
|
||||
{
|
||||
if (m_MaterialEditor.EmissionEnabledProperty())
|
||||
{
|
||||
bool hadEmissionTexture = emissionMap.textureValue != null;
|
||||
|
||||
m_MaterialEditor.TexturePropertyWithHDRColor(StandardLitStyles.emissionText, emissionMap, emissionColor, false);
|
||||
|
||||
float brightness = emissionColor.colorValue.maxColorComponent;
|
||||
if (emissionMap.textureValue != null && !hadEmissionTexture && brightness <= 0f)
|
||||
{
|
||||
emissionColor.colorValue = Color.white;
|
||||
}
|
||||
|
||||
m_MaterialEditor.LightmapEmissionFlagsProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static SmoothnessMapChannel GetSmoothnessMapChannel(Material material)
|
||||
{
|
||||
int ch = (int)material.GetFloat("_SmoothnessTextureChannel");
|
||||
if (ch == (int)SmoothnessMapChannel.AlbedoAlpha)
|
||||
return SmoothnessMapChannel.AlbedoAlpha;
|
||||
else
|
||||
return SmoothnessMapChannel.SpecularMetallicAlpha;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void SetupMaterialWithBlendMode(Material material, BlendMode blendMode)
|
||||
{
|
||||
//switch (blendMode)
|
||||
//{
|
||||
// case BlendMode.Opaque:
|
||||
// material.SetFloat("_AlphaMode", (float)AlphaModes.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.renderQueue = -1;
|
||||
// //material.SetColor("_Color", Color.green);
|
||||
// break;
|
||||
// case BlendMode.Cutout:
|
||||
// material.SetFloat("_AlphaMode", (float)AlphaModes.Opaque);
|
||||
// //material.SetInt("_ZWrite", 1);
|
||||
// //material.EnableKeyword("_ALPHATEST_ON");
|
||||
// //material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
|
||||
// break;
|
||||
// case BlendMode.Transparent:
|
||||
// material.SetOverrideTag("RenderType", "Transparent");
|
||||
// material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
|
||||
// //material.SetColor("_Color", Color.blue);
|
||||
// material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
||||
// material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
// material.SetInt("_ZWrite", 0);
|
||||
// //material.SetFloat("_AlphaMode", (float)AlphaModes.Blend);
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 366dd6a816be8c040862fa3ea7bddc58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderGUI/BiRPLightingGUI.cs
|
||||
uploadId: 919972
|
||||
+7810
File diff suppressed because it is too large
Load Diff
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33247f247717cf14684dd2a4377df685
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderGUI/TheToonShaderGUIEditor.cs
|
||||
uploadId: 919972
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef2bd3b8659ddf74a8dd8083161ff076
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 123d9432966facc47b882fba28ad7595
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+628
@@ -0,0 +1,628 @@
|
||||
//SEE: https://github.com/Unity-Technologies/Graphics/blob/v10.10.1/com.unity.render-pipelines.universal/Editor/ShaderGUI/BaseShaderGUI.cs
|
||||
|
||||
#if !UNITY_2021_1_OR_NEWER
|
||||
#if USING_URP
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEditor.Rendering.Universal;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public abstract class BaseShaderGUI : ShaderGUI
|
||||
{
|
||||
#region EnumsAndClasses
|
||||
|
||||
public enum SurfaceType
|
||||
{
|
||||
Opaque,
|
||||
Transparent
|
||||
}
|
||||
|
||||
public enum BlendMode
|
||||
{
|
||||
Alpha, // Old school alpha-blending mode, fresnel does not affect amount of transparency
|
||||
Premultiply, // Physically plausible transparency mode, implemented as alpha pre-multiply
|
||||
Additive,
|
||||
Multiply
|
||||
}
|
||||
|
||||
public enum SmoothnessSource
|
||||
{
|
||||
BaseAlpha,
|
||||
SpecularAlpha
|
||||
}
|
||||
|
||||
public enum RenderFace
|
||||
{
|
||||
Front = 2,
|
||||
Back = 1,
|
||||
Both = 0
|
||||
}
|
||||
|
||||
protected class Styles
|
||||
{
|
||||
// Catergories
|
||||
public static readonly GUIContent SurfaceOptions =
|
||||
new GUIContent("Surface Options", "Controls how Universal RP renders the Material on a screen.");
|
||||
|
||||
public static readonly GUIContent SurfaceInputs = new GUIContent("Surface Inputs",
|
||||
"These settings describe the look and feel of the surface itself.");
|
||||
|
||||
public static readonly GUIContent AdvancedLabel = new GUIContent("Advanced",
|
||||
"These settings affect behind-the-scenes rendering and underlying calculations.");
|
||||
|
||||
public static readonly GUIContent surfaceType = new GUIContent("Surface Type",
|
||||
"Select a surface type for your texture. Choose between Opaque or Transparent.");
|
||||
|
||||
public static readonly GUIContent blendingMode = new GUIContent("Blending Mode",
|
||||
"Controls how the color of the Transparent surface blends with the Material color in the background.");
|
||||
|
||||
public static readonly GUIContent cullingText = new GUIContent("Render Face",
|
||||
"Specifies which faces to cull from your geometry. Front culls front faces. Back culls backfaces. None means that both sides are rendered.");
|
||||
|
||||
public static readonly GUIContent alphaClipText = new GUIContent("Alpha Clipping",
|
||||
"Makes your Material act like a Cutout shader. Use this to create a transparent effect with hard edges between opaque and transparent areas.");
|
||||
|
||||
public static readonly GUIContent alphaClipThresholdText = new GUIContent("Threshold",
|
||||
"Sets where the Alpha Clipping starts. The higher the value is, the brighter the effect is when clipping starts.");
|
||||
|
||||
public static readonly GUIContent receiveShadowText = new GUIContent("Receive Shadows",
|
||||
"When enabled, other GameObjects can cast shadows onto this GameObject.");
|
||||
|
||||
public static readonly GUIContent baseMap = new GUIContent("Base Map",
|
||||
"Specifies the base Material and/or Color of the surface. If you’ve selected Transparent or Alpha Clipping under Surface Options, your Material uses the Texture’s alpha channel or color.");
|
||||
|
||||
public static readonly GUIContent emissionMap = new GUIContent("Emission Map",
|
||||
"Sets a Texture map to use for emission. You can also select a color with the color picker. Colors are multiplied over the Texture.");
|
||||
|
||||
public static readonly GUIContent normalMapText =
|
||||
new GUIContent("Normal Map", "Assigns a tangent-space normal map.");
|
||||
|
||||
public static readonly GUIContent bumpScaleNotSupported =
|
||||
new GUIContent("Bump scale is not supported on mobile platforms");
|
||||
|
||||
public static readonly GUIContent fixNormalNow = new GUIContent("Fix now",
|
||||
"Converts the assigned texture to be a normal map format.");
|
||||
|
||||
public static readonly GUIContent queueSlider = new GUIContent("Priority",
|
||||
"Determines the chronological rendering order for a Material. High values are rendered first.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Variables
|
||||
|
||||
protected MaterialEditor materialEditor { get; set; }
|
||||
|
||||
protected MaterialProperty surfaceTypeProp { get; set; }
|
||||
|
||||
protected MaterialProperty blendModeProp { get; set; }
|
||||
|
||||
protected MaterialProperty cullingProp { get; set; }
|
||||
|
||||
protected MaterialProperty alphaClipProp { get; set; }
|
||||
|
||||
protected MaterialProperty alphaCutoffProp { get; set; }
|
||||
|
||||
protected MaterialProperty receiveShadowsProp { get; set; }
|
||||
|
||||
// Common Surface Input properties
|
||||
|
||||
protected MaterialProperty baseMapProp { get; set; }
|
||||
|
||||
protected MaterialProperty baseColorProp { get; set; }
|
||||
|
||||
protected MaterialProperty emissionMapProp { get; set; }
|
||||
|
||||
protected MaterialProperty emissionColorProp { get; set; }
|
||||
|
||||
protected MaterialProperty queueOffsetProp { get; set; }
|
||||
|
||||
public bool m_FirstTimeApply = true;
|
||||
|
||||
private const string k_KeyPrefix = "UniversalRP:Material:UI_State:";
|
||||
|
||||
private string m_HeaderStateKey = null;
|
||||
|
||||
protected string headerStateKey { get { return m_HeaderStateKey; } }
|
||||
|
||||
// Header foldout states
|
||||
|
||||
SavedBool m_SurfaceOptionsFoldout;
|
||||
|
||||
SavedBool m_SurfaceInputsFoldout;
|
||||
|
||||
SavedBool m_AdvancedFoldout;
|
||||
|
||||
#endregion
|
||||
|
||||
private const int queueOffsetRange = 50;
|
||||
////////////////////////////////////
|
||||
// General Functions //
|
||||
////////////////////////////////////
|
||||
#region GeneralFunctions
|
||||
|
||||
public abstract void MaterialChanged(Material material);
|
||||
|
||||
public virtual void FindProperties(MaterialProperty[] properties)
|
||||
{
|
||||
surfaceTypeProp = FindProperty("_Surface", properties);
|
||||
blendModeProp = FindProperty("_Blend", properties);
|
||||
cullingProp = FindProperty("_Cull", properties);
|
||||
alphaClipProp = FindProperty("_AlphaClip", properties);
|
||||
alphaCutoffProp = FindProperty("_Cutoff", properties);
|
||||
receiveShadowsProp = FindProperty("_ReceiveShadows", properties, false);
|
||||
baseMapProp = FindProperty("_BaseMap", properties, false);
|
||||
baseColorProp = FindProperty("_BaseColor", properties, false);
|
||||
emissionMapProp = FindProperty("_EmissionMap", properties, false);
|
||||
emissionColorProp = FindProperty("_EmissionColor", properties, false);
|
||||
queueOffsetProp = FindProperty("_QueueOffset", properties, false);
|
||||
}
|
||||
|
||||
public override void OnGUI(MaterialEditor materialEditorIn, MaterialProperty[] properties)
|
||||
{
|
||||
if (materialEditorIn == null)
|
||||
throw new ArgumentNullException("materialEditorIn");
|
||||
|
||||
FindProperties(properties); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
|
||||
materialEditor = materialEditorIn;
|
||||
Material material = materialEditor.target as Material;
|
||||
|
||||
// Make sure that needed setup (ie keywords/renderqueue) are set up if we're switching some existing
|
||||
// material to a universal shader.
|
||||
if (m_FirstTimeApply)
|
||||
{
|
||||
OnOpenGUI(material, materialEditorIn);
|
||||
m_FirstTimeApply = false;
|
||||
}
|
||||
|
||||
ShaderPropertiesGUI(material);
|
||||
}
|
||||
|
||||
public virtual void OnOpenGUI(Material material, MaterialEditor materialEditor)
|
||||
{
|
||||
// Foldout states
|
||||
m_HeaderStateKey = k_KeyPrefix + material.shader.name; // Create key string for editor prefs
|
||||
m_SurfaceOptionsFoldout = new SavedBool($"{m_HeaderStateKey}.SurfaceOptionsFoldout", true);
|
||||
m_SurfaceInputsFoldout = new SavedBool($"{m_HeaderStateKey}.SurfaceInputsFoldout", true);
|
||||
m_AdvancedFoldout = new SavedBool($"{m_HeaderStateKey}.AdvancedFoldout", false);
|
||||
|
||||
foreach (var obj in materialEditor.targets)
|
||||
MaterialChanged((Material)obj);
|
||||
}
|
||||
|
||||
public void ShaderPropertiesGUI(Material material)
|
||||
{
|
||||
if (material == null)
|
||||
throw new ArgumentNullException("material");
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
m_SurfaceOptionsFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_SurfaceOptionsFoldout.value, Styles.SurfaceOptions);
|
||||
if (m_SurfaceOptionsFoldout.value)
|
||||
{
|
||||
DrawSurfaceOptions(material);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
m_SurfaceInputsFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_SurfaceInputsFoldout.value, Styles.SurfaceInputs);
|
||||
if (m_SurfaceInputsFoldout.value)
|
||||
{
|
||||
DrawSurfaceInputs(material);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
DrawAdditionalFoldouts(material);
|
||||
|
||||
m_AdvancedFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_AdvancedFoldout.value, Styles.AdvancedLabel);
|
||||
if (m_AdvancedFoldout.value)
|
||||
{
|
||||
DrawAdvancedOptions(material);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
foreach (var obj in materialEditor.targets)
|
||||
MaterialChanged((Material)obj);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
////////////////////////////////////
|
||||
// Drawing Functions //
|
||||
////////////////////////////////////
|
||||
#region DrawingFunctions
|
||||
|
||||
public virtual void DrawSurfaceOptions(Material material)
|
||||
{
|
||||
DoPopup(Styles.surfaceType, surfaceTypeProp, Enum.GetNames(typeof(SurfaceType)));
|
||||
if ((SurfaceType)material.GetFloat("_Surface") == SurfaceType.Transparent)
|
||||
DoPopup(Styles.blendingMode, blendModeProp, Enum.GetNames(typeof(BlendMode)));
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.showMixedValue = cullingProp.hasMixedValue;
|
||||
var culling = (RenderFace)cullingProp.floatValue;
|
||||
culling = (RenderFace)EditorGUILayout.EnumPopup(Styles.cullingText, culling);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
materialEditor.RegisterPropertyChangeUndo(Styles.cullingText.text);
|
||||
cullingProp.floatValue = (float)culling;
|
||||
material.doubleSidedGI = (RenderFace)cullingProp.floatValue != RenderFace.Front;
|
||||
}
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.showMixedValue = alphaClipProp.hasMixedValue;
|
||||
var alphaClipEnabled = EditorGUILayout.Toggle(Styles.alphaClipText, alphaClipProp.floatValue == 1);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
alphaClipProp.floatValue = alphaClipEnabled ? 1 : 0;
|
||||
EditorGUI.showMixedValue = false;
|
||||
|
||||
if (alphaClipProp.floatValue == 1)
|
||||
materialEditor.ShaderProperty(alphaCutoffProp, Styles.alphaClipThresholdText, 1);
|
||||
|
||||
if (receiveShadowsProp != null)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.showMixedValue = receiveShadowsProp.hasMixedValue;
|
||||
var receiveShadows =
|
||||
EditorGUILayout.Toggle(Styles.receiveShadowText, receiveShadowsProp.floatValue == 1.0f);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
receiveShadowsProp.floatValue = receiveShadows ? 1.0f : 0.0f;
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawSurfaceInputs(Material material)
|
||||
{
|
||||
DrawBaseProperties(material);
|
||||
}
|
||||
|
||||
public virtual void DrawAdvancedOptions(Material material)
|
||||
{
|
||||
materialEditor.EnableInstancingField();
|
||||
DrawQueueOffsetField();
|
||||
}
|
||||
|
||||
protected void DrawQueueOffsetField()
|
||||
{
|
||||
if (queueOffsetProp != null)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.showMixedValue = queueOffsetProp.hasMixedValue;
|
||||
var queue = EditorGUILayout.IntSlider(Styles.queueSlider, (int)queueOffsetProp.floatValue, -queueOffsetRange, queueOffsetRange);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
queueOffsetProp.floatValue = queue;
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawAdditionalFoldouts(Material material) { }
|
||||
|
||||
public virtual void DrawBaseProperties(Material material)
|
||||
{
|
||||
if (baseMapProp != null && baseColorProp != null) // Draw the baseMap, most shader will have at least a baseMap
|
||||
{
|
||||
materialEditor.TexturePropertySingleLine(Styles.baseMap, baseMapProp, baseColorProp);
|
||||
// TODO Temporary fix for lightmapping, to be replaced with attribute tag.
|
||||
if (material.HasProperty("_MainTex"))
|
||||
{
|
||||
material.SetTexture("_MainTex", baseMapProp.textureValue);
|
||||
var baseMapTiling = baseMapProp.textureScaleAndOffset;
|
||||
material.SetTextureScale("_MainTex", new Vector2(baseMapTiling.x, baseMapTiling.y));
|
||||
material.SetTextureOffset("_MainTex", new Vector2(baseMapTiling.z, baseMapTiling.w));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void DrawEmissionProperties(Material material, bool keyword)
|
||||
{
|
||||
var emissive = true;
|
||||
var hadEmissionTexture = emissionMapProp.textureValue != null;
|
||||
|
||||
if (!keyword)
|
||||
{
|
||||
materialEditor.TexturePropertyWithHDRColor(Styles.emissionMap, emissionMapProp, emissionColorProp,
|
||||
false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Emission for GI?
|
||||
emissive = materialEditor.EmissionEnabledProperty();
|
||||
|
||||
EditorGUI.BeginDisabledGroup(!emissive);
|
||||
{
|
||||
// Texture and HDR color controls
|
||||
materialEditor.TexturePropertyWithHDRColor(Styles.emissionMap, emissionMapProp,
|
||||
emissionColorProp,
|
||||
false);
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
// If texture was assigned and color was black set color to white
|
||||
var brightness = emissionColorProp.colorValue.maxColorComponent;
|
||||
if (emissionMapProp.textureValue != null && !hadEmissionTexture && brightness <= 0f)
|
||||
emissionColorProp.colorValue = Color.white;
|
||||
|
||||
// UniversalRP does not support RealtimeEmissive. We set it to bake emissive and handle the emissive is black right.
|
||||
if (emissive)
|
||||
{
|
||||
var oldFlags = material.globalIlluminationFlags;
|
||||
var newFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
|
||||
|
||||
if (brightness <= 0f)
|
||||
newFlags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
|
||||
|
||||
if (newFlags != oldFlags)
|
||||
material.globalIlluminationFlags = newFlags;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DrawNormalArea(MaterialEditor materialEditor, MaterialProperty bumpMap, MaterialProperty bumpMapScale = null)
|
||||
{
|
||||
if (bumpMapScale != null)
|
||||
{
|
||||
materialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap,
|
||||
bumpMap.textureValue != null ? bumpMapScale : null);
|
||||
if (bumpMapScale.floatValue != 1 &&
|
||||
UnityEditorInternal.InternalEditorUtility.IsMobilePlatform(
|
||||
EditorUserBuildSettings.activeBuildTarget))
|
||||
if (materialEditor.HelpBoxWithButton(Styles.bumpScaleNotSupported, Styles.fixNormalNow))
|
||||
bumpMapScale.floatValue = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
materialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void DrawTileOffset(MaterialEditor materialEditor, MaterialProperty textureProp)
|
||||
{
|
||||
materialEditor.TextureScaleOffsetProperty(textureProp);
|
||||
}
|
||||
|
||||
#endregion
|
||||
////////////////////////////////////
|
||||
// Material Data Functions //
|
||||
////////////////////////////////////
|
||||
#region MaterialDataFunctions
|
||||
|
||||
public static void SetMaterialKeywords(Material material, Action<Material> shadingModelFunc = null, Action<Material> shaderFunc = null)
|
||||
{
|
||||
// Clear all keywords for fresh start
|
||||
material.shaderKeywords = null;
|
||||
|
||||
// Setup blending - consistent across all Universal RP shaders
|
||||
SetupMaterialBlendMode(material);
|
||||
|
||||
// Receive Shadows
|
||||
if (material.HasProperty("_ReceiveShadows"))
|
||||
CoreUtils.SetKeyword(material, "_RECEIVE_SHADOWS_OFF", material.GetFloat("_ReceiveShadows") == 0.0f);
|
||||
|
||||
// Emission
|
||||
if (material.HasProperty("_EmissionColor"))
|
||||
MaterialEditor.FixupEmissiveFlag(material);
|
||||
bool shouldEmissionBeEnabled =
|
||||
(material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0;
|
||||
if (material.HasProperty("_EmissionEnabled") && !shouldEmissionBeEnabled)
|
||||
shouldEmissionBeEnabled = material.GetFloat("_EmissionEnabled") >= 0.5f;
|
||||
CoreUtils.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled);
|
||||
|
||||
// Normal Map
|
||||
if (material.HasProperty("_BumpMap"))
|
||||
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
|
||||
|
||||
// Shader specific keyword functions
|
||||
shadingModelFunc?.Invoke(material);
|
||||
shaderFunc?.Invoke(material);
|
||||
}
|
||||
|
||||
public static void SetupMaterialBlendMode(Material material)
|
||||
{
|
||||
if (material == null)
|
||||
throw new ArgumentNullException("material");
|
||||
|
||||
bool alphaClip = false;
|
||||
if (material.HasProperty("_AlphaClip"))
|
||||
alphaClip = material.GetFloat("_AlphaClip") >= 0.5;
|
||||
|
||||
if (alphaClip)
|
||||
{
|
||||
material.EnableKeyword("_ALPHATEST_ON");
|
||||
}
|
||||
else
|
||||
{
|
||||
material.DisableKeyword("_ALPHATEST_ON");
|
||||
}
|
||||
|
||||
if (material.HasProperty("_Surface"))
|
||||
{
|
||||
SurfaceType surfaceType = (SurfaceType)material.GetFloat("_Surface");
|
||||
if (surfaceType == SurfaceType.Opaque)
|
||||
{
|
||||
if (alphaClip)
|
||||
{
|
||||
material.renderQueue = (int)RenderQueue.AlphaTest;
|
||||
material.SetOverrideTag("RenderType", "TransparentCutout");
|
||||
}
|
||||
else
|
||||
{
|
||||
material.renderQueue = (int)RenderQueue.Geometry;
|
||||
material.SetOverrideTag("RenderType", "Opaque");
|
||||
}
|
||||
|
||||
material.renderQueue += material.HasProperty("_QueueOffset") ? (int)material.GetFloat("_QueueOffset") : 0;
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
material.SetInt("_ZWrite", 1);
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
material.SetShaderPassEnabled("ShadowCaster", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
BlendMode blendMode = (BlendMode)material.GetFloat("_Blend");
|
||||
|
||||
// Specific Transparent Mode Settings
|
||||
switch (blendMode)
|
||||
{
|
||||
case BlendMode.Alpha:
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
break;
|
||||
case BlendMode.Premultiply:
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
break;
|
||||
case BlendMode.Additive:
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
break;
|
||||
case BlendMode.Multiply:
|
||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
|
||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
material.EnableKeyword("_ALPHAMODULATE_ON");
|
||||
break;
|
||||
}
|
||||
|
||||
// General Transparent Material Settings
|
||||
material.SetOverrideTag("RenderType", "Transparent");
|
||||
material.SetInt("_ZWrite", 0);
|
||||
material.renderQueue = (int)RenderQueue.Transparent;
|
||||
material.renderQueue += material.HasProperty("_QueueOffset") ? (int)material.GetFloat("_QueueOffset") : 0;
|
||||
material.SetShaderPassEnabled("ShadowCaster", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
////////////////////////////////////
|
||||
// Helper Functions //
|
||||
////////////////////////////////////
|
||||
#region HelperFunctions
|
||||
|
||||
public static void TwoFloatSingleLine(GUIContent title, MaterialProperty prop1, GUIContent prop1Label,
|
||||
MaterialProperty prop2, GUIContent prop2Label, MaterialEditor materialEditor, float labelWidth = 30f)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.showMixedValue = prop1.hasMixedValue || prop2.hasMixedValue;
|
||||
Rect rect = EditorGUILayout.GetControlRect();
|
||||
EditorGUI.PrefixLabel(rect, title);
|
||||
var indent = EditorGUI.indentLevel;
|
||||
var preLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUI.indentLevel = 0;
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
Rect propRect1 = new Rect(rect.x + preLabelWidth, rect.y,
|
||||
(rect.width - preLabelWidth) * 0.5f, EditorGUIUtility.singleLineHeight);
|
||||
var prop1val = EditorGUI.FloatField(propRect1, prop1Label, prop1.floatValue);
|
||||
|
||||
Rect propRect2 = new Rect(propRect1.x + propRect1.width, rect.y,
|
||||
propRect1.width, EditorGUIUtility.singleLineHeight);
|
||||
var prop2val = EditorGUI.FloatField(propRect2, prop2Label, prop2.floatValue);
|
||||
|
||||
EditorGUI.indentLevel = indent;
|
||||
EditorGUIUtility.labelWidth = preLabelWidth;
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
materialEditor.RegisterPropertyChangeUndo(title.text);
|
||||
prop1.floatValue = prop1val;
|
||||
prop2.floatValue = prop2val;
|
||||
}
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
public void DoPopup(GUIContent label, MaterialProperty property, string[] options)
|
||||
{
|
||||
DoPopup(label, property, options, materialEditor);
|
||||
}
|
||||
|
||||
public static void DoPopup(GUIContent label, MaterialProperty property, string[] options, MaterialEditor materialEditor)
|
||||
{
|
||||
if (property == null)
|
||||
throw new ArgumentNullException("property");
|
||||
|
||||
EditorGUI.showMixedValue = property.hasMixedValue;
|
||||
|
||||
var mode = property.floatValue;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
mode = EditorGUILayout.Popup(label, (int)mode, options);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
materialEditor.RegisterPropertyChangeUndo(label.text);
|
||||
property.floatValue = mode;
|
||||
}
|
||||
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
// Helper to show texture and color properties
|
||||
public static Rect TextureColorProps(MaterialEditor materialEditor, GUIContent label, MaterialProperty textureProp, MaterialProperty colorProp, bool hdr = false)
|
||||
{
|
||||
Rect rect = EditorGUILayout.GetControlRect();
|
||||
EditorGUI.showMixedValue = textureProp.hasMixedValue;
|
||||
materialEditor.TexturePropertyMiniThumbnail(rect, textureProp, label.text, label.tooltip);
|
||||
EditorGUI.showMixedValue = false;
|
||||
|
||||
if (colorProp != null)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.showMixedValue = colorProp.hasMixedValue;
|
||||
int indentLevel = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
Rect rectAfterLabel = new Rect(rect.x + EditorGUIUtility.labelWidth, rect.y,
|
||||
EditorGUIUtility.fieldWidth, EditorGUIUtility.singleLineHeight);
|
||||
var col = EditorGUI.ColorField(rectAfterLabel, GUIContent.none, colorProp.colorValue, true,
|
||||
false, hdr);
|
||||
EditorGUI.indentLevel = indentLevel;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
materialEditor.RegisterPropertyChangeUndo(colorProp.displayName);
|
||||
colorProp.colorValue = col;
|
||||
}
|
||||
EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Copied from shaderGUI as it is a protected function in an abstract class, unavailable to others
|
||||
|
||||
public new static MaterialProperty FindProperty(string propertyName, MaterialProperty[] properties)
|
||||
{
|
||||
return FindProperty(propertyName, properties, true);
|
||||
}
|
||||
|
||||
// Copied from shaderGUI as it is a protected function in an abstract class, unavailable to others
|
||||
|
||||
public new static MaterialProperty FindProperty(string propertyName, MaterialProperty[] properties, bool propertyIsMandatory)
|
||||
{
|
||||
for (int index = 0; index < properties.Length; ++index)
|
||||
{
|
||||
if (properties[index] != null && properties[index].name == propertyName)
|
||||
return properties[index];
|
||||
}
|
||||
if (propertyIsMandatory)
|
||||
throw new ArgumentException("Could not find MaterialProperty: '" + propertyName + "', Num properties: " + (object)properties.Length);
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d9c32b84c5466d4e8831430c414ee0a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderGUI/URP/2019-2020/BaseShaderGUI.cs
|
||||
uploadId: 919972
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
//SEE: https://github.com/Unity-Technologies/Graphics/blob/v10.10.1/com.unity.render-pipelines.universal/Editor/ShaderGUI/Shaders/LitShader.cs
|
||||
|
||||
#if !UNITY_2021_1_OR_NEWER
|
||||
#if USING_URP
|
||||
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Rendering.Universal.ShaderGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public class LitShader : BaseShaderGUI
|
||||
{
|
||||
private LitGUI.LitProperties litProperties;
|
||||
private LitDetailGUI.LitProperties litDetailProperties;
|
||||
private SavedBool m_DetailInputsFoldout;
|
||||
|
||||
public override void OnOpenGUI(Material material, MaterialEditor materialEditor)
|
||||
{
|
||||
base.OnOpenGUI(material, materialEditor);
|
||||
m_DetailInputsFoldout = new SavedBool($"{headerStateKey}.DetailInputsFoldout", true);
|
||||
}
|
||||
|
||||
public override void DrawAdditionalFoldouts(Material material)
|
||||
{
|
||||
m_DetailInputsFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_DetailInputsFoldout.value, LitDetailGUI.Styles.detailInputs);
|
||||
if (m_DetailInputsFoldout.value)
|
||||
{
|
||||
LitDetailGUI.DoDetailArea(litDetailProperties, materialEditor);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
}
|
||||
|
||||
// collect properties from the material properties
|
||||
public override void FindProperties(MaterialProperty[] properties)
|
||||
{
|
||||
base.FindProperties(properties);
|
||||
litProperties = new LitGUI.LitProperties(properties);
|
||||
litDetailProperties = new LitDetailGUI.LitProperties(properties);
|
||||
}
|
||||
|
||||
// material changed check
|
||||
public override void MaterialChanged(Material material)
|
||||
{
|
||||
if (material == null)
|
||||
throw new ArgumentNullException("material");
|
||||
|
||||
SetMaterialKeywords(material, LitGUI.SetMaterialKeywords, LitDetailGUI.SetMaterialKeywords);
|
||||
}
|
||||
|
||||
// material main surface options
|
||||
public override void DrawSurfaceOptions(Material material)
|
||||
{
|
||||
if (material == null)
|
||||
throw new ArgumentNullException("material");
|
||||
|
||||
// Use default labelWidth
|
||||
EditorGUIUtility.labelWidth = 0f;
|
||||
|
||||
// Detect any changes to the material
|
||||
EditorGUI.BeginChangeCheck();
|
||||
if (litProperties.workflowMode != null)
|
||||
{
|
||||
DoPopup(LitGUI.Styles.workflowModeText, litProperties.workflowMode, Enum.GetNames(typeof(LitGUI.WorkflowMode)));
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
foreach (var obj in blendModeProp.targets)
|
||||
MaterialChanged((Material)obj);
|
||||
}
|
||||
base.DrawSurfaceOptions(material);
|
||||
}
|
||||
|
||||
// material main surface inputs
|
||||
public override void DrawSurfaceInputs(Material material)
|
||||
{
|
||||
base.DrawSurfaceInputs(material);
|
||||
LitGUI.Inputs(litProperties, materialEditor, material);
|
||||
DrawEmissionProperties(material, true);
|
||||
DrawTileOffset(materialEditor, baseMapProp);
|
||||
}
|
||||
|
||||
// material main advanced options
|
||||
public override void DrawAdvancedOptions(Material material)
|
||||
{
|
||||
if (litProperties.reflections != null && litProperties.highlights != null)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
materialEditor.ShaderProperty(litProperties.highlights, LitGUI.Styles.highlightsText);
|
||||
materialEditor.ShaderProperty(litProperties.reflections, LitGUI.Styles.reflectionsText);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
MaterialChanged(material);
|
||||
}
|
||||
}
|
||||
|
||||
base.DrawAdvancedOptions(material);
|
||||
}
|
||||
|
||||
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
|
||||
{
|
||||
if (material == null)
|
||||
throw new ArgumentNullException("material");
|
||||
|
||||
// _Emission property is lost after assigning Standard shader to the material
|
||||
// thus transfer it before assigning the new shader
|
||||
if (material.HasProperty("_Emission"))
|
||||
{
|
||||
material.SetColor("_EmissionColor", material.GetColor("_Emission"));
|
||||
}
|
||||
|
||||
base.AssignNewShaderToMaterial(material, oldShader, newShader);
|
||||
|
||||
if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
|
||||
{
|
||||
SetupMaterialBlendMode(material);
|
||||
return;
|
||||
}
|
||||
|
||||
SurfaceType surfaceType = SurfaceType.Opaque;
|
||||
BlendMode blendMode = BlendMode.Alpha;
|
||||
if (oldShader.name.Contains("/Transparent/Cutout/"))
|
||||
{
|
||||
surfaceType = SurfaceType.Opaque;
|
||||
material.SetFloat("_AlphaClip", 1);
|
||||
}
|
||||
else if (oldShader.name.Contains("/Transparent/"))
|
||||
{
|
||||
// NOTE: legacy shaders did not provide physically based transparency
|
||||
// therefore Fade mode
|
||||
surfaceType = SurfaceType.Transparent;
|
||||
blendMode = BlendMode.Alpha;
|
||||
}
|
||||
material.SetFloat("_Surface", (float)surfaceType);
|
||||
material.SetFloat("_Blend", (float)blendMode);
|
||||
|
||||
if (oldShader.name.Equals("Standard (Specular setup)"))
|
||||
{
|
||||
material.SetFloat("_WorkflowMode", (float)LitGUI.WorkflowMode.Specular);
|
||||
Texture texture = material.GetTexture("_SpecGlossMap");
|
||||
if (texture != null)
|
||||
material.SetTexture("_MetallicSpecGlossMap", texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetFloat("_WorkflowMode", (float)LitGUI.WorkflowMode.Metallic);
|
||||
Texture texture = material.GetTexture("_MetallicGlossMap");
|
||||
if (texture != null)
|
||||
material.SetTexture("_MetallicSpecGlossMap", texture);
|
||||
}
|
||||
|
||||
MaterialChanged(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c18bb56219273c842a5ce95b7e8493ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderGUI/URP/2019-2020/LitShader.cs
|
||||
uploadId: 919972
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
//SEE: https://github.com/Unity-Technologies/Graphics/blob/v10.10.1/com.unity.render-pipelines.universal/Editor/SavedParameter.cs
|
||||
|
||||
//#if !UNITY_2021_1_OR_NEWER
|
||||
//#if USING_URP
|
||||
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public class SavedParameter<T>
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
public delegate void SetParameter(string key, T value);
|
||||
public delegate T GetParameter(string key, T defaultValue);
|
||||
|
||||
readonly string m_Key;
|
||||
bool m_Loaded;
|
||||
T m_Value;
|
||||
|
||||
readonly SetParameter m_Setter;
|
||||
readonly GetParameter m_Getter;
|
||||
|
||||
public SavedParameter(string key, T value, GetParameter getter, SetParameter setter)
|
||||
{
|
||||
Assert.IsNotNull(setter);
|
||||
Assert.IsNotNull(getter);
|
||||
|
||||
m_Key = key;
|
||||
m_Loaded = false;
|
||||
m_Value = value;
|
||||
m_Setter = setter;
|
||||
m_Getter = getter;
|
||||
}
|
||||
|
||||
void Load()
|
||||
{
|
||||
if (m_Loaded)
|
||||
return;
|
||||
|
||||
m_Loaded = true;
|
||||
m_Value = m_Getter(m_Key, m_Value);
|
||||
}
|
||||
|
||||
public T value
|
||||
{
|
||||
get
|
||||
{
|
||||
Load();
|
||||
return m_Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
Load();
|
||||
|
||||
if (m_Value.Equals(value))
|
||||
return;
|
||||
|
||||
m_Value = value;
|
||||
m_Setter(m_Key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pre-specialized class for easier use and compatibility with existing code
|
||||
public sealed class SavedBool : SavedParameter<bool>
|
||||
{
|
||||
public SavedBool(string key, bool value)
|
||||
: base(key, value, EditorPrefs.GetBool, EditorPrefs.SetBool) { }
|
||||
}
|
||||
|
||||
public sealed class SavedInt : SavedParameter<int>
|
||||
{
|
||||
public SavedInt(string key, int value)
|
||||
: base(key, value, EditorPrefs.GetInt, EditorPrefs.SetInt) { }
|
||||
}
|
||||
|
||||
public sealed class SavedFloat : SavedParameter<float>
|
||||
{
|
||||
public SavedFloat(string key, float value)
|
||||
: base(key, value, EditorPrefs.GetFloat, EditorPrefs.SetFloat) { }
|
||||
}
|
||||
|
||||
public sealed class SavedString : SavedParameter<string>
|
||||
{
|
||||
public SavedString(string key, string value)
|
||||
: base(key, value, EditorPrefs.GetString, EditorPrefs.SetString) { }
|
||||
}
|
||||
}
|
||||
|
||||
//#endif
|
||||
//#endif
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a1e3c272858e934d8a774f5d100020f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderGUI/URP/2019-2020/SavedParameter.cs
|
||||
uploadId: 919972
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06c569b799330c24ea9d07dcbb486bf0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
//SEE: https://github.com/Unity-Technologies/Graphics/blob/569f8878feb8f4340d6de66efa151d0fc1b79c77/Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/Shaders/LitShader.cs
|
||||
|
||||
#if USING_URP
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEditor.Rendering.Universal.ShaderGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public class LitShader : BaseShaderGUI
|
||||
{
|
||||
static readonly string[] workflowModeNames = Enum.GetNames(typeof(LitGUI.WorkflowMode));
|
||||
|
||||
private LitGUI.LitProperties litProperties;
|
||||
private LitDetailGUI.LitProperties litDetailProperties;
|
||||
|
||||
public override void FillAdditionalFoldouts(MaterialHeaderScopeList materialScopesList)
|
||||
{
|
||||
materialScopesList.RegisterHeaderScope(LitDetailGUI.Styles.detailInputs, Expandable.Details, _ => LitDetailGUI.DoDetailArea(litDetailProperties, materialEditor));
|
||||
}
|
||||
|
||||
// collect properties from the material properties
|
||||
public override void FindProperties(MaterialProperty[] properties)
|
||||
{
|
||||
base.FindProperties(properties);
|
||||
litProperties = new LitGUI.LitProperties(properties);
|
||||
litDetailProperties = new LitDetailGUI.LitProperties(properties);
|
||||
}
|
||||
|
||||
// material changed check
|
||||
public override void ValidateMaterial(Material material)
|
||||
{
|
||||
SetMaterialKeywords(material, LitGUI.SetMaterialKeywords, LitDetailGUI.SetMaterialKeywords);
|
||||
}
|
||||
|
||||
// material main surface options
|
||||
public override void DrawSurfaceOptions(Material material)
|
||||
{
|
||||
// Use default labelWidth
|
||||
EditorGUIUtility.labelWidth = 0f;
|
||||
|
||||
if (litProperties.workflowMode != null)
|
||||
DoPopup(LitGUI.Styles.workflowModeText, litProperties.workflowMode, workflowModeNames);
|
||||
|
||||
base.DrawSurfaceOptions(material);
|
||||
}
|
||||
|
||||
// material main surface inputs
|
||||
public override void DrawSurfaceInputs(Material material)
|
||||
{
|
||||
base.DrawSurfaceInputs(material);
|
||||
LitGUI.Inputs(litProperties, materialEditor, material);
|
||||
DrawEmissionProperties(material, true);
|
||||
DrawTileOffset(materialEditor, baseMapProp);
|
||||
}
|
||||
|
||||
// material main advanced options
|
||||
public override void DrawAdvancedOptions(Material material)
|
||||
{
|
||||
if (litProperties.reflections != null && litProperties.highlights != null)
|
||||
{
|
||||
materialEditor.ShaderProperty(litProperties.highlights, LitGUI.Styles.highlightsText);
|
||||
materialEditor.ShaderProperty(litProperties.reflections, LitGUI.Styles.reflectionsText);
|
||||
}
|
||||
|
||||
base.DrawAdvancedOptions(material);
|
||||
}
|
||||
|
||||
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
|
||||
{
|
||||
if (material == null)
|
||||
throw new ArgumentNullException("material");
|
||||
|
||||
// _Emission property is lost after assigning Standard shader to the material
|
||||
// thus transfer it before assigning the new shader
|
||||
if (material.HasProperty("_Emission"))
|
||||
{
|
||||
material.SetColor("_EmissionColor", material.GetColor("_Emission"));
|
||||
}
|
||||
|
||||
base.AssignNewShaderToMaterial(material, oldShader, newShader);
|
||||
|
||||
if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
|
||||
{
|
||||
SetupMaterialBlendMode(material);
|
||||
return;
|
||||
}
|
||||
|
||||
SurfaceType surfaceType = SurfaceType.Opaque;
|
||||
BlendMode blendMode = BlendMode.Alpha;
|
||||
if (oldShader.name.Contains("/Transparent/Cutout/"))
|
||||
{
|
||||
surfaceType = SurfaceType.Opaque;
|
||||
material.SetFloat("_AlphaClip", 1);
|
||||
}
|
||||
else if (oldShader.name.Contains("/Transparent/"))
|
||||
{
|
||||
// NOTE: legacy shaders did not provide physically based transparency
|
||||
// therefore Fade mode
|
||||
surfaceType = SurfaceType.Transparent;
|
||||
blendMode = BlendMode.Alpha;
|
||||
}
|
||||
material.SetFloat("_Blend", (float)blendMode);
|
||||
|
||||
material.SetFloat("_Surface", (float)surfaceType);
|
||||
if (surfaceType == SurfaceType.Opaque)
|
||||
{
|
||||
material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
|
||||
}
|
||||
else
|
||||
{
|
||||
material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
|
||||
}
|
||||
|
||||
if (oldShader.name.Equals("Standard (Specular setup)"))
|
||||
{
|
||||
material.SetFloat("_WorkflowMode", (float)LitGUI.WorkflowMode.Specular);
|
||||
Texture texture = material.GetTexture("_SpecGlossMap");
|
||||
if (texture != null)
|
||||
material.SetTexture("_MetallicSpecGlossMap", texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetFloat("_WorkflowMode", (float)LitGUI.WorkflowMode.Metallic);
|
||||
Texture texture = material.GetTexture("_MetallicGlossMap");
|
||||
if (texture != null)
|
||||
material.SetTexture("_MetallicSpecGlossMap", texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e318227579cea0469bbb060b48f848e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderGUI/URP/2021/LitShader.cs
|
||||
uploadId: 919972
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
//SEE: https://github.com/Unity-Technologies/Graphics/blob/632f80e011f18ea537ee6e2f0be3ff4f4dea6a11/Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadingModels/LitDetailGUI.cs
|
||||
|
||||
#if USING_URP
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public class LitDetailGUI
|
||||
{
|
||||
|
||||
public static class Styles
|
||||
{
|
||||
public static readonly GUIContent detailInputs = EditorGUIUtility.TrTextContent("Detail Inputs",
|
||||
"These settings define the surface details by tiling and overlaying additional maps on the surface.");
|
||||
|
||||
public static readonly GUIContent detailMaskText = EditorGUIUtility.TrTextContent("Mask",
|
||||
"Select a mask for the Detail map. The mask uses the alpha channel of the selected texture. The Tiling and Offset settings have no effect on the mask.");
|
||||
|
||||
public static readonly GUIContent detailAlbedoMapText = EditorGUIUtility.TrTextContent("Base Map",
|
||||
"Select the surface detail texture.The alpha of your texture determines surface hue and intensity.");
|
||||
|
||||
public static readonly GUIContent detailNormalMapText = EditorGUIUtility.TrTextContent("Normal Map",
|
||||
"Designates a Normal Map to create the illusion of bumps and dents in the details of this Material's surface.");
|
||||
|
||||
public static readonly GUIContent detailAlbedoMapScaleInfo = EditorGUIUtility.TrTextContent("Setting the scaling factor to a value other than 1 results in a less performant shader variant.");
|
||||
public static readonly GUIContent detailAlbedoMapFormatError = EditorGUIUtility.TrTextContent("This texture is not in linear space.");
|
||||
}
|
||||
|
||||
public struct LitProperties
|
||||
{
|
||||
public MaterialProperty detailMask;
|
||||
public MaterialProperty detailAlbedoMapScale;
|
||||
public MaterialProperty detailAlbedoMap;
|
||||
public MaterialProperty detailNormalMapScale;
|
||||
public MaterialProperty detailNormalMap;
|
||||
|
||||
public LitProperties(MaterialProperty[] properties)
|
||||
{
|
||||
detailMask = BaseShaderGUI.FindProperty("_DetailMask", properties, false);
|
||||
detailAlbedoMapScale = BaseShaderGUI.FindProperty("_DetailAlbedoMapScale", properties, false);
|
||||
detailAlbedoMap = BaseShaderGUI.FindProperty("_DetailAlbedoMap", properties, false);
|
||||
detailNormalMapScale = BaseShaderGUI.FindProperty("_DetailNormalMapScale", properties, false);
|
||||
detailNormalMap = BaseShaderGUI.FindProperty("_DetailNormalMap", properties, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoDetailArea(LitProperties properties, MaterialEditor materialEditor)
|
||||
{
|
||||
materialEditor.TexturePropertySingleLine(Styles.detailMaskText, properties.detailMask);
|
||||
materialEditor.TexturePropertySingleLine(Styles.detailAlbedoMapText, properties.detailAlbedoMap,
|
||||
properties.detailAlbedoMap.textureValue != null ? properties.detailAlbedoMapScale : null);
|
||||
if (properties.detailAlbedoMapScale.floatValue != 1.0f)
|
||||
{
|
||||
EditorGUILayout.HelpBox(Styles.detailAlbedoMapScaleInfo.text, MessageType.Info, true);
|
||||
}
|
||||
var detailAlbedoTexture = properties.detailAlbedoMap.textureValue as Texture2D;
|
||||
if (detailAlbedoTexture != null && GraphicsFormatUtility.IsSRGBFormat(detailAlbedoTexture.graphicsFormat))
|
||||
{
|
||||
EditorGUILayout.HelpBox(Styles.detailAlbedoMapFormatError.text, MessageType.Warning, true);
|
||||
}
|
||||
materialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, properties.detailNormalMap,
|
||||
properties.detailNormalMap.textureValue != null ? properties.detailNormalMapScale : null);
|
||||
materialEditor.TextureScaleOffsetProperty(properties.detailAlbedoMap);
|
||||
}
|
||||
|
||||
public static void SetMaterialKeywords(Material material)
|
||||
{
|
||||
if (material.HasProperty("_DetailAlbedoMap") && material.HasProperty("_DetailNormalMap") && material.HasProperty("_DetailAlbedoMapScale"))
|
||||
{
|
||||
bool isScaled = material.GetFloat("_DetailAlbedoMapScale") != 1.0f;
|
||||
bool hasDetailMap = material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap");
|
||||
CoreUtils.SetKeyword(material, "_DETAIL_MULX2", !isScaled && hasDetailMap);
|
||||
CoreUtils.SetKeyword(material, "_DETAIL_SCALED", isScaled && hasDetailMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb3a74fd4c1042841a9468e1b00d0bbf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderGUI/URP/LitDetailGUI.cs
|
||||
uploadId: 919972
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
//SEE: https://github.com/Unity-Technologies/Graphics/blob/6fdc7996098aa184495c0a3c0da10135bfe18340/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/UniversalProperties.cs
|
||||
|
||||
|
||||
#if USING_URP
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShaderCrew.TheToonShader
|
||||
{
|
||||
public class UniversalProperties
|
||||
{
|
||||
public static class Property
|
||||
{
|
||||
public static readonly string SpecularWorkflowMode = "_WorkflowMode";
|
||||
public static readonly string SurfaceType = "_Surface";
|
||||
public static readonly string BlendMode = "_Blend";
|
||||
public static readonly string AlphaClip = "_AlphaClip";
|
||||
public static readonly string AlphaToMask = "_AlphaToMask";
|
||||
public static readonly string SrcBlend = "_SrcBlend";
|
||||
public static readonly string DstBlend = "_DstBlend";
|
||||
public static readonly string SrcBlendAlpha = "_SrcBlendAlpha";
|
||||
public static readonly string DstBlendAlpha = "_DstBlendAlpha";
|
||||
public static readonly string BlendModePreserveSpecular = "_BlendModePreserveSpecular";
|
||||
public static readonly string ZWrite = "_ZWrite";
|
||||
public static readonly string CullMode = "_Cull";
|
||||
public static readonly string CastShadows = "_CastShadows";
|
||||
public static readonly string ReceiveShadows = "_ReceiveShadows";
|
||||
public static readonly string QueueOffset = "_QueueOffset";
|
||||
|
||||
// for ShaderGraph shaders only
|
||||
public static readonly string ZTest = "_ZTest";
|
||||
public static readonly string ZWriteControl = "_ZWriteControl";
|
||||
public static readonly string QueueControl = "_QueueControl";
|
||||
|
||||
// Global Illumination requires some properties to be named specifically:
|
||||
public static readonly string EmissionMap = "_EmissionMap";
|
||||
public static readonly string EmissionColor = "_EmissionColor";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1526c7c016946e949b453370ac31ab34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 269238
|
||||
packageName: The Toon Shader
|
||||
packageVersion: 1.4.2
|
||||
assetPath: Packages/com.shadercrew.the-toon-shader.core/Scripts/Editor/ShaderGUI/URP/UniversalProperties.cs
|
||||
uploadId: 919972
|
||||
Reference in New Issue
Block a user