initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UnityEditor.Rendering.Universal.ShaderGUI
|
||||
{
|
||||
public static class BakedLitGUI
|
||||
{
|
||||
public struct BakedLitProperties
|
||||
{
|
||||
// Surface Input Props
|
||||
public MaterialProperty bumpMapProp;
|
||||
|
||||
public BakedLitProperties(MaterialProperty[] properties)
|
||||
{
|
||||
// Surface Input Props
|
||||
bumpMapProp = BaseShaderGUI.FindProperty("_BumpMap", properties, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Inputs(BakedLitProperties properties, MaterialEditor materialEditor)
|
||||
{
|
||||
BaseShaderGUI.DrawNormalArea(materialEditor, properties.bumpMapProp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 795fde47942374005bbe56e3879983db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UnityEditor.Rendering.Universal.ShaderGUI
|
||||
{
|
||||
internal 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("Detail Map",
|
||||
"(R) Desaturated albedo, (G) Normal Y, (B) Smoothness, (A) Normal X.");
|
||||
// "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 struct LitProperties
|
||||
{
|
||||
// public MaterialProperty detailMask;
|
||||
public MaterialProperty detailMap;
|
||||
//public MaterialProperty detailAlbedoMapScale;
|
||||
//public MaterialProperty detailAlbedoMap;
|
||||
public MaterialProperty detailNormalMapScale;
|
||||
public MaterialProperty detailSmoothnessMapScale;
|
||||
//public MaterialProperty detailNormalMap;
|
||||
|
||||
public LitProperties(MaterialProperty[] properties)
|
||||
{
|
||||
// detailMask = BaseShaderGUI.FindProperty("_DetailMask", properties, false);
|
||||
detailMap = BaseShaderGUI.FindProperty("_DetailMap", properties, false);
|
||||
//detailAlbedoMapScale = BaseShaderGUI.FindProperty("_DetailAlbedoMapScale", properties, false);
|
||||
// detailAlbedoMap = BaseShaderGUI.FindProperty("_DetailAlbedoMap", properties, false);
|
||||
detailNormalMapScale = BaseShaderGUI.FindProperty("_DetailNormalMapScale", properties, false);
|
||||
detailSmoothnessMapScale = BaseShaderGUI.FindProperty("_DetailSmoothnessMapScale", 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.detailMap);
|
||||
//,properties.detailMap.textureValue != null ? properties.detailAlbedoMapScale : null);
|
||||
// if (properties.detailAlbedoMapScale.floatValue != 1.0f)
|
||||
// {
|
||||
// EditorGUILayout.HelpBox(Styles.detailAlbedoMapScaleInfo.text, MessageType.Info, true);
|
||||
// }
|
||||
if (properties.detailMap.textureValue != null)
|
||||
{
|
||||
// materialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, properties.detailNormalMap,
|
||||
// properties.detailNormalMap.textureValue != null ? properties.detailNormalMapScale : null);
|
||||
materialEditor.RangeProperty(properties.detailNormalMapScale, "Bump Scale");
|
||||
materialEditor.RangeProperty(properties.detailSmoothnessMapScale, "Smoothness Scale");
|
||||
materialEditor.TextureScaleOffsetProperty(properties.detailMap);
|
||||
// materialEditor.TextureScaleOffsetProperty(properties.detailAlbedoMap);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetMaterialKeywords(Material material)
|
||||
{
|
||||
if (material.HasProperty("_DetailMap") )//&& material.HasProperty("_DetailAlbedoMapScale"))
|
||||
{
|
||||
bool isScaled = false;//material.GetFloat("_DetailAlbedoMapScale") != 1.0f;
|
||||
bool hasDetailMap = material.GetTexture("_DetailMap");
|
||||
CoreUtils.SetKeyword(material, "_DETAIL_MULX2", !isScaled && hasDetailMap);
|
||||
if (hasDetailMap) CoreUtils.SetKeyword(material, "_NORMALMAP", true); //Forcing on normalmap to avoid a darkening bug with mixed directional lights :/
|
||||
// CoreUtils.SetKeyword(material, "_DETAIL_SCALED", isScaled && hasDetailMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7645809b8de779942be231eecf635c5b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,320 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UnityEditor.Rendering.Universal.ShaderGUI
|
||||
{
|
||||
public static class LitGUI
|
||||
{
|
||||
public enum WorkflowMode
|
||||
{
|
||||
Specular = 0,
|
||||
Metallic
|
||||
}
|
||||
|
||||
public enum SmoothnessMapChannel
|
||||
{
|
||||
SpecularMetallicAlpha,
|
||||
AlbedoAlpha,
|
||||
}
|
||||
|
||||
public static class Styles
|
||||
{
|
||||
public static GUIContent workflowModeText = EditorGUIUtility.TrTextContent("Workflow Mode",
|
||||
"Select a workflow that fits your textures. Choose between Metallic or Specular.");
|
||||
|
||||
public static GUIContent specularMapText =
|
||||
EditorGUIUtility.TrTextContent("Specular Map", "Designates a Specular Map and specular color determining the apperance of reflections on this Material's surface.");
|
||||
|
||||
public static GUIContent metallicMapText =
|
||||
EditorGUIUtility.TrTextContent("Mask Map", "Metallic (R), AO (G), Detail Mask (B), Smoothness (A)"); //Using HDRP's packing to free up some texture channels
|
||||
|
||||
public static GUIContent smoothnessText = EditorGUIUtility.TrTextContent("Smoothness",
|
||||
"Controls the spread of highlights and reflections on the surface.");
|
||||
|
||||
public static GUIContent smoothnessMapChannelText =
|
||||
EditorGUIUtility.TrTextContent("Source",
|
||||
"Specifies where to sample a smoothness map from. By default, uses the alpha channel for your map.");
|
||||
|
||||
public static GUIContent highlightsText = EditorGUIUtility.TrTextContent("Specular Highlights",
|
||||
"When enabled, the Material reflects the shine from direct lighting.");
|
||||
|
||||
public static GUIContent reflectionsText =
|
||||
EditorGUIUtility.TrTextContent("Environment Reflections",
|
||||
"When enabled, the Material samples reflections from the nearest Reflection Probes or Lighting Probe.");
|
||||
|
||||
public static GUIContent heightMapText = EditorGUIUtility.TrTextContent("Height Map",
|
||||
"Defines a Height Map that will drive a parallax effect in the shader making the surface seem displaced.");
|
||||
|
||||
public static GUIContent occlusionText = EditorGUIUtility.TrTextContent("Occlusion Map",
|
||||
"Sets an occlusion map to simulate shadowing from ambient lighting (G).");
|
||||
|
||||
public static readonly string[] metallicSmoothnessChannelNames = { "Metallic Alpha", "Albedo Alpha" };
|
||||
public static readonly string[] specularSmoothnessChannelNames = { "Specular Alpha", "Albedo Alpha" };
|
||||
|
||||
public static GUIContent clearCoatText = EditorGUIUtility.TrTextContent("Clear Coat",
|
||||
"A multi-layer material feature which simulates a thin layer of coating on top of the surface material." +
|
||||
"\nPerformance cost is considerable as the specular component is evaluated twice, once per layer.");
|
||||
|
||||
public static GUIContent clearCoatMaskText = EditorGUIUtility.TrTextContent("Mask",
|
||||
"Specifies the amount of the coat blending." +
|
||||
"\nActs as a multiplier of the clear coat map mask value or as a direct mask value if no map is specified." +
|
||||
"\nThe map specifies clear coat mask in the red channel and clear coat smoothness in the green channel.");
|
||||
|
||||
public static GUIContent clearCoatSmoothnessText = EditorGUIUtility.TrTextContent("Smoothness",
|
||||
"Specifies the smoothness of the coating." +
|
||||
"\nActs as a multiplier of the clear coat map smoothness value or as a direct smoothness value if no map is specified.");
|
||||
}
|
||||
|
||||
public struct LitProperties
|
||||
{
|
||||
// Surface Option Props
|
||||
public MaterialProperty workflowMode;
|
||||
|
||||
// Surface Input Props
|
||||
public MaterialProperty metallic;
|
||||
public MaterialProperty specColor;
|
||||
public MaterialProperty metallicGlossMap;
|
||||
public MaterialProperty specGlossMap;
|
||||
public MaterialProperty smoothness;
|
||||
public MaterialProperty smoothnessMapChannel;
|
||||
public MaterialProperty bumpMapProp;
|
||||
public MaterialProperty bumpScaleProp;
|
||||
public MaterialProperty parallaxMapProp;
|
||||
public MaterialProperty parallaxScaleProp;
|
||||
public MaterialProperty occlusionStrength;
|
||||
public MaterialProperty occlusionMap;
|
||||
|
||||
// Advanced Props
|
||||
public MaterialProperty highlights;
|
||||
public MaterialProperty reflections;
|
||||
|
||||
public MaterialProperty clearCoat; // Enable/Disable dummy property
|
||||
public MaterialProperty clearCoatMap;
|
||||
public MaterialProperty clearCoatMask;
|
||||
public MaterialProperty clearCoatSmoothness;
|
||||
|
||||
public LitProperties(MaterialProperty[] properties)
|
||||
{
|
||||
// Surface Option Props
|
||||
workflowMode = BaseShaderGUI.FindProperty("_WorkflowMode", properties, false);
|
||||
// Surface Input Props
|
||||
metallic = BaseShaderGUI.FindProperty("_Metallic", properties);
|
||||
specColor = BaseShaderGUI.FindProperty("_SpecColor", properties, false);
|
||||
metallicGlossMap = BaseShaderGUI.FindProperty("_MetallicGlossMap", properties);
|
||||
specGlossMap = BaseShaderGUI.FindProperty("_SpecGlossMap", properties, false);
|
||||
smoothness = BaseShaderGUI.FindProperty("_Smoothness", properties, false);
|
||||
smoothnessMapChannel = BaseShaderGUI.FindProperty("_SmoothnessTextureChannel", properties, false);
|
||||
bumpMapProp = BaseShaderGUI.FindProperty("_BumpMap", properties, false);
|
||||
bumpScaleProp = BaseShaderGUI.FindProperty("_BumpScale", properties, false);
|
||||
parallaxMapProp = BaseShaderGUI.FindProperty("_ParallaxMap", properties, false);
|
||||
parallaxScaleProp = BaseShaderGUI.FindProperty("_Parallax", properties, false);
|
||||
occlusionStrength = BaseShaderGUI.FindProperty("_OcclusionStrength", properties, false);
|
||||
occlusionMap = BaseShaderGUI.FindProperty("_OcclusionMap", properties, false);
|
||||
// Advanced Props
|
||||
highlights = BaseShaderGUI.FindProperty("_SpecularHighlights", properties, false);
|
||||
reflections = BaseShaderGUI.FindProperty("_EnvironmentReflections", properties, false);
|
||||
|
||||
clearCoat = BaseShaderGUI.FindProperty("_ClearCoat", properties, false);
|
||||
clearCoatMap = BaseShaderGUI.FindProperty("_ClearCoatMap", properties, false);
|
||||
clearCoatMask = BaseShaderGUI.FindProperty("_ClearCoatMask", properties, false);
|
||||
clearCoatSmoothness = BaseShaderGUI.FindProperty("_ClearCoatSmoothness", properties, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Inputs(LitProperties properties, MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
DoMetallicSpecularArea(properties, materialEditor, material);
|
||||
BaseShaderGUI.DrawNormalArea(materialEditor, properties.bumpMapProp, properties.bumpScaleProp);
|
||||
|
||||
if (HeightmapAvailable(material))
|
||||
DoHeightmapArea(properties, materialEditor);
|
||||
|
||||
if (properties.occlusionMap != null)
|
||||
{
|
||||
materialEditor.TexturePropertySingleLine(Styles.occlusionText, properties.occlusionMap,
|
||||
properties.occlusionMap.textureValue != null ? properties.occlusionStrength : null);
|
||||
}
|
||||
|
||||
// Check that we have all the required properties for clear coat,
|
||||
// otherwise we will get null ref exception from MaterialEditor GUI helpers.
|
||||
if (ClearCoatAvailable(material))
|
||||
DoClearCoat(properties, materialEditor, material);
|
||||
}
|
||||
|
||||
private static bool ClearCoatAvailable(Material material)
|
||||
{
|
||||
return material.HasProperty("_ClearCoat")
|
||||
&& material.HasProperty("_ClearCoatMap")
|
||||
&& material.HasProperty("_ClearCoatMask")
|
||||
&& material.HasProperty("_ClearCoatSmoothness");
|
||||
}
|
||||
|
||||
private static bool HeightmapAvailable(Material material)
|
||||
{
|
||||
return material.HasProperty("_Parallax")
|
||||
&& material.HasProperty("_ParallaxMap");
|
||||
}
|
||||
|
||||
private static void DoHeightmapArea(LitProperties properties, MaterialEditor materialEditor)
|
||||
{
|
||||
materialEditor.TexturePropertySingleLine(Styles.heightMapText, properties.parallaxMapProp,
|
||||
properties.parallaxMapProp.textureValue != null ? properties.parallaxScaleProp : null);
|
||||
}
|
||||
|
||||
private static bool ClearCoatEnabled(Material material)
|
||||
{
|
||||
return material.HasProperty("_ClearCoat") && material.GetFloat("_ClearCoat") > 0.0;
|
||||
}
|
||||
|
||||
public static void DoClearCoat(LitProperties properties, MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
materialEditor.ShaderProperty(properties.clearCoat, Styles.clearCoatText);
|
||||
var coatEnabled = material.GetFloat("_ClearCoat") > 0.0;
|
||||
|
||||
EditorGUI.BeginDisabledGroup(!coatEnabled);
|
||||
{
|
||||
materialEditor.TexturePropertySingleLine(Styles.clearCoatMaskText, properties.clearCoatMap, properties.clearCoatMask);
|
||||
|
||||
EditorGUI.indentLevel += 2;
|
||||
|
||||
// Texture and HDR color controls
|
||||
materialEditor.ShaderProperty(properties.clearCoatSmoothness, Styles.clearCoatSmoothnessText);
|
||||
|
||||
EditorGUI.indentLevel -= 2;
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
public static void DoMetallicSpecularArea(LitProperties properties, MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
string[] smoothnessChannelNames;
|
||||
bool hasGlossMap = false;
|
||||
if (properties.workflowMode == null ||
|
||||
(WorkflowMode)properties.workflowMode.floatValue == WorkflowMode.Metallic)
|
||||
{
|
||||
hasGlossMap = properties.metallicGlossMap.textureValue != null;
|
||||
smoothnessChannelNames = Styles.metallicSmoothnessChannelNames;
|
||||
materialEditor.TexturePropertySingleLine(Styles.metallicMapText, properties.metallicGlossMap,
|
||||
hasGlossMap ? null : properties.metallic);
|
||||
}
|
||||
else
|
||||
{
|
||||
hasGlossMap = properties.specGlossMap.textureValue != null;
|
||||
smoothnessChannelNames = Styles.specularSmoothnessChannelNames;
|
||||
BaseShaderGUI.TextureColorProps(materialEditor, Styles.specularMapText, properties.specGlossMap,
|
||||
hasGlossMap ? null : properties.specColor);
|
||||
}
|
||||
DoSmoothness(materialEditor, material, properties.smoothness, properties.smoothnessMapChannel, smoothnessChannelNames);
|
||||
}
|
||||
|
||||
internal static bool IsOpaque(Material material)
|
||||
{
|
||||
bool opaque = true;
|
||||
if (material.HasProperty(Property.SurfaceType))
|
||||
opaque = ((BaseShaderGUI.SurfaceType)material.GetFloat(Property.SurfaceType) == BaseShaderGUI.SurfaceType.Opaque);
|
||||
return opaque;
|
||||
}
|
||||
|
||||
public static void DoSmoothness(MaterialEditor materialEditor, Material material, MaterialProperty smoothness, MaterialProperty smoothnessMapChannel, string[] smoothnessChannelNames)
|
||||
{
|
||||
EditorGUI.indentLevel += 2;
|
||||
|
||||
materialEditor.ShaderProperty(smoothness, Styles.smoothnessText);
|
||||
|
||||
if (smoothnessMapChannel != null) // smoothness channel
|
||||
{
|
||||
var opaque = IsOpaque(material);
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUI.showMixedValue = smoothnessMapChannel.hasMixedValue;
|
||||
if (opaque)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var smoothnessSource = (int)smoothnessMapChannel.floatValue;
|
||||
smoothnessSource = EditorGUILayout.Popup(Styles.smoothnessMapChannelText, smoothnessSource, smoothnessChannelNames);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
smoothnessMapChannel.floatValue = smoothnessSource;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
EditorGUILayout.Popup(Styles.smoothnessMapChannelText, 0, smoothnessChannelNames);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
EditorGUI.showMixedValue = false;
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
EditorGUI.indentLevel -= 2;
|
||||
}
|
||||
|
||||
public static SmoothnessMapChannel GetSmoothnessMapChannel(Material material)
|
||||
{
|
||||
int ch = (int)material.GetFloat("_SmoothnessTextureChannel");
|
||||
if (ch == (int)SmoothnessMapChannel.AlbedoAlpha)
|
||||
return SmoothnessMapChannel.AlbedoAlpha;
|
||||
|
||||
return SmoothnessMapChannel.SpecularMetallicAlpha;
|
||||
}
|
||||
|
||||
// (shared by all lit shaders, including shadergraph Lit Target and Lit.shader)
|
||||
internal static void SetupSpecularWorkflowKeyword(Material material, out bool isSpecularWorkflow)
|
||||
{
|
||||
isSpecularWorkflow = false; // default is metallic workflow
|
||||
if (material.HasProperty(Property.SpecularWorkflowMode))
|
||||
isSpecularWorkflow = ((WorkflowMode)material.GetFloat(Property.SpecularWorkflowMode)) == WorkflowMode.Specular;
|
||||
CoreUtils.SetKeyword(material, "_SPECULAR_SETUP", isSpecularWorkflow);
|
||||
}
|
||||
|
||||
// setup keywords for Lit.shader
|
||||
public static void SetMaterialKeywords(Material material)
|
||||
{
|
||||
SetupSpecularWorkflowKeyword(material, out bool isSpecularWorkFlow);
|
||||
|
||||
// Note: keywords must be based on Material value not on MaterialProperty due to multi-edit & material animation
|
||||
// (MaterialProperty value might come from renderer material property block)
|
||||
var specularGlossMap = isSpecularWorkFlow ? "_SpecGlossMap" : "_MetallicGlossMap";
|
||||
var hasGlossMap = material.GetTexture(specularGlossMap) != null;
|
||||
|
||||
CoreUtils.SetKeyword(material, "_METALLICSPECGLOSSMAP", hasGlossMap);
|
||||
|
||||
//if (material.HasProperty("_SpecularHighlights"))
|
||||
// CoreUtils.SetKeyword(material, "_SPECULARHIGHLIGHTS_OFF",
|
||||
// material.GetFloat("_SpecularHighlights") == 0.0f);
|
||||
//if (material.HasProperty("_EnvironmentReflections"))
|
||||
// CoreUtils.SetKeyword(material, "_ENVIRONMENTREFLECTIONS_OFF",
|
||||
// material.GetFloat("_EnvironmentReflections") == 0.0f);
|
||||
//if (material.HasProperty("_OcclusionMap"))
|
||||
// CoreUtils.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));
|
||||
|
||||
if (material.HasProperty("_ParallaxMap"))
|
||||
CoreUtils.SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap"));
|
||||
|
||||
if (material.HasProperty("_SmoothnessTextureChannel"))
|
||||
{
|
||||
var opaque = IsOpaque(material);
|
||||
CoreUtils.SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A",
|
||||
GetSmoothnessMapChannel(material) == SmoothnessMapChannel.AlbedoAlpha && opaque);
|
||||
}
|
||||
|
||||
// Clear coat keywords are independent to remove possiblity of invalid combinations.
|
||||
if (ClearCoatEnabled(material))
|
||||
{
|
||||
var hasMap = material.HasProperty("_ClearCoatMap") && material.GetTexture("_ClearCoatMap") != null;
|
||||
if (hasMap)
|
||||
{
|
||||
CoreUtils.SetKeyword(material, "_CLEARCOAT", false);
|
||||
CoreUtils.SetKeyword(material, "_CLEARCOATMAP", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CoreUtils.SetKeyword(material, "_CLEARCOAT", true);
|
||||
CoreUtils.SetKeyword(material, "_CLEARCOATMAP", false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CoreUtils.SetKeyword(material, "_CLEARCOAT", false);
|
||||
CoreUtils.SetKeyword(material, "_CLEARCOATMAP", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b33851187d4324530b9f7abfe14d0137
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Scripting.APIUpdating;
|
||||
|
||||
namespace UnityEditor.Rendering.Universal.ShaderGUI
|
||||
{
|
||||
public static class SimpleLitGUI
|
||||
{
|
||||
public enum SpecularSource
|
||||
{
|
||||
SpecularTextureAndColor,
|
||||
NoSpecular
|
||||
}
|
||||
|
||||
public enum SmoothnessMapChannel
|
||||
{
|
||||
SpecularAlpha,
|
||||
AlbedoAlpha,
|
||||
}
|
||||
|
||||
public static class Styles
|
||||
{
|
||||
public static GUIContent specularMapText =
|
||||
EditorGUIUtility.TrTextContent("Specular Map", "Designates a Specular Map and specular color determining the apperance of reflections on this Material's surface.");
|
||||
}
|
||||
|
||||
public struct SimpleLitProperties
|
||||
{
|
||||
// Surface Input Props
|
||||
public MaterialProperty specColor;
|
||||
public MaterialProperty specGlossMap;
|
||||
public MaterialProperty specHighlights;
|
||||
public MaterialProperty smoothnessMapChannel;
|
||||
public MaterialProperty smoothness;
|
||||
public MaterialProperty bumpMapProp;
|
||||
|
||||
public SimpleLitProperties(MaterialProperty[] properties)
|
||||
{
|
||||
// Surface Input Props
|
||||
specColor = BaseShaderGUI.FindProperty("_SpecColor", properties);
|
||||
specGlossMap = BaseShaderGUI.FindProperty("_SpecGlossMap", properties, false);
|
||||
specHighlights = BaseShaderGUI.FindProperty("_SpecularHighlights", properties, false);
|
||||
smoothnessMapChannel = BaseShaderGUI.FindProperty("_SmoothnessSource", properties, false);
|
||||
smoothness = BaseShaderGUI.FindProperty("_Smoothness", properties, false);
|
||||
bumpMapProp = BaseShaderGUI.FindProperty("_BumpMap", properties, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Inputs(SimpleLitProperties properties, MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
DoSpecularArea(properties, materialEditor, material);
|
||||
BaseShaderGUI.DrawNormalArea(materialEditor, properties.bumpMapProp);
|
||||
}
|
||||
|
||||
public static void Advanced(SimpleLitProperties properties)
|
||||
{
|
||||
//SpecularSource specularSource = (SpecularSource)properties.specHighlights.floatValue;
|
||||
//EditorGUI.BeginChangeCheck();
|
||||
//EditorGUI.showMixedValue = properties.specHighlights.hasMixedValue;
|
||||
//bool enabled = EditorGUILayout.Toggle(LitGUI.Styles.highlightsText, specularSource == SpecularSource.SpecularTextureAndColor);
|
||||
//if (EditorGUI.EndChangeCheck())
|
||||
// properties.specHighlights.floatValue = enabled ? (float)SpecularSource.SpecularTextureAndColor : (float)SpecularSource.NoSpecular;
|
||||
//EditorGUI.showMixedValue = false;
|
||||
}
|
||||
|
||||
public static void DoSpecularArea(SimpleLitProperties properties, MaterialEditor materialEditor, Material material)
|
||||
{
|
||||
//SpecularSource specSource = (SpecularSource)properties.specHighlights.floatValue;
|
||||
//EditorGUI.BeginDisabledGroup(specSource == SpecularSource.NoSpecular);
|
||||
BaseShaderGUI.TextureColorProps(materialEditor, Styles.specularMapText, properties.specGlossMap, properties.specColor, true);
|
||||
LitGUI.DoSmoothness(materialEditor, material, properties.smoothness, properties.smoothnessMapChannel, LitGUI.Styles.specularSmoothnessChannelNames);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
public static void SetMaterialKeywords(Material material)
|
||||
{
|
||||
UpdateMaterialSpecularSource(material);
|
||||
}
|
||||
|
||||
private static void UpdateMaterialSpecularSource(Material material)
|
||||
{
|
||||
var opaque = ((BaseShaderGUI.SurfaceType)material.GetFloat("_Surface") ==
|
||||
BaseShaderGUI.SurfaceType.Opaque);
|
||||
//SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecularHighlights");
|
||||
//if (specSource == SpecularSource.NoSpecular)
|
||||
//{
|
||||
// CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", false);
|
||||
// CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", false);
|
||||
// CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false);
|
||||
//}
|
||||
//else
|
||||
{
|
||||
//var smoothnessSource = (SmoothnessMapChannel)material.GetFloat("_SmoothnessSource");
|
||||
bool hasMap = material.GetTexture("_SpecGlossMap");
|
||||
CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", hasMap);
|
||||
CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", !hasMap);
|
||||
// if (opaque)
|
||||
// CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", smoothnessSource == SmoothnessMapChannel.AlbedoAlpha);
|
||||
// else
|
||||
// CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false);
|
||||
|
||||
string color;
|
||||
// if (smoothnessSource != SmoothnessMapChannel.AlbedoAlpha || !opaque)
|
||||
color = "_SpecColor";
|
||||
//else
|
||||
// color = "_BaseColor";
|
||||
|
||||
var col = material.GetColor(color);
|
||||
float smoothness = material.GetFloat("_Smoothness");
|
||||
if (smoothness != col.a)
|
||||
{
|
||||
col.a = smoothness;
|
||||
material.SetColor(color, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f2b965a0132c42a4b52332918ed154a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue