This commit is contained in:
2026-11-24 15:51:02 +01:00
parent cca4d73e41
commit f4aa17114a
22092 changed files with 5042406 additions and 0 deletions
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5faac1f019b9d88418c3721b7845b4d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,615 @@
using UnityEngine;
using UnityEditorInternal;
using System.Linq;
using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
/// <summary>
/// Editor script for the particle material inspector.
/// </summary>
public static class ParticleGUI
{
/// <summary>
/// The available color modes.
/// Controls how the Particle color and the Material color blend together.
/// </summary>
public enum ColorMode
{
/// <summary>
/// Use this to select multiply mode.
/// </summary>
Multiply,
/// <summary>
/// Use this to select additive mode.
/// </summary>
Additive,
/// <summary>
/// Use this to select subtractive mode.
/// </summary>
Subtractive,
/// <summary>
/// Use this to select overlay mode.
/// </summary>
Overlay,
/// <summary>
/// Use this to select color mode.
/// </summary>
Color,
/// <summary>
/// Use this to select difference mode.
/// </summary>
Difference
}
/// <summary>
/// Container for the text and tooltips used to display the shader.
/// </summary>
public static class Styles
{
/// <summary>
/// The text and tooltip color mode.
/// </summary>
public static GUIContent colorMode = EditorGUIUtility.TrTextContent("Color Mode",
"Controls how the Particle color and the Material color blend together.");
/// <summary>
/// The text and tooltip flip-book blending.
/// </summary>
public static GUIContent flipbookMode = EditorGUIUtility.TrTextContent("Flip-Book Blending",
"Blends the frames in a flip-book together in a smooth animation.");
/// <summary>
/// The text and tooltip soft particles.
/// </summary>
public static GUIContent softParticlesEnabled = EditorGUIUtility.TrTextContent("Soft Particles",
"Makes particles fade out when they get close to intersecting with the surface of other geometry in the depth buffer.");
/// <summary>
/// The text and tooltip soft particles surface fade.
/// </summary>
public static GUIContent softParticlesFadeText = EditorGUIUtility.TrTextContent("Surface Fade");
/// <summary>
/// The text and tooltip soft particles near fade distance.
/// </summary>
public static GUIContent softParticlesNearFadeDistanceText =
EditorGUIUtility.TrTextContent("Near",
"The distance from the other surface where the particle is completely transparent.");
/// <summary>
/// The text and tooltip soft particles far fade distance.
/// </summary>
public static GUIContent softParticlesFarFadeDistanceText =
EditorGUIUtility.TrTextContent("Far",
"The distance from the other surface where the particle is completely opaque.");
/// <summary>
/// The text and tooltip camera fading.
/// </summary>
public static GUIContent cameraFadingEnabled = EditorGUIUtility.TrTextContent("Camera Fading",
"Makes particles fade out when they get close to the camera.");
/// <summary>
/// The text and tooltip camera fading distance.
/// </summary>
public static GUIContent cameraFadingDistanceText = EditorGUIUtility.TrTextContent("Distance");
/// <summary>
/// The text and tooltip camera fading near distance.
/// </summary>
public static GUIContent cameraNearFadeDistanceText =
EditorGUIUtility.TrTextContent("Near",
"The distance from the camera where the particle is completely transparent.");
/// <summary>
/// The text and tooltip camera fading far distance.
/// </summary>
public static GUIContent cameraFarFadeDistanceText =
EditorGUIUtility.TrTextContent("Far", "The distance from the camera where the particle is completely opaque.");
/// <summary>
/// The text and tooltip distortion.
/// </summary>
public static GUIContent distortionEnabled = EditorGUIUtility.TrTextContent("Distortion",
"Creates a distortion effect by making particles perform refraction with the objects drawn before them.");
/// <summary>
/// The text and tooltip distortion strength.
/// </summary>
public static GUIContent distortionStrength = EditorGUIUtility.TrTextContent("Strength",
"Controls how much the Particle distorts the background. ");
/// <summary>
/// The text and tooltip distortion blend.
/// </summary>
public static GUIContent distortionBlend = EditorGUIUtility.TrTextContent("Blend",
"Controls how visible the distortion effect is. At 0, there’s no visible distortion. At 1, only the distortion effect is visible, not the background.");
/// <summary>
/// The text and tooltip for vertex streams.
/// </summary>
public static GUIContent VertexStreams = EditorGUIUtility.TrTextContent("Vertex Streams",
"List detailing the expected layout of data sent to the shader from the particle system.");
/// <summary>
/// The string for position vertex stream.
/// </summary>
public static string streamPositionText = "Position (POSITION.xyz)";
/// <summary>
/// The string for normal vertex stream.
/// </summary>
public static string streamNormalText = "Normal (NORMAL.xyz)";
/// <summary>
/// The string for color vertex stream.
/// </summary>
public static string streamColorText = "Color (COLOR.xyzw | INSTANCED0.xyzw)";
/// <summary>
/// The string for UV vertex stream.
/// </summary>
public static string streamUVText = "UV (TEXCOORD0.xy)";
/// <summary>
/// The string for UV2 vertex stream.
/// </summary>
public static string streamUV2Text = "UV2 (TEXCOORD0.zw)";
/// <summary>
/// The string for AnimBlend Texcoord1 vertex stream.
/// </summary>
public static string streamAnimBlendText = "AnimBlend (TEXCOORD1.x)";
/// <summary>
/// The string for AnimBlend Instanced1 vertex stream.
/// </summary>
public static string streamAnimFrameText = "AnimFrame (INSTANCED1.x)";
/// <summary>
/// The string for tangent vertex stream.
/// </summary>
public static string streamTangentText = "Tangent (TANGENT.xyzw)";
/// <summary>
/// The text and tooltip for the vertex stream fix now GUI.
/// </summary>
public static GUIContent streamApplyToAllSystemsText = EditorGUIUtility.TrTextContent("Fix Now",
"Apply the vertex stream layout to all Particle Systems using this material");
/// <summary>
/// The string for applying custom vertex streams from material.
/// </summary>
public static string undoApplyCustomVertexStreams = L10n.Tr("Apply custom vertex streams from material");
/// <summary>
/// The vertex stream icon.
/// </summary>
public static GUIStyle vertexStreamIcon = new GUIStyle();
}
private static ReorderableList vertexStreamList;
/// <summary>
/// Container for the properties used in the <c>ParticleGUI</c> editor script.
/// </summary>
public struct ParticleProperties
{
// Surface Option Props
/// <summary>
/// The MaterialProperty for color mode.
/// </summary>
public MaterialProperty colorMode;
// Advanced Props
/// <summary>
/// The MaterialProperty for flip-book blending.
/// </summary>
public MaterialProperty flipbookMode;
/// <summary>
/// The MaterialProperty for soft particles enabled.
/// </summary>
public MaterialProperty softParticlesEnabled;
/// <summary>
/// The MaterialProperty for camera fading.
/// </summary>
public MaterialProperty cameraFadingEnabled;
/// <summary>
/// The MaterialProperty for distortion enabled.
/// </summary>
public MaterialProperty distortionEnabled;
/// <summary>
/// The MaterialProperty for soft particles near fade distance.
/// </summary>
public MaterialProperty softParticlesNearFadeDistance;
/// <summary>
/// The MaterialProperty for soft particles far fade distance.
/// </summary>
public MaterialProperty softParticlesFarFadeDistance;
/// <summary>
/// The MaterialProperty for camera fading near distance.
/// </summary>
public MaterialProperty cameraNearFadeDistance;
/// <summary>
/// The MaterialProperty for camera fading far distance.
/// </summary>
public MaterialProperty cameraFarFadeDistance;
/// <summary>
/// The MaterialProperty for distortion blend.
/// </summary>
public MaterialProperty distortionBlend;
/// <summary>
/// The MaterialProperty for distortion strength.
/// </summary>
public MaterialProperty distortionStrength;
/// <summary>
/// Constructor for the <c>ParticleProperties</c> container struct.
/// </summary>
/// <param name="properties"></param>
public ParticleProperties(MaterialProperty[] properties)
{
// Surface Option Props
colorMode = BaseShaderGUI.FindProperty("_ColorMode", properties, false);
// Advanced Props
flipbookMode = BaseShaderGUI.FindProperty("_FlipbookBlending", properties);
softParticlesEnabled = BaseShaderGUI.FindProperty("_SoftParticlesEnabled", properties);
cameraFadingEnabled = BaseShaderGUI.FindProperty("_CameraFadingEnabled", properties);
distortionEnabled = BaseShaderGUI.FindProperty("_DistortionEnabled", properties, false);
softParticlesNearFadeDistance = BaseShaderGUI.FindProperty("_SoftParticlesNearFadeDistance", properties);
softParticlesFarFadeDistance = BaseShaderGUI.FindProperty("_SoftParticlesFarFadeDistance", properties);
cameraNearFadeDistance = BaseShaderGUI.FindProperty("_CameraNearFadeDistance", properties);
cameraFarFadeDistance = BaseShaderGUI.FindProperty("_CameraFarFadeDistance", properties);
distortionBlend = BaseShaderGUI.FindProperty("_DistortionBlend", properties, false);
distortionStrength = BaseShaderGUI.FindProperty("_DistortionStrength", properties, false);
}
}
/// <summary>
/// Sets up the material with correct keywords based on the color mode.
/// </summary>
/// <param name="material">The material to use.</param>
public static void SetupMaterialWithColorMode(Material material)
{
var colorMode = (ColorMode)material.GetFloat("_ColorMode");
switch (colorMode)
{
case ColorMode.Multiply:
material.DisableKeyword("_COLOROVERLAY_ON");
material.DisableKeyword("_COLORCOLOR_ON");
material.DisableKeyword("_COLORADDSUBDIFF_ON");
break;
case ColorMode.Overlay:
material.DisableKeyword("_COLORCOLOR_ON");
material.DisableKeyword("_COLORADDSUBDIFF_ON");
material.EnableKeyword("_COLOROVERLAY_ON");
break;
case ColorMode.Color:
material.DisableKeyword("_COLOROVERLAY_ON");
material.DisableKeyword("_COLORADDSUBDIFF_ON");
material.EnableKeyword("_COLORCOLOR_ON");
break;
case ColorMode.Difference:
material.DisableKeyword("_COLOROVERLAY_ON");
material.DisableKeyword("_COLORCOLOR_ON");
material.EnableKeyword("_COLORADDSUBDIFF_ON");
material.SetVector("_BaseColorAddSubDiff", new Vector4(-1.0f, 1.0f, 0.0f, 0.0f));
break;
case ColorMode.Additive:
material.DisableKeyword("_COLOROVERLAY_ON");
material.DisableKeyword("_COLORCOLOR_ON");
material.EnableKeyword("_COLORADDSUBDIFF_ON");
material.SetVector("_BaseColorAddSubDiff", new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
break;
case ColorMode.Subtractive:
material.DisableKeyword("_COLOROVERLAY_ON");
material.DisableKeyword("_COLORCOLOR_ON");
material.EnableKeyword("_COLORADDSUBDIFF_ON");
material.SetVector("_BaseColorAddSubDiff", new Vector4(-1.0f, 0.0f, 0.0f, 0.0f));
break;
}
}
/// <summary>
/// Draws the fading options GUI.
/// </summary>
/// <param name="material">The material to use.</param>
/// <param name="materialEditor">The material editor to use.</param>
/// <param name="properties">The particle properties to use.</param>
public static void FadingOptions(Material material, MaterialEditor materialEditor, ParticleProperties properties)
{
// Z write doesn't work with fading
bool hasZWrite = (material.GetFloat("_ZWrite") > 0.0f);
if (!hasZWrite)
{
// Soft Particles
{
materialEditor.ShaderProperty(properties.softParticlesEnabled, Styles.softParticlesEnabled);
if (properties.softParticlesEnabled.floatValue >= 0.5f)
{
UniversalRenderPipelineAsset urpAsset = UniversalRenderPipeline.asset;
if (urpAsset != null && !urpAsset.supportsCameraDepthTexture)
{
GUIStyle warnStyle = new GUIStyle(GUI.skin.label);
warnStyle.fontStyle = FontStyle.BoldAndItalic;
warnStyle.wordWrap = true;
EditorGUILayout.HelpBox("Soft Particles require depth texture. Please enable \"Depth Texture\" in the Universal Render Pipeline settings.", MessageType.Warning);
}
EditorGUI.indentLevel++;
BaseShaderGUI.TwoFloatSingleLine(Styles.softParticlesFadeText,
properties.softParticlesNearFadeDistance,
Styles.softParticlesNearFadeDistanceText,
properties.softParticlesFarFadeDistance,
Styles.softParticlesFarFadeDistanceText,
materialEditor);
EditorGUI.indentLevel--;
}
}
// Camera Fading
{
materialEditor.ShaderProperty(properties.cameraFadingEnabled, Styles.cameraFadingEnabled);
if (properties.cameraFadingEnabled.floatValue >= 0.5f)
{
EditorGUI.indentLevel++;
BaseShaderGUI.TwoFloatSingleLine(Styles.cameraFadingDistanceText,
properties.cameraNearFadeDistance,
Styles.cameraNearFadeDistanceText,
properties.cameraFarFadeDistance,
Styles.cameraFarFadeDistanceText,
materialEditor);
EditorGUI.indentLevel--;
}
}
// Distortion
if (properties.distortionEnabled != null)
{
materialEditor.ShaderProperty(properties.distortionEnabled, Styles.distortionEnabled);
if (properties.distortionEnabled.floatValue >= 0.5f)
{
EditorGUI.indentLevel++;
materialEditor.ShaderProperty(properties.distortionStrength, Styles.distortionStrength);
materialEditor.ShaderProperty(properties.distortionBlend, Styles.distortionBlend);
EditorGUI.indentLevel--;
}
}
EditorGUI.showMixedValue = false;
}
}
/// <summary>
/// Draws the vertex streams area.
/// </summary>
/// <param name="material">The material to use.</param>
/// <param name="renderers">List of particle system renderers.</param>
/// <param name="useLighting">Marks whether the renderers uses lighting or not.</param>
public static void DoVertexStreamsArea(Material material, List<ParticleSystemRenderer> renderers, bool useLighting = false)
{
EditorGUILayout.Space();
// Display list of streams required to make this shader work
bool useNormalMap = false;
bool useFlipbookBlending = (material.GetFloat("_FlipbookBlending") > 0.0f);
if (material.HasProperty("_BumpMap"))
useNormalMap = material.GetTexture("_BumpMap");
bool useGPUInstancing = ShaderUtil.HasProceduralInstancing(material.shader);
// Build the list of expected vertex streams
List<ParticleSystemVertexStream> streams = new List<ParticleSystemVertexStream>();
List<string> streamList = new List<string>();
streams.Add(ParticleSystemVertexStream.Position);
streamList.Add(Styles.streamPositionText);
if (useLighting || useNormalMap)
{
streams.Add(ParticleSystemVertexStream.Normal);
streamList.Add(Styles.streamNormalText);
if (useNormalMap)
{
streams.Add(ParticleSystemVertexStream.Tangent);
streamList.Add(Styles.streamTangentText);
}
}
streams.Add(ParticleSystemVertexStream.Color);
streamList.Add(Styles.streamColorText);
streams.Add(ParticleSystemVertexStream.UV);
streamList.Add(Styles.streamUVText);
List<ParticleSystemVertexStream> instancedStreams = new List<ParticleSystemVertexStream>(streams);
if (useFlipbookBlending)
{
streams.Add(ParticleSystemVertexStream.UV2);
streamList.Add(Styles.streamUV2Text);
streams.Add(ParticleSystemVertexStream.AnimBlend);
streamList.Add(Styles.streamAnimBlendText);
}
instancedStreams.Add(ParticleSystemVertexStream.AnimFrame);
streamList.Add(Styles.streamAnimFrameText);
vertexStreamList = new ReorderableList(streamList, typeof(string), false, true, false, false);
vertexStreamList.drawHeaderCallback = (Rect rect) =>
{
EditorGUI.LabelField(rect, Styles.VertexStreams);
};
vertexStreamList.DoLayoutList();
// Display a warning if any renderers have incorrect vertex streams
string Warnings = "";
List<ParticleSystemVertexStream> rendererStreams = new List<ParticleSystemVertexStream>();
foreach (ParticleSystemRenderer renderer in renderers)
{
renderer.GetActiveVertexStreams(rendererStreams);
bool streamsValid;
if (useGPUInstancing && renderer.renderMode == ParticleSystemRenderMode.Mesh && renderer.supportsMeshInstancing)
streamsValid = CompareVertexStreams(rendererStreams, instancedStreams);
else
streamsValid = CompareVertexStreams(rendererStreams, streams);
if (!streamsValid)
Warnings += "-" + renderer.name + "\n";
}
if (!string.IsNullOrEmpty(Warnings))
{
EditorGUILayout.HelpBox(
"The following Particle System Renderers are using this material with incorrect Vertex Streams:\n" +
Warnings, MessageType.Error, true);
// Set the streams on all systems using this material
if (GUILayout.Button(Styles.streamApplyToAllSystemsText, EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
Undo.RecordObjects(renderers.Where(r => r != null).ToArray(), Styles.undoApplyCustomVertexStreams);
foreach (ParticleSystemRenderer renderer in renderers)
{
if (useGPUInstancing && renderer.renderMode == ParticleSystemRenderMode.Mesh && renderer.supportsMeshInstancing)
renderer.SetActiveVertexStreams(instancedStreams);
else
renderer.SetActiveVertexStreams(streams);
}
}
}
}
private static bool CompareVertexStreams(IEnumerable<ParticleSystemVertexStream> a, IEnumerable<ParticleSystemVertexStream> b)
{
var differenceA = a.Except(b);
var differenceB = b.Except(a);
var difference = differenceA.Union(differenceB).Distinct();
if (!difference.Any())
return true;
// If normals are the only difference, ignore them, because the default particle streams include normals, to make it easy for users to switch between lit and unlit
if (difference.Count() == 1)
{
if (difference.First() == ParticleSystemVertexStream.Normal)
return true;
}
return false;
}
/// <summary>
/// Sets up the keywords for the material and shader.
/// </summary>
/// <param name="material">The material to use.</param>
public static void SetMaterialKeywords(Material material)
{
// Setup particle + material color blending
SetupMaterialWithColorMode(material);
// Is the material transparent, this is set in BaseShaderGUI
bool isTransparent = material.GetTag("RenderType", false) == "Transparent";
// Z write doesn't work with distortion/fading
bool hasZWrite = (material.GetFloat("_ZWrite") > 0.0f);
// Flipbook blending
if (material.HasProperty("_FlipbookBlending"))
{
var useFlipbookBlending = (material.GetFloat("_FlipbookBlending") > 0.0f);
CoreUtils.SetKeyword(material, "_FLIPBOOKBLENDING_ON", useFlipbookBlending);
}
// Soft particles
var useSoftParticles = false;
if (material.HasProperty("_SoftParticlesEnabled"))
{
useSoftParticles = (material.GetFloat("_SoftParticlesEnabled") > 0.0f && isTransparent);
if (useSoftParticles)
{
var softParticlesNearFadeDistance = material.GetFloat("_SoftParticlesNearFadeDistance");
var softParticlesFarFadeDistance = material.GetFloat("_SoftParticlesFarFadeDistance");
// clamp values
if (softParticlesNearFadeDistance < 0.0f)
{
softParticlesNearFadeDistance = 0.0f;
material.SetFloat("_SoftParticlesNearFadeDistance", 0.0f);
}
if (softParticlesFarFadeDistance < 0.0f)
{
softParticlesFarFadeDistance = 0.0f;
material.SetFloat("_SoftParticlesFarFadeDistance", 0.0f);
}
// set keywords
material.SetVector("_SoftParticleFadeParams",
new Vector4(softParticlesNearFadeDistance,
1.0f / (softParticlesFarFadeDistance - softParticlesNearFadeDistance), 0.0f, 0.0f));
}
else
{
material.SetVector("_SoftParticleFadeParams", new Vector4(0.0f, 0.0f, 0.0f, 0.0f));
}
CoreUtils.SetKeyword(material, "_SOFTPARTICLES_ON", useSoftParticles);
}
// Camera fading
var useCameraFading = false;
if (material.HasProperty("_CameraFadingEnabled") && isTransparent)
{
useCameraFading = (material.GetFloat("_CameraFadingEnabled") > 0.0f);
if (useCameraFading)
{
var cameraNearFadeDistance = material.GetFloat("_CameraNearFadeDistance");
var cameraFarFadeDistance = material.GetFloat("_CameraFarFadeDistance");
// clamp values
if (cameraNearFadeDistance < 0.0f)
{
cameraNearFadeDistance = 0.0f;
material.SetFloat("_CameraNearFadeDistance", 0.0f);
}
if (cameraFarFadeDistance < 0.0f)
{
cameraFarFadeDistance = 0.0f;
material.SetFloat("_CameraFarFadeDistance", 0.0f);
}
// set keywords
material.SetVector("_CameraFadeParams",
new Vector4(cameraNearFadeDistance, 1.0f / (cameraFarFadeDistance - cameraNearFadeDistance),
0.0f, 0.0f));
}
else
{
material.SetVector("_CameraFadeParams", new Vector4(0.0f, Mathf.Infinity, 0.0f, 0.0f));
}
}
// Distortion
if (material.HasProperty("_DistortionEnabled"))
{
var useDistortion = (material.GetFloat("_DistortionEnabled") > 0.0f) && isTransparent;
CoreUtils.SetKeyword(material, "_DISTORTION_ON", useDistortion);
if (useDistortion)
material.SetFloat("_DistortionStrengthScaled", material.GetFloat("_DistortionStrength") * 0.1f);
}
var useFading = useCameraFading && !hasZWrite;
CoreUtils.SetKeyword(material, "_FADING_ON", useFading);
}
}
} // namespace UnityEditor
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2b54c0ca113574ce495f3b706648b6d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,86 @@
using System;
using UnityEditor.Rendering.Universal;
using UnityEditor.Rendering.Universal.ShaderGUI;
using UnityEngine;
using static Unity.Rendering.Universal.ShaderUtils;
namespace UnityEditor
{
// Used for ShaderGraph Lit shaders
class ShaderGraphLitGUI : BaseShaderGUI
{
public MaterialProperty workflowMode;
MaterialProperty[] properties;
// collect properties from the material properties
public override void FindProperties(MaterialProperty[] properties)
{
// save off the list of all properties for shadergraph
this.properties = properties;
var material = materialEditor?.target as Material;
if (material == null)
return;
base.FindProperties(properties);
workflowMode = BaseShaderGUI.FindProperty(Property.SpecularWorkflowMode, properties, false);
}
public static void UpdateMaterial(Material material, MaterialUpdateType updateType)
{
// newly created materials should initialize the globalIlluminationFlags (default is off)
if (updateType == MaterialUpdateType.CreatedNewMaterial)
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
bool automaticRenderQueue = GetAutomaticQueueControlSetting(material);
BaseShaderGUI.UpdateMaterialSurfaceOptions(material, automaticRenderQueue);
LitGUI.SetupSpecularWorkflowKeyword(material, out bool isSpecularWorkflow);
BaseShaderGUI.UpdateMotionVectorKeywordsAndPass(material);
#if ENABLE_VR && ENABLE_XR_MODULE
BaseShaderGUI.UpdateXRMotionVectorKeywordsAndPass(material);
#endif
}
public override void ValidateMaterial(Material material)
{
if (material == null)
throw new ArgumentNullException("material");
UpdateMaterial(material, MaterialUpdateType.ModifiedMaterial);
}
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
if (workflowMode != null)
DoPopup(LitGUI.Styles.workflowModeText, workflowMode, Enum.GetNames(typeof(LitGUI.WorkflowMode)));
base.DrawSurfaceOptions(material);
}
// material main surface inputs
public override void DrawSurfaceInputs(Material material)
{
DrawShaderGraphProperties(properties);
}
public override void DrawAdvancedOptions(Material material)
{
// Always show the queue control field. Only show the render queue field if queue control is set to user override
DoPopup(Styles.queueControl, queueControlProp, Styles.queueControlNames);
if (material.HasProperty(Property.QueueControl) && material.GetFloat(Property.QueueControl) == (float)QueueControl.UserOverride)
materialEditor.RenderQueueField();
base.DrawAdvancedOptions(material);
// ignore emission color for shadergraphs, because shadergraphs don't have a hard-coded emission property, it's up to the user
materialEditor.DoubleSidedGIField();
materialEditor.LightmapEmissionFlagsProperty(0, enabled: true, ignoreEmissionColor: true);
}
}
} // namespace UnityEditor
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1efcaa82db5b5604b861d10e36958714
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
using UnityEngine;
namespace UnityEditor.Rendering.Universal
{
internal class ShaderGraphTerrainLitGUI : TerrainLitShaderGUI
{
protected override uint materialFilter => (uint)(Expandable.SurfaceOptions | Expandable.SurfaceInputs);
private MaterialProperty[] properties;
public override void FindProperties(MaterialProperty[] properties)
{
this.properties = properties;
var material = materialEditor?.target as Material;
if (material == null)
return;
base.FindProperties(properties);
FindMaterialProperties(properties);
}
public override void DrawSurfaceInputs(Material material)
{
DrawShaderGraphProperties(properties);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a48458ea708872f44bf79d4c9e33ff07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
using System;
using UnityEngine;
using UnityEditor.Rendering.Universal;
using static Unity.Rendering.Universal.ShaderUtils;
namespace UnityEditor
{
// Used for ShaderGraph Unlit shaders
class ShaderGraphUnlitGUI : BaseShaderGUI
{
MaterialProperty[] properties;
// collect properties from the material properties
public override void FindProperties(MaterialProperty[] properties)
{
// save off the list of all properties for shadergraph
this.properties = properties;
base.FindProperties(properties);
}
public static void UpdateMaterial(Material material, MaterialUpdateType updateType)
{
bool automaticRenderQueue = GetAutomaticQueueControlSetting(material);
BaseShaderGUI.UpdateMaterialSurfaceOptions(material, automaticRenderQueue);
BaseShaderGUI.UpdateMotionVectorKeywordsAndPass(material);
#if ENABLE_VR && ENABLE_XR_MODULE
BaseShaderGUI.UpdateXRMotionVectorKeywordsAndPass(material);
#endif
}
public override void ValidateMaterial(Material material)
{
UpdateMaterial(material, MaterialUpdateType.ModifiedMaterial);
}
// material main surface inputs
public override void DrawSurfaceInputs(Material material)
{
DrawShaderGraphProperties(properties);
}
public override void DrawAdvancedOptions(Material material)
{
// Always show the queue control field. Only show the render queue field if queue control is set to user override
DoPopup(Styles.queueControl, queueControlProp, Styles.queueControlNames);
if (material.HasProperty(Property.QueueControl) && material.GetFloat(Property.QueueControl) == (float)QueueControl.UserOverride)
materialEditor.RenderQueueField();
base.DrawAdvancedOptions(material);
materialEditor.DoubleSidedGIField();
}
}
} // namespace UnityEditor
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5b95b9b576115ac4bbf3b1ea150ab3c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
using UnityEngine;
namespace UnityEditor
{
// Used for ShaderGraph Sprite shaders
class ShaderGraphSpriteGUI : BaseShaderGUI
{
protected override uint materialFilter => uint.MaxValue & ~(uint)Expandable.SurfaceOptions;
MaterialProperty[] properties;
// collect properties from the material properties
public override void FindProperties(MaterialProperty[] properties)
{
// save off the list of all properties for shadergraph
this.properties = properties;
var material = materialEditor?.target as Material;
if (material == null)
return;
base.FindProperties(properties);
}
public override void DrawSurfaceInputs(Material material)
{
DrawShaderGraphProperties(properties);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 478c8ec8473e14f4597a729050dc56f3
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 44979452441cd45d5a88ff530647528f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,92 @@
using System;
using UnityEngine;
using UnityEditor.Rendering.Universal;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
internal class BakedLitShader : BaseShaderGUI
{
// Properties
private BakedLitGUI.BakedLitProperties shadingModelProperties;
// collect properties from the material properties
public override void FindProperties(MaterialProperty[] properties)
{
base.FindProperties(properties);
shadingModelProperties = new BakedLitGUI.BakedLitProperties(properties);
}
// material changed check
public override void ValidateMaterial(Material material)
{
SetMaterialKeywords(material);
}
// material main surface options
public override void DrawSurfaceOptions(Material material)
{
if (material == null)
throw new ArgumentNullException("material");
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
base.DrawSurfaceOptions(material);
}
// material main surface inputs
public override void DrawSurfaceInputs(Material material)
{
base.DrawSurfaceInputs(material);
BakedLitGUI.Inputs(shadingModelProperties, materialEditor);
DrawTileOffset(materialEditor, baseMapProp);
}
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");
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 8176ef27c50d1485084b4ab6f1554353
timeCreated: 1504689095
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
internal 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);
}
#if URP_SCREEN_SPACE_REFLECTION
if (litProperties.screenSpaceReflections != null)
materialEditor.ShaderProperty(litProperties.screenSpaceReflections, LitGUI.Styles.screenSpaceReflectionsText);
if (litProperties.screenSpaceReflectionsContributeTransparent != null)
{
bool isTransparent = material.renderQueue >= (int)RenderQueue.Transparent;
if (isTransparent)
materialEditor.ShaderProperty(litProperties.screenSpaceReflectionsContributeTransparent, LitGUI.Styles.screenSpaceReflectionsContributeTransparentText);
}
#endif
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);
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a72ab9c46e7987c40bcd48bcf9e7c0dd
timeCreated: 1504689095
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
internal class ParticlesLitShader : BaseShaderGUI
{
// Properties
private LitGUI.LitProperties litProperties;
private ParticleGUI.ParticleProperties particleProps;
// List of renderers using this material in the scene, used for validating vertex streams
List<ParticleSystemRenderer> m_RenderersUsingThisMaterial = new List<ParticleSystemRenderer>();
public override void FindProperties(MaterialProperty[] properties)
{
base.FindProperties(properties);
litProperties = new LitGUI.LitProperties(properties);
particleProps = new ParticleGUI.ParticleProperties(properties);
}
public override void ValidateMaterial(Material material)
{
SetMaterialKeywords(material, LitGUI.SetMaterialKeywords, ParticleGUI.SetMaterialKeywords);
}
public override void DrawSurfaceOptions(Material material)
{
base.DrawSurfaceOptions(material);
DoPopup(ParticleGUI.Styles.colorMode, particleProps.colorMode, Enum.GetNames(typeof(ParticleGUI.ColorMode)));
}
public override void DrawSurfaceInputs(Material material)
{
base.DrawSurfaceInputs(material);
LitGUI.Inputs(litProperties, materialEditor, material);
DrawEmissionProperties(material, true);
}
public override void DrawAdvancedOptions(Material material)
{
materialEditor.ShaderProperty(particleProps.flipbookMode, ParticleGUI.Styles.flipbookMode);
ParticleGUI.FadingOptions(material, materialEditor, particleProps);
ParticleGUI.DoVertexStreamsArea(material, m_RenderersUsingThisMaterial, true);
DrawQueueOffsetField();
}
public override void OnOpenGUI(Material material, MaterialEditor materialEditor)
{
CacheRenderersUsingThisMaterial(material);
base.OnOpenGUI(material, materialEditor);
}
void CacheRenderersUsingThisMaterial(Material material)
{
m_RenderersUsingThisMaterial.Clear();
#pragma warning disable CS0618 // Type or member is obsolete
ParticleSystemRenderer[] renderers = UnityEngine.Object.FindObjectsByType<ParticleSystemRenderer>(FindObjectsSortMode.InstanceID);
#pragma warning restore CS0618 // Type or member is obsolete
foreach (ParticleSystemRenderer renderer in renderers)
{
if (renderer.sharedMaterial == material)
m_RenderersUsingThisMaterial.Add(renderer);
}
}
}
} // namespace UnityEditor
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 9818dc043dbe84466a71ed6178bbffda
timeCreated: 1509367878
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
internal class ParticlesSimpleLitShader : BaseShaderGUI
{
// Properties
private SimpleLitGUI.SimpleLitProperties shadingModelProperties;
private ParticleGUI.ParticleProperties particleProps;
// List of renderers using this material in the scene, used for validating vertex streams
List<ParticleSystemRenderer> m_RenderersUsingThisMaterial = new List<ParticleSystemRenderer>();
public override void FindProperties(MaterialProperty[] properties)
{
base.FindProperties(properties);
shadingModelProperties = new SimpleLitGUI.SimpleLitProperties(properties);
particleProps = new ParticleGUI.ParticleProperties(properties);
}
public override void ValidateMaterial(Material material)
{
SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords, ParticleGUI.SetMaterialKeywords);
}
public override void DrawSurfaceOptions(Material material)
{
base.DrawSurfaceOptions(material);
DoPopup(ParticleGUI.Styles.colorMode, particleProps.colorMode, Enum.GetNames(typeof(ParticleGUI.ColorMode)));
}
public override void DrawSurfaceInputs(Material material)
{
base.DrawSurfaceInputs(material);
SimpleLitGUI.Inputs(shadingModelProperties, materialEditor, material);
DrawEmissionProperties(material, true);
}
public override void DrawAdvancedOptions(Material material)
{
SimpleLitGUI.Advanced(shadingModelProperties, materialEditor, material);
materialEditor.ShaderProperty(particleProps.flipbookMode, ParticleGUI.Styles.flipbookMode);
ParticleGUI.FadingOptions(material, materialEditor, particleProps);
ParticleGUI.DoVertexStreamsArea(material, m_RenderersUsingThisMaterial, true);
DrawQueueOffsetField();
}
public override void OnOpenGUI(Material material, MaterialEditor materialEditor)
{
CacheRenderersUsingThisMaterial(material);
base.OnOpenGUI(material, materialEditor);
}
void CacheRenderersUsingThisMaterial(Material material)
{
m_RenderersUsingThisMaterial.Clear();
#pragma warning disable CS0618 // Type or member is obsolete
ParticleSystemRenderer[] renderers = UnityEngine.Object.FindObjectsByType<ParticleSystemRenderer>(FindObjectsSortMode.InstanceID);
#pragma warning restore CS0618 // Type or member is obsolete
foreach (ParticleSystemRenderer renderer in renderers)
{
if (renderer.sharedMaterial == material)
m_RenderersUsingThisMaterial.Add(renderer);
}
}
}
} // namespace UnityEditor
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 3d80ff2d19402463c8a2a52558deaf43
timeCreated: 1509367878
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
internal class ParticlesUnlitShader : BaseShaderGUI
{
// Properties
private BakedLitGUI.BakedLitProperties shadingModelProperties;
private ParticleGUI.ParticleProperties particleProps;
// List of renderers using this material in the scene, used for validating vertex streams
List<ParticleSystemRenderer> m_RenderersUsingThisMaterial = new List<ParticleSystemRenderer>();
public override void FindProperties(MaterialProperty[] properties)
{
base.FindProperties(properties);
shadingModelProperties = new BakedLitGUI.BakedLitProperties(properties);
particleProps = new ParticleGUI.ParticleProperties(properties);
}
public override void ValidateMaterial(Material material)
{
SetMaterialKeywords(material, null, ParticleGUI.SetMaterialKeywords);
}
public override void DrawSurfaceOptions(Material material)
{
base.DrawSurfaceOptions(material);
DoPopup(ParticleGUI.Styles.colorMode, particleProps.colorMode, Enum.GetNames(typeof(ParticleGUI.ColorMode)));
}
public override void DrawSurfaceInputs(Material material)
{
base.DrawSurfaceInputs(material);
BakedLitGUI.Inputs(shadingModelProperties, materialEditor);
DrawEmissionProperties(material, true);
}
public override void DrawAdvancedOptions(Material material)
{
materialEditor.ShaderProperty(particleProps.flipbookMode, ParticleGUI.Styles.flipbookMode);
ParticleGUI.FadingOptions(material, materialEditor, particleProps);
ParticleGUI.DoVertexStreamsArea(material, m_RenderersUsingThisMaterial);
DrawQueueOffsetField();
}
public override void OnOpenGUI(Material material, MaterialEditor materialEditor)
{
CacheRenderersUsingThisMaterial(material);
base.OnOpenGUI(material, materialEditor);
}
void CacheRenderersUsingThisMaterial(Material material)
{
m_RenderersUsingThisMaterial.Clear();
#pragma warning disable CS0618 // Type or member is obsolete
ParticleSystemRenderer[] renderers = UnityEngine.Object.FindObjectsByType<ParticleSystemRenderer>(FindObjectsSortMode.InstanceID);
#pragma warning restore CS0618 // Type or member is obsolete
foreach (ParticleSystemRenderer renderer in renderers)
{
if (renderer.sharedMaterial == material)
m_RenderersUsingThisMaterial.Add(renderer);
}
}
}
} // namespace UnityEditor
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 84e6c97ce450449128b4f193da9c0263
timeCreated: 1509367878
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,89 @@
using System;
using UnityEngine;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
internal class SimpleLitShader : BaseShaderGUI
{
// Properties
private SimpleLitGUI.SimpleLitProperties shadingModelProperties;
// collect properties from the material properties
public override void FindProperties(MaterialProperty[] properties)
{
base.FindProperties(properties);
shadingModelProperties = new SimpleLitGUI.SimpleLitProperties(properties);
}
// material changed check
public override void ValidateMaterial(Material material)
{
SetMaterialKeywords(material, SimpleLitGUI.SetMaterialKeywords);
}
// material main surface options
public override void DrawSurfaceOptions(Material material)
{
if (material == null)
throw new ArgumentNullException("material");
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
base.DrawSurfaceOptions(material);
}
// material main surface inputs
public override void DrawSurfaceInputs(Material material)
{
base.DrawSurfaceInputs(material);
SimpleLitGUI.Inputs(shadingModelProperties, materialEditor, material);
DrawEmissionProperties(material, true);
DrawTileOffset(materialEditor, baseMapProp);
}
public override void DrawAdvancedOptions(Material material)
{
SimpleLitGUI.Advanced(shadingModelProperties, materialEditor, 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);
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b31b6386794884dfbb8513e510144b19
timeCreated: 1504689095
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,80 @@
using System;
using UnityEngine;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
internal class UnlitShader : BaseShaderGUI
{
// material changed check
public override void ValidateMaterial(Material material)
{
SetMaterialKeywords(material);
}
// material main surface options
public override void DrawSurfaceOptions(Material material)
{
if (material == null)
throw new ArgumentNullException("material");
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;
base.DrawSurfaceOptions(material);
}
// material main surface inputs
public override void DrawSurfaceInputs(Material material)
{
base.DrawSurfaceInputs(material);
DrawTileOffset(materialEditor, baseMapProp);
}
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");
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 8ed8ed178d5584da0874d4c69e3624a9
timeCreated: 1504689095
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a22c22fb536604167866c59ce9a780d2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,45 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
/// <summary>
/// Editor script for the BakedLit material inspector.
/// </summary>
public static class BakedLitGUI
{
/// <summary>
/// Container for the properties used in the <c>BakedLitGUI</c> editor script.
/// </summary>
public struct BakedLitProperties
{
// Surface Input Props
/// <summary>
/// The MaterialProperty for normal map.
/// </summary>
public MaterialProperty bumpMapProp;
/// <summary>
/// Constructor for the <c>BakedLitProperties</c> container struct.
/// </summary>
/// <param name="properties"></param>
public BakedLitProperties(MaterialProperty[] properties)
{
// Surface Input Props
bumpMapProp = BaseShaderGUI.FindProperty("_BumpMap", properties, false);
}
}
/// <summary>
/// Draws the surface inputs GUI.
/// </summary>
/// <param name="properties"></param>
/// <param name="materialEditor"></param>
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,75 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
internal class LitDetailGUI
{
internal 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);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7645809b8de779942be231eecf635c5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,547 @@
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
/// <summary>
/// Editor script for the Lit material inspector.
/// </summary>
public static class LitGUI
{
/// <summary>
/// Workflow modes for the shader.
/// </summary>
public enum WorkflowMode
{
/// <summary>
/// Use this for specular workflow.
/// </summary>
Specular = 0,
/// <summary>
/// Use this for metallic workflow.
/// </summary>
Metallic
}
/// <summary>
/// Options to select the texture channel where the smoothness value is stored.
/// </summary>
public enum SmoothnessMapChannel
{
/// <summary>
/// Use this when smoothness is stored in the alpha channel of the Specular/Metallic Map.
/// </summary>
SpecularMetallicAlpha,
/// <summary>
/// Use this when smoothness is stored in the alpha channel of the Albedo Map.
/// </summary>
AlbedoAlpha,
}
/// <summary>
/// Container for the text and tooltips used to display the shader.
/// </summary>
public static class Styles
{
/// <summary>
/// The text and tooltip for the workflow Mode GUI.
/// </summary>
public static GUIContent workflowModeText = EditorGUIUtility.TrTextContent("Workflow Mode",
"Select a workflow that fits your textures. Choose between Metallic or Specular.");
/// <summary>
/// The text and tooltip for the specular Map GUI.
/// </summary>
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.");
/// <summary>
/// The text and tooltip for the metallic Map GUI.
/// </summary>
public static GUIContent metallicMapText =
EditorGUIUtility.TrTextContent("Metallic Map", "Sets and configures the map for the Metallic workflow.");
/// <summary>
/// The text and tooltip for the smoothness GUI.
/// </summary>
public static GUIContent smoothnessText = EditorGUIUtility.TrTextContent("Smoothness",
"Controls the spread of highlights and reflections on the surface.");
/// <summary>
/// The text and tooltip for the smoothness source GUI.
/// </summary>
public static GUIContent smoothnessMapChannelText =
EditorGUIUtility.TrTextContent("Source",
"Specifies where to sample a smoothness map from. By default, uses the alpha channel for your map.");
/// <summary>
/// The text and tooltip for the specular Highlights GUI.
/// </summary>
public static GUIContent highlightsText = EditorGUIUtility.TrTextContent("Specular Highlights",
"When enabled, the Material reflects the shine from direct lighting.");
/// <summary>
/// The text and tooltip for the environment Reflections GUI.
/// </summary>
public static GUIContent reflectionsText =
EditorGUIUtility.TrTextContent("Environment Reflections",
"When enabled, the Material samples reflections from the nearest Reflection Probes or Lighting Probe.");
#if URP_SCREEN_SPACE_REFLECTION
/// <summary>
/// The text and tooltip for the screen space reflections GUI.
/// </summary>
public static GUIContent screenSpaceReflectionsText =
EditorGUIUtility.TrTextContent("Screen Space Reflections",
"When enabled, the Material samples screen space reflections.");
/// <summary>
/// The text and tooltip for the screen space reflections contribute transparent GUI.
/// </summary>
public static GUIContent screenSpaceReflectionsContributeTransparentText =
EditorGUIUtility.TrTextContent("Contribute Screen Space Reflections",
"When enabled, this Material will contribute to screen space reflections. This will include the object in the transparency-depth prepass.");
#endif
/// <summary>
/// The text and tooltip for the height map GUI.
/// </summary>
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.");
/// <summary>
/// The text and tooltip for the occlusion map GUI.
/// </summary>
public static GUIContent occlusionText = EditorGUIUtility.TrTextContent("Occlusion Map",
"Sets an occlusion map to simulate shadowing from ambient lighting.");
/// <summary>
/// The names for smoothness alpha options available for metallic workflow.
/// </summary>
public static readonly string[] metallicSmoothnessChannelNames = { "Metallic Alpha", "Albedo Alpha" };
/// <summary>
/// The names for smoothness alpha options available for specular workflow.
/// </summary>
public static readonly string[] specularSmoothnessChannelNames = { "Specular Alpha", "Albedo Alpha" };
/// <summary>
/// The text and tooltip for the enabling/disabling clear coat GUI.
/// </summary>
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.");
/// <summary>
/// The text and tooltip for the clear coat Mask GUI.
/// </summary>
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.");
/// <summary>
/// The text and tooltip for the clear coat smoothness GUI.
/// </summary>
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.");
}
/// <summary>
/// Container for the properties used in the <c>LitGUI</c> editor script.
/// </summary>
public struct LitProperties
{
// Surface Option Props
/// <summary>
/// The MaterialProperty for workflow mode.
/// </summary>
public MaterialProperty workflowMode;
// Surface Input Props
/// <summary>
/// The MaterialProperty for metallic value.
/// </summary>
public MaterialProperty metallic;
/// <summary>
/// The MaterialProperty for specular color.
/// </summary>
public MaterialProperty specColor;
/// <summary>
/// The MaterialProperty for metallic Smoothness map.
/// </summary>
public MaterialProperty metallicGlossMap;
/// <summary>
/// The MaterialProperty for specular smoothness map.
/// </summary>
public MaterialProperty specGlossMap;
/// <summary>
/// The MaterialProperty for smoothness value.
/// </summary>
public MaterialProperty smoothness;
/// <summary>
/// The MaterialProperty for smoothness alpha channel.
/// </summary>
public MaterialProperty smoothnessMapChannel;
/// <summary>
/// The MaterialProperty for normal map.
/// </summary>
public MaterialProperty bumpMapProp;
/// <summary>
/// The MaterialProperty for normal map scale.
/// </summary>
public MaterialProperty bumpScaleProp;
/// <summary>
/// The MaterialProperty for height map.
/// </summary>
public MaterialProperty parallaxMapProp;
/// <summary>
/// The MaterialProperty for height map scale.
/// </summary>
public MaterialProperty parallaxScaleProp;
/// <summary>
/// The MaterialProperty for occlusion strength.
/// </summary>
public MaterialProperty occlusionStrength;
/// <summary>
/// The MaterialProperty for occlusion map.
/// </summary>
public MaterialProperty occlusionMap;
// Advanced Props
/// <summary>
/// The MaterialProperty for specular highlights.
/// </summary>
public MaterialProperty highlights;
/// <summary>
/// The MaterialProperty for environment reflections.
/// </summary>
public MaterialProperty reflections;
#if URP_SCREEN_SPACE_REFLECTION
/// <summary>
/// The MaterialProperty for screen space reflections.
/// </summary>
public MaterialProperty screenSpaceReflections;
/// <summary>
/// The MaterialProperty for screen space reflections contribute transparent.
/// </summary>
public MaterialProperty screenSpaceReflectionsContributeTransparent;
#endif
/// <summary>
/// The MaterialProperty for enabling/disabling clear coat.
/// </summary>
public MaterialProperty clearCoat; // Enable/Disable dummy property
/// <summary>
/// The MaterialProperty for clear coat map.
/// </summary>
public MaterialProperty clearCoatMap;
/// <summary>
/// The MaterialProperty for clear coat mask.
/// </summary>
public MaterialProperty clearCoatMask;
/// <summary>
/// The MaterialProperty for clear coat smoothness.
/// </summary>
public MaterialProperty clearCoatSmoothness;
/// <summary>
/// Constructor for the <c>LitProperties</c> container struct.
/// </summary>
/// <param name="properties"></param>
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);
#if URP_SCREEN_SPACE_REFLECTION
screenSpaceReflections = BaseShaderGUI.FindProperty("_ScreenSpaceReflections", properties, false);
screenSpaceReflectionsContributeTransparent = BaseShaderGUI.FindProperty("_ScreenSpaceReflectionsContributeTransparent", properties, false);
#endif
clearCoat = BaseShaderGUI.FindProperty("_ClearCoat", properties, false);
clearCoatMap = BaseShaderGUI.FindProperty("_ClearCoatMap", properties, false);
clearCoatMask = BaseShaderGUI.FindProperty("_ClearCoatMask", properties, false);
clearCoatSmoothness = BaseShaderGUI.FindProperty("_ClearCoatSmoothness", properties, false);
}
}
/// <summary>
/// Draws the surface inputs GUI.
/// </summary>
/// <param name="properties"></param>
/// <param name="materialEditor"></param>
/// <param name="material"></param>
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;
}
/// <summary>
/// Draws the clear coat GUI.
/// </summary>
/// <param name="properties"></param>
/// <param name="materialEditor"></param>
/// <param name="material"></param>
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);
{
EditorGUI.indentLevel += 2;
materialEditor.TexturePropertySingleLine(Styles.clearCoatMaskText, properties.clearCoatMap, properties.clearCoatMask);
// Texture and HDR color controls
materialEditor.ShaderProperty(properties.clearCoatSmoothness, Styles.clearCoatSmoothnessText);
EditorGUI.indentLevel -= 2;
}
EditorGUI.EndDisabledGroup();
}
/// <summary>
/// Draws the metallic/specular area GUI.
/// </summary>
/// <param name="properties"></param>
/// <param name="materialEditor"></param>
/// <param name="material"></param>
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;
}
/// <summary>
/// Draws the smoothness GUI.
/// </summary>
/// <param name="materialEditor"></param>
/// <param name="material"></param>
/// <param name="smoothness"></param>
/// <param name="smoothnessMapChannel"></param>
/// <param name="smoothnessChannelNames"></param>
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)
{
MaterialEditor.BeginProperty(smoothnessMapChannel);
EditorGUI.BeginChangeCheck();
var smoothnessSource = (int)smoothnessMapChannel.floatValue;
smoothnessSource = EditorGUILayout.Popup(Styles.smoothnessMapChannelText, smoothnessSource, smoothnessChannelNames);
if (EditorGUI.EndChangeCheck())
smoothnessMapChannel.floatValue = smoothnessSource;
MaterialEditor.EndProperty();
}
else
{
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.Popup(Styles.smoothnessMapChannelText, 0, smoothnessChannelNames);
EditorGUI.EndDisabledGroup();
}
EditorGUI.showMixedValue = false;
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel -= 2;
}
/// <summary>
/// Retrieves the alpha channel used for smoothness.
/// </summary>
/// <param name="material"></param>
/// <returns>The Alpha channel used for Smoothness.</returns>
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);
}
/// <summary>
/// Sets up the keywords for the Lit shader and material.
/// </summary>
/// <param name="material"></param>
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 URP_SCREEN_SPACE_REFLECTION
if (material.HasProperty("_ScreenSpaceReflections"))
CoreUtils.SetKeyword(material, "_SCREENSPACEREFLECTIONS_OFF",
material.GetFloat("_ScreenSpaceReflections") == 0.0f);
if (material.HasProperty("_ScreenSpaceReflectionsContributeTransparent"))
CoreUtils.SetKeyword(material, "_SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF",
material.GetFloat("_ScreenSpaceReflectionsContributeTransparent") == 0.0f && material.renderQueue >= (int)UnityEngine.Rendering.RenderQueue.Transparent);
#endif
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 possibility 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,226 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Scripting.APIUpdating;
namespace UnityEditor.Rendering.Universal.ShaderGUI
{
/// <summary>
/// Editor script for the SimpleLit material inspector.
/// </summary>
public static class SimpleLitGUI
{
/// <summary>
/// Options for specular source.
/// </summary>
public enum SpecularSource
{
/// <summary>
/// Use this to use specular texture and color.
/// </summary>
SpecularTextureAndColor,
/// <summary>
/// Use this when not using specular.
/// </summary>
NoSpecular
}
/// <summary>
/// Options to select the texture channel where the smoothness value is stored.
/// </summary>
public enum SmoothnessMapChannel
{
/// <summary>
/// Use this when smoothness is stored in the alpha channel of the Specular Map.
/// </summary>
SpecularAlpha,
/// <summary>
/// Use this when smoothness is stored in the alpha channel of the Albedo Map.
/// </summary>
AlbedoAlpha,
}
/// <summary>
/// Container for the text and tooltips used to display the shader.
/// </summary>
public static class Styles
{
/// <summary>
/// The text and tooltip for the specular map GUI.
/// </summary>
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.");
}
/// <summary>
/// Container for the properties used in the <c>SimpleLitGUI</c> editor script.
/// </summary>
public struct SimpleLitProperties
{
// Surface Input Props
/// <summary>
/// The MaterialProperty for specular color.
/// </summary>
public MaterialProperty specColor;
/// <summary>
/// The MaterialProperty for specular smoothness map.
/// </summary>
public MaterialProperty specGlossMap;
/// <summary>
/// The MaterialProperty for specular highlights.
/// </summary>
public MaterialProperty specHighlights;
/// <summary>
/// The MaterialProperty for smoothness alpha channel.
/// </summary>
public MaterialProperty smoothnessMapChannel;
/// <summary>
/// The MaterialProperty for smoothness value.
/// </summary>
public MaterialProperty smoothness;
/// <summary>
/// The MaterialProperty for normal map.
/// </summary>
public MaterialProperty bumpMapProp;
#if URP_SCREEN_SPACE_REFLECTION
/// <summary>
/// The MaterialProperty for screen space reflections contribute transparent.
/// </summary>
public MaterialProperty screenSpaceReflectionsContributeTransparent;
#endif
/// <summary>
/// Constructor for the <c>SimpleLitProperties</c> container struct.
/// </summary>
/// <param name="properties"></param>
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);
#if URP_SCREEN_SPACE_REFLECTION
screenSpaceReflectionsContributeTransparent = BaseShaderGUI.FindProperty("_ScreenSpaceReflectionsContributeTransparent", properties, false);
#endif
}
}
/// <summary>
/// Draws the surface inputs GUI.
/// </summary>
/// <param name="properties"></param>
/// <param name="materialEditor"></param>
/// <param name="material">The material to use.</param>
public static void Inputs(SimpleLitProperties properties, MaterialEditor materialEditor, Material material)
{
DoSpecularArea(properties, materialEditor, material);
BaseShaderGUI.DrawNormalArea(materialEditor, properties.bumpMapProp);
}
/// <summary>
/// Draws the advanced GUI.
/// </summary>
/// <param name="properties">The SimpleLit properties.</param>
/// <param name="materialEditor">The material editor.</param>
/// <param name="material">The material to use.</param>
public static void Advanced(SimpleLitProperties properties, MaterialEditor materialEditor, Material material)
{
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;
#if URP_SCREEN_SPACE_REFLECTION
if (properties.screenSpaceReflectionsContributeTransparent != null)
{
bool isTransparent = material.renderQueue >= (int)UnityEngine.Rendering.RenderQueue.Transparent;
if (isTransparent)
materialEditor.ShaderProperty(properties.screenSpaceReflectionsContributeTransparent, LitGUI.Styles.screenSpaceReflectionsContributeTransparentText);
}
#endif
}
/// <summary>
/// Draws the specular area GUI.
/// </summary>
/// <param name="properties"></param>
/// <param name="materialEditor"></param>
/// <param name="material">The material to use.</param>
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();
}
/// <summary>
/// Sets up the keywords for the material and shader.
/// </summary>
/// <param name="material">The material to use.</param>
public static void SetMaterialKeywords(Material material)
{
UpdateMaterialSpecularSource(material);
#if URP_SCREEN_SPACE_REFLECTION
if (material.HasProperty("_ScreenSpaceReflectionsContributeTransparent"))
CoreUtils.SetKeyword(material, "_SCREENSPACEREFLECTIONSCONTRIBUTETRANSPARENT_OFF",
material.GetFloat("_ScreenSpaceReflectionsContributeTransparent") == 0.0f && material.renderQueue >= (int)UnityEngine.Rendering.RenderQueue.Transparent);
#endif
}
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:
@@ -0,0 +1,54 @@
using UnityEditor.Rendering.Universal.ShaderGraph;
using UnityEngine;
using UnityEngine.Rendering;
using static Unity.Rendering.Universal.ShaderUtils;
namespace UnityEditor
{
// Used for ShaderGraph Lit shaders
class SixWayGUI : ShaderGraphLitGUI
{
private MaterialProperty useColorAbsorption;
/// <summary>
/// Container for the text and tooltips used to display the shader.
/// </summary>
protected class SixWayStyles
{
// Categories
/// <summary>
/// The text and tooltip for the surface options GUI.
/// </summary>
public static readonly GUIContent UseColorAbsorptionText =
EditorGUIUtility.TrTextContent("Use Color Absorption", "When enabled, the lightmaps are used to simulate color absorption whose strength can be tuned with the Absorption Strength parameter.");
}
// collect properties from the material properties
public override void FindProperties(MaterialProperty[] properties)
{
base.FindProperties(properties);
useColorAbsorption = FindProperty(UniversalSixWaySubTarget.SixWayProperties.UseColorAbsorption, properties, false);
}
public override void DrawSurfaceOptions(Material material)
{
base.DrawSurfaceOptions(material);
if(useColorAbsorption != null)
materialEditor.ShaderProperty(useColorAbsorption, SixWayStyles.UseColorAbsorptionText);
}
public static void UpdateSixWayKeywords(Material material)
{
bool useColorAbsorptionValue = false;
if (material.HasProperty(UniversalSixWaySubTarget.SixWayProperties.UseColorAbsorption))
useColorAbsorptionValue = material.GetFloat(UniversalSixWaySubTarget.SixWayProperties.UseColorAbsorption) > 0.0f;
CoreUtils.SetKeyword(material, "_SIX_WAY_COLOR_ABSORPTION", useColorAbsorptionValue);
}
public override void ValidateMaterial(Material material)
{
base.ValidateMaterial(material);
UpdateSixWayKeywords(material);
}
}
} // namespace UnityEditor
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b0e62b855f4840d5a767597e3fa34a90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,377 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Rendering.Universal
{
internal class TerrainLitShaderGUI : BaseShaderGUI, ITerrainLayerCustomUI
{
private class StylesLayer
{
public readonly GUIContent warningHeightBasedBlending = new GUIContent("Height-based blending is disabled if you have more than four TerrainLayer materials!");
public readonly GUIContent enableHeightBlend = new GUIContent("Enable Height-based Blend", "Blend terrain layers based on height values.");
public readonly GUIContent heightTransition = new GUIContent("Height Transition", "Size in world units of the smooth transition between layers.");
public readonly GUIContent enableInstancedPerPixelNormal = new GUIContent("Enable Per-pixel Normal", "Enable per-pixel normal when the terrain uses instanced rendering.");
public readonly GUIContent diffuseTexture = new GUIContent("Diffuse");
public readonly GUIContent colorTint = new GUIContent("Color Tint");
public readonly GUIContent opacityAsDensity = new GUIContent("Opacity as Density", "Enable Density Blend (if unchecked, opacity is used as Smoothness)");
public readonly GUIContent normalMapTexture = new GUIContent("Normal Map");
public readonly GUIContent normalScale = new GUIContent("Normal Scale");
public readonly GUIContent maskMapTexture = new GUIContent("Mask", "R: Metallic\nG: AO\nB: Height\nA: Smoothness");
public readonly GUIContent maskMapTextureWithoutHeight = new GUIContent("Mask Map", "R: Metallic\nG: AO\nA: Smoothness");
public readonly GUIContent channelRemapping = new GUIContent("Channel Remapping");
public readonly GUIContent defaultValues = new GUIContent("Channel Default Values");
public readonly GUIContent metallic = new GUIContent("R: Metallic");
public readonly GUIContent ao = new GUIContent("G: AO");
public readonly GUIContent height = new GUIContent("B: Height");
public readonly GUIContent heightParametrization = new GUIContent("Parametrization");
public readonly GUIContent heightAmplitude = new GUIContent("Amplitude (cm)");
public readonly GUIContent heightBase = new GUIContent("Base (cm)");
public readonly GUIContent heightMin = new GUIContent("Min (cm)");
public readonly GUIContent heightMax = new GUIContent("Max (cm)");
public readonly GUIContent heightCm = new GUIContent("B: Height (cm)");
public readonly GUIContent smoothness = new GUIContent("A: Smoothness");
}
static StylesLayer s_Styles = null;
private static StylesLayer styles { get { if (s_Styles == null) s_Styles = new StylesLayer(); return s_Styles; } }
protected override uint materialFilter => (uint)Expandable.SurfaceOptions;
public TerrainLitShaderGUI()
{
}
// Height blend params
MaterialProperty enableHeightBlend = null;
const string kEnableHeightBlend = "_EnableHeightBlend";
MaterialProperty heightTransition = null;
const string kHeightTransition = "_HeightTransition";
// Per-pixel Normal (while instancing)
MaterialProperty enableInstancedPerPixelNormal = null;
const string kEnableInstancedPerPixelNormal = "_EnableInstancedPerPixelNormal";
private bool m_ShowChannelRemapping = false;
enum HeightParametrization
{
Amplitude,
MinMax
};
private HeightParametrization m_HeightParametrization = HeightParametrization.Amplitude;
private static bool DoesTerrainUseMaskMaps(TerrainLayer[] terrainLayers)
{
for (int i = 0; i < terrainLayers.Length; ++i)
{
if (terrainLayers[i].maskMapTexture != null)
return true;
}
return false;
}
protected void FindMaterialProperties(MaterialProperty[] props)
{
enableHeightBlend = FindProperty(kEnableHeightBlend, props, false);
heightTransition = FindProperty(kHeightTransition, props, false);
enableInstancedPerPixelNormal = FindProperty(kEnableInstancedPerPixelNormal, props, false);
}
static public void SetupMaterialKeywords(Material material)
{
bool enableHeightBlend = (material.HasProperty(kEnableHeightBlend) && material.GetFloat(kEnableHeightBlend) > 0);
CoreUtils.SetKeyword(material, "_TERRAIN_BLEND_HEIGHT", enableHeightBlend);
bool enableInstancedPerPixelNormal = material.GetFloat(kEnableInstancedPerPixelNormal) > 0.0f;
CoreUtils.SetKeyword(material, "_TERRAIN_INSTANCED_PERPIXEL_NORMAL", enableInstancedPerPixelNormal);
}
static public bool TextureHasAlpha(Texture2D inTex)
{
if (inTex != null)
{
return GraphicsFormatUtility.HasAlphaChannel(GraphicsFormatUtility.GetGraphicsFormat(inTex.format, true));
}
return false;
}
public override void FindProperties(MaterialProperty[] properties)
{
base.FindProperties(properties);
FindMaterialProperties(properties);
}
public override void DrawSurfaceOptions(Material material)
{
if (materialEditor == null)
throw new ArgumentNullException("materialEditor");
bool optionsChanged = false;
EditorGUI.BeginChangeCheck();
{
if (enableHeightBlend != null)
{
EditorGUI.indentLevel++;
materialEditor.ShaderProperty(enableHeightBlend, styles.enableHeightBlend);
if (enableHeightBlend.floatValue > 0)
{
EditorGUI.indentLevel++;
EditorGUILayout.HelpBox(styles.warningHeightBasedBlending.text, MessageType.Info);
materialEditor.ShaderProperty(heightTransition, styles.heightTransition);
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
}
}
if (EditorGUI.EndChangeCheck())
{
optionsChanged = true;
}
bool enablePerPixelNormalChanged = false;
// Since Instanced Per-pixel normal is actually dependent on instancing enabled or not, it is not
// important to check it in the GUI. The shader will make sure it is enabled/disabled properly.s
if (enableInstancedPerPixelNormal != null)
{
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
materialEditor.ShaderProperty(enableInstancedPerPixelNormal, styles.enableInstancedPerPixelNormal);
enablePerPixelNormalChanged = EditorGUI.EndChangeCheck();
EditorGUI.indentLevel--;
}
if (optionsChanged || enablePerPixelNormalChanged)
{
foreach (var obj in materialEditor.targets)
{
SetupMaterialKeywords((Material)obj);
}
}
// We should always do this call at the end
materialEditor.serializedObject.ApplyModifiedProperties();
}
bool ITerrainLayerCustomUI.OnTerrainLayerGUI(TerrainLayer terrainLayer, Terrain terrain)
{
var terrainLayers = terrain.terrainData.terrainLayers;
// Don't use the member field enableHeightBlend as ShaderGUI.OnGUI might not be called if the material UI is folded.
// heightblend shouldn't be available if we are in multi-pass mode, because it is guaranteed to be broken.
bool heightBlendAvailable = (terrainLayers.Length <= 4);
bool heightBlend = heightBlendAvailable && terrain.materialTemplate.HasProperty(kEnableHeightBlend) && (terrain.materialTemplate.GetFloat(kEnableHeightBlend) > 0);
EditorGUI.BeginChangeCheck();
var diffuseTexture = EditorGUILayout.ObjectField(styles.diffuseTexture, terrainLayer.diffuseTexture, typeof(Texture2D), false) as Texture2D;
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(terrainLayer, "Terrain Layer Diffuse Texture");
terrainLayer.diffuseTexture = diffuseTexture;
}
// Anchor before validation, which may insert help boxes.
var diffuseFieldRect = GUILayoutUtility.GetLastRect();
TerrainLayerUtility.ValidateDiffuseTextureUI(terrainLayer.diffuseTexture);
var diffuseRemapMin = terrainLayer.diffuseRemapMin;
var diffuseRemapMax = terrainLayer.diffuseRemapMax;
EditorGUI.BeginChangeCheck();
bool enableDensity = false;
if (terrainLayer.diffuseTexture != null)
{
var rect = diffuseFieldRect;
rect.y += 16 + 4;
rect.width = EditorGUIUtility.labelWidth + 64;
rect.height = 16;
++EditorGUI.indentLevel;
var diffuseTint = new Color(diffuseRemapMax.x, diffuseRemapMax.y, diffuseRemapMax.z);
diffuseTint = EditorGUI.ColorField(rect, styles.colorTint, diffuseTint, true, false, false);
diffuseRemapMax.x = diffuseTint.r;
diffuseRemapMax.y = diffuseTint.g;
diffuseRemapMax.z = diffuseTint.b;
diffuseRemapMin.x = diffuseRemapMin.y = diffuseRemapMin.z = 0;
if (!heightBlend)
{
rect.y = rect.yMax + 2;
enableDensity = EditorGUI.Toggle(rect, styles.opacityAsDensity, diffuseRemapMin.w > 0);
}
--EditorGUI.indentLevel;
}
diffuseRemapMax.w = 1;
diffuseRemapMin.w = enableDensity ? 1 : 0;
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(terrainLayer, "Terrain Layer Diffuse Remap");
terrainLayer.diffuseRemapMin = diffuseRemapMin;
terrainLayer.diffuseRemapMax = diffuseRemapMax;
}
// Display normal map UI
EditorGUI.BeginChangeCheck();
var normalMapTexture = EditorGUILayout.ObjectField(styles.normalMapTexture, terrainLayer.normalMapTexture, typeof(Texture2D), false) as Texture2D;
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(terrainLayer, "Terrain Layer Normal Map");
terrainLayer.normalMapTexture = normalMapTexture;
}
// Anchor before validation, which may insert help boxes.
var normalMapFieldRect = GUILayoutUtility.GetLastRect();
TerrainLayerUtility.ValidateNormalMapTextureUI(terrainLayer.normalMapTexture, TerrainLayerUtility.CheckNormalMapTextureType(terrainLayer.normalMapTexture));
if (terrainLayer.normalMapTexture != null)
{
var rect = normalMapFieldRect;
rect.y += 16 + 4;
rect.width = EditorGUIUtility.labelWidth + 64;
rect.height = 16;
++EditorGUI.indentLevel;
EditorGUI.BeginChangeCheck();
var normalScale = EditorGUI.FloatField(rect, styles.normalScale, terrainLayer.normalScale);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(terrainLayer, "Terrain Layer Normal Scale");
terrainLayer.normalScale = normalScale;
}
--EditorGUI.indentLevel;
}
// Display the mask map UI and the remap controls
EditorGUI.BeginChangeCheck();
var maskMapTexture = EditorGUILayout.ObjectField(heightBlend ? styles.maskMapTexture : styles.maskMapTextureWithoutHeight, terrainLayer.maskMapTexture, typeof(Texture2D), false) as Texture2D;
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(terrainLayer, "Terrain Layer Mask Map");
terrainLayer.maskMapTexture = maskMapTexture;
}
TerrainLayerUtility.ValidateMaskMapTextureUI(terrainLayer.maskMapTexture);
var maskMapRemapMin = terrainLayer.maskMapRemapMin;
var maskMapRemapMax = terrainLayer.maskMapRemapMax;
var smoothness = terrainLayer.smoothness;
var metallic = terrainLayer.metallic;
++EditorGUI.indentLevel;
EditorGUI.BeginChangeCheck();
m_ShowChannelRemapping = EditorGUILayout.Foldout(m_ShowChannelRemapping, terrainLayer.maskMapTexture != null ? s_Styles.channelRemapping : s_Styles.defaultValues);
if (m_ShowChannelRemapping)
{
if (terrainLayer.maskMapTexture != null)
{
float min, max;
min = maskMapRemapMin.x; max = maskMapRemapMax.x;
EditorGUILayout.MinMaxSlider(s_Styles.metallic, ref min, ref max, 0, 1);
maskMapRemapMin.x = min; maskMapRemapMax.x = max;
min = maskMapRemapMin.y; max = maskMapRemapMax.y;
EditorGUILayout.MinMaxSlider(s_Styles.ao, ref min, ref max, 0, 1);
maskMapRemapMin.y = min; maskMapRemapMax.y = max;
if (heightBlend)
{
EditorGUILayout.LabelField(styles.height);
++EditorGUI.indentLevel;
m_HeightParametrization = (HeightParametrization)EditorGUILayout.EnumPopup(styles.heightParametrization, m_HeightParametrization);
if (m_HeightParametrization == HeightParametrization.Amplitude)
{
// (height - heightBase) * amplitude
float amplitude = Mathf.Max(maskMapRemapMax.z - maskMapRemapMin.z, Mathf.Epsilon); // to avoid divide by zero
float heightBase = maskMapRemapMin.z / amplitude;
amplitude = EditorGUILayout.FloatField(styles.heightAmplitude, amplitude * 100) / 100;
heightBase = EditorGUILayout.FloatField(styles.heightBase, heightBase * 100) / 100;
maskMapRemapMin.z = heightBase * amplitude;
maskMapRemapMax.z = (1.0f - heightBase) * amplitude;
}
else
{
maskMapRemapMin.z = EditorGUILayout.FloatField(styles.heightMin, maskMapRemapMin.z * 100) / 100;
maskMapRemapMax.z = EditorGUILayout.FloatField(styles.heightMax, maskMapRemapMax.z * 100) / 100;
}
--EditorGUI.indentLevel;
}
min = maskMapRemapMin.w; max = maskMapRemapMax.w;
EditorGUILayout.MinMaxSlider(s_Styles.smoothness, ref min, ref max, 0, 1);
maskMapRemapMin.w = min; maskMapRemapMax.w = max;
}
else
{
metallic = EditorGUILayout.Slider(s_Styles.metallic, metallic, 0, 1);
// AO and Height are still exclusively controlled via the maskRemap controls
// metallic and smoothness have their own values as fields within the LayerData.
maskMapRemapMax.y = EditorGUILayout.Slider(s_Styles.ao, maskMapRemapMax.y, 0, 1);
if (heightBlend)
{
maskMapRemapMax.z = EditorGUILayout.FloatField(s_Styles.heightCm, maskMapRemapMax.z * 100) / 100;
}
// There's a possibility that someone could slide max below the existing min value
// so we'll just protect against that by locking the min value down a little bit.
// In the case of height (Z), we are trying to set min to no lower than zero value unless
// max goes negative. Zero is a good sensible value for the minimum. For AO (Y), we
// don't need this extra protection step because the UI blocks us from going negative
// anyway. In both cases, pushing the slider below the min value will lock them together,
// but min will be "left behind" if you go back up.
maskMapRemapMin.y = Mathf.Min(maskMapRemapMin.y, maskMapRemapMax.y);
maskMapRemapMin.z = Mathf.Min(Mathf.Max(0, maskMapRemapMin.z), maskMapRemapMax.z);
// See also: TerrainLitGUI, TerrainLayerInspector.
if (TextureHasAlpha(terrainLayer.diffuseTexture))
{
EditorGUI.BeginChangeCheck();
var smoothnessSource = (UnityEngine.TerrainLayerSmoothnessSource)EditorGUILayout.EnumPopup(
EditorGUIUtility.TrTextContent("Smoothness Source"), terrainLayer.smoothnessSource);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(terrainLayer, "Terrain Layer Smoothness Source");
terrainLayer.smoothnessSource = smoothnessSource;
}
if (terrainLayer.smoothnessSource == TerrainLayerSmoothnessSource.DiffuseAlphaChannel)
{
GUIStyle warnStyle = new GUIStyle(GUI.skin.label);
warnStyle.wordWrap = true;
GUILayout.Label("Smoothness is controlled by diffuse alpha channel", warnStyle);
}
else
{
smoothness = EditorGUILayout.Slider(s_Styles.smoothness, smoothness, 0, 1);
}
}
else
{
smoothness = EditorGUILayout.Slider(s_Styles.smoothness, smoothness, 0, 1);
}
}
}
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(terrainLayer, "Terrain Layer Mask Map Remap");
terrainLayer.maskMapRemapMin = maskMapRemapMin;
terrainLayer.maskMapRemapMax = maskMapRemapMax;
terrainLayer.smoothness = smoothness;
terrainLayer.metallic = metallic;
}
--EditorGUI.indentLevel;
EditorGUILayout.Space();
TerrainLayerUtility.TilingSettingsUI(terrainLayer);
return true;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f2216b7cb5772784daf9ad851edda832
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: