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:
+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