浏览代码

HDRenderLoop: First version of LayeredLit GUI.

/main
Julien Ignace 8 年前
当前提交
3b5d9978
共有 4 个文件被更改,包括 238 次插入437 次删除
  1. 524
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LayeredLitUI.cs
  2. 139
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitUI.cs
  3. 8
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered.mat
  4. 4
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered.mat.meta

524
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LayeredLitUI.cs


namespace UnityEditor
{
internal class LayeredLitGUI : ShaderGUI
internal class LayeredLitGUI : LitGUI
// public enum SurfaceType
// {
// Opaque,
// Transparent
// }
// public enum BlendMode
// {
// Lerp,
// Add,
// SoftAdd,
// Multiply,
// Premultiply
// }
// public enum SmoothnessMapChannel
// {
// MaskAlpha,
// AlbedoAlpha,
// }
// public enum EmissiveColorMode
// {
// UseEmissiveColor,
// UseEmissiveMask,
// }
// public enum DoubleSidedMode
// {
// None,
// DoubleSided,
// DoubleSidedLightingFlip,
// DoubleSidedLightingMirror,
// }
// public enum NormalMapSpace
// {
// TangentSpace,
// ObjectSpace,
// }
// public enum HeightmapMode
// {
// Parallax,
// Displacement,
// }
// private static class Styles
// {
// public static string OptionText = "Options";
// public static string SurfaceTypeText = "Surface Type";
// public static string BlendModeText = "Blend Mode";
// public static GUIContent alphaCutoffEnableText = new GUIContent("Alpha Cutoff Enable", "Threshold for alpha cutoff");
// public static GUIContent alphaCutoffText = new GUIContent("Alpha Cutoff", "Threshold for alpha cutoff");
// public static GUIContent doubleSidedModeText = new GUIContent("Double Sided", "This will render the two face of the objects (disable backface culling)");
// public static readonly string[] surfaceTypeNames = Enum.GetNames(typeof(SurfaceType));
// public static readonly string[] blendModeNames = Enum.GetNames(typeof(BlendMode));
// public static string InputsOptionsText = "Inputs options";
// public static GUIContent smoothnessMapChannelText = new GUIContent("Smoothness Source", "Smoothness texture and channel");
// public static GUIContent emissiveColorModeText = new GUIContent("Emissive Color Usage", "Use emissive color or emissive mask");
// public static string InputsText = "Inputs";
// public static string InputsMapText = "";
// public static GUIContent baseColorText = new GUIContent("Base Color", "Albedo (RGB) and Smoothness (A)");
// public static GUIContent baseColorSmoothnessText = new GUIContent("Base Color + Smoothness", "Albedo (RGB) and Smoothness (A)");
// public static GUIContent mettalicText = new GUIContent("Mettalic", "Mettalic scale factor");
// public static GUIContent smoothnessText = new GUIContent("Smoothness", "Smoothness scale factor");
// public static GUIContent maskMapESText = new GUIContent("Mask Map - M(R), AO(G), E(B), S(A)", "Mask map");
// public static GUIContent maskMapEText = new GUIContent("Mask Map - M(R), AO(G), E(B)", "Mask map");
// public static GUIContent maskMapText = new GUIContent("Mask Map - M(R), AO(G)", "Mask map");
// public static GUIContent maskMapSText = new GUIContent("Mask Map - M(R), AO(G), S(A)", "Mask map");
// public static GUIContent specularOcclusionMapText = new GUIContent("Specular Occlusion Map (RGBA)", "Specular Occlusion Map");
// public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (BC5) - DXT5 for test");
// public static GUIContent normalMapSpaceText = new GUIContent("Normal Map space", "");
// public static GUIContent heightMapText = new GUIContent("Height Map", "Height Map");
// public static GUIContent heightMapModeText = new GUIContent("Height Map Mode", "");
// // public static GUIContent diffuseLightingMapText = new GUIContent("DiffuseLightingMap", "Lightmap/Lightprobe data (fill by system is not done");
// public static GUIContent emissiveText = new GUIContent("Emissive Color", "Emissive");
// public static GUIContent emissiveIntensityText = new GUIContent("Emissive Intensity", "Emissive");
// }
// MaterialProperty surfaceType = null;
// MaterialProperty blendMode = null;
// MaterialProperty alphaCutoff = null;
// MaterialProperty alphaCutoffEnable = null;
// MaterialProperty doubleSidedMode = null;
// MaterialProperty smoothnessMapChannel = null;
// MaterialProperty emissiveColorMode = null;
// MaterialProperty baseColor = null;
// MaterialProperty baseColorMap = null;
// MaterialProperty mettalic = null;
// MaterialProperty smoothness = null;
// MaterialProperty maskMap = null;
// MaterialProperty specularOcclusionMap = null;
// MaterialProperty normalMap = null;
// MaterialProperty normalMapSpace = null;
// MaterialProperty heightMap = null;
// MaterialProperty heightScale = null;
// MaterialProperty heightBias = null;
// MaterialProperty heightMapMode = null;
//// MaterialProperty diffuseLightingMap = null;
// MaterialProperty emissiveColor = null;
// MaterialProperty emissiveColorMap = null;
// MaterialProperty emissiveIntensity = null;
//// MaterialProperty subSurfaceRadius = null;
//// MaterialProperty subSurfaceRadiusMap = null;
// MaterialEditor m_MaterialEditor;
// public void FindProperties (MaterialProperty[] props)
// {
// surfaceType = FindProperty("_SurfaceType", props);
// blendMode = FindProperty("_BlendMode", props);
// alphaCutoff = FindProperty("_AlphaCutoff", props);
// alphaCutoffEnable = FindProperty("_AlphaCutoffEnable", props);
// doubleSidedMode = FindProperty("_DoubleSidedMode", props);
// smoothnessMapChannel = FindProperty("_SmoothnessTextureChannel", props);
// emissiveColorMode = FindProperty("_EmissiveColorMode", props);
// baseColor = FindProperty("_BaseColor", props);
// baseColorMap = FindProperty("_BaseColorMap", props);
// mettalic = FindProperty("_Mettalic", props);
// smoothness = FindProperty("_Smoothness", props);
// maskMap = FindProperty("_MaskMap", props);
// specularOcclusionMap = FindProperty("_SpecularOcclusionMap", props);
// normalMap = FindProperty("_NormalMap", props);
// normalMapSpace = FindProperty("_NormalMapSpace", props);
// heightMap = FindProperty("_HeightMap", props);
// heightScale = FindProperty("_HeightScale", props);
// heightBias = FindProperty("_HeightBias", props);
// heightMapMode = FindProperty("_HeightMapMode", props);
// // diffuseLightingMap = FindProperty("_DiffuseLightingMap", props);
// emissiveColor = FindProperty("_EmissiveColor", props);
// emissiveColorMap = FindProperty("_EmissiveColorMap", props);
// emissiveIntensity = FindProperty("_EmissiveIntensity", props);
// }
// public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] props)
// {
// FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
// m_MaterialEditor = materialEditor;
// Material material = materialEditor.target as Material;
private class Styles
{
public readonly GUIContent[] materialLayerLabels =
{
new GUIContent("Material Layer 0"),
new GUIContent("Material Layer 1"),
new GUIContent("Material Layer 2"),
new GUIContent("Material Layer 3"),
};
public readonly GUIContent syncButton = new GUIContent("Sync", "Re-synchronize this layer's properties with the referenced Material");
public readonly GUIContent layers = new GUIContent("Layers");
}
// ShaderPropertiesGUI (material);
// }
static Styles s_Styles = null;
private static Styles styles { get { if (s_Styles == null) s_Styles = new Styles(); return s_Styles; } }
// public void ShaderPropertiesGUI (Material material)
// {
// // Use default labelWidth
// EditorGUIUtility.labelWidth = 0f;
// Needed for json serialization to work
[Serializable]
internal struct SerializeableGUIDs
{
public string[] GUIDArray;
}
// // Detect any changes to the material
// EditorGUI.BeginChangeCheck();
// {
// GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel);
// SurfaceTypePopup();
// if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
// {
// BlendModePopup();
// }
// m_MaterialEditor.ShaderProperty(alphaCutoffEnable, Styles.alphaCutoffEnableText.text);
// if (alphaCutoffEnable.floatValue == 1.0)
// {
// m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text);
// }
// m_MaterialEditor.ShaderProperty(doubleSidedMode, Styles.doubleSidedModeText.text);
// GUILayout.Label(Styles.InputsOptionsText, EditorStyles.boldLabel);
// m_MaterialEditor.ShaderProperty(smoothnessMapChannel, Styles.smoothnessMapChannelText.text);
// m_MaterialEditor.ShaderProperty(emissiveColorMode, Styles.emissiveColorModeText.text);
// bool isAlbedoAlpha = (SmoothnessMapChannel)smoothnessMapChannel.floatValue == SmoothnessMapChannel.AlbedoAlpha;
// bool useEmissiveMask = (EmissiveColorMode)emissiveColorMode.floatValue == EmissiveColorMode.UseEmissiveMask;
// GUILayout.Label(Styles.InputsText, EditorStyles.boldLabel);
// m_MaterialEditor.TexturePropertySingleLine(isAlbedoAlpha ? Styles.baseColorSmoothnessText : Styles.baseColorText, baseColorMap, baseColor);
// m_MaterialEditor.ShaderProperty(mettalic, Styles.mettalicText);
// m_MaterialEditor.ShaderProperty(smoothness, Styles.smoothnessText);
// if (isAlbedoAlpha && useEmissiveMask)
// m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapESText, maskMap);
// else if (useEmissiveMask)
// m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapEText, maskMap);
// else if (isAlbedoAlpha)
// m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapSText, maskMap);
// else
// m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
// m_MaterialEditor.TexturePropertySingleLine(Styles.specularOcclusionMapText, specularOcclusionMap);
// m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
// m_MaterialEditor.ShaderProperty(normalMapSpace, Styles.normalMapSpaceText.text);
// m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap, heightScale, heightBias);
// m_MaterialEditor.ShaderProperty(heightMapMode, Styles.heightMapModeText.text);
// if (!useEmissiveMask)
// {
// m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor);
// }
// m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
// }
// if (EditorGUI.EndChangeCheck())
// {
// foreach (var obj in blendMode.targets)
// MaterialChanged((Material)obj);
// }
// }
// // TODO: try to setup minimun value to fall back to standard shaders and reverse
// public override void AssignNewShaderToMaterial (Material material, Shader oldShader, Shader newShader)
// {
// base.AssignNewShaderToMaterial(material, oldShader, newShader);
// }
// void SurfaceTypePopup()
// {
// EditorGUI.showMixedValue = surfaceType.hasMixedValue;
// var mode = (SurfaceType)surfaceType.floatValue;
// EditorGUI.BeginChangeCheck();
// mode = (SurfaceType)EditorGUILayout.Popup(Styles.SurfaceTypeText, (int)mode, Styles.surfaceTypeNames);
// if (EditorGUI.EndChangeCheck())
// {
// m_MaterialEditor.RegisterPropertyChangeUndo("Surface Type");
// surfaceType.floatValue = (float)mode;
// }
// EditorGUI.showMixedValue = false;
// }
private int kSyncButtonWidth = 58;
private Material[] m_MaterialLayers = new Material[4];
// void BlendModePopup()
// {
// EditorGUI.showMixedValue = blendMode.hasMixedValue;
// var mode = (BlendMode)blendMode.floatValue;
void SynchronizeLayerProperties(int layerIndex)
{
Material material = m_MaterialEditor.target as Material;
Material layerMaterial = m_MaterialLayers[layerIndex];
// EditorGUI.BeginChangeCheck();
// mode = (BlendMode)EditorGUILayout.Popup(Styles.BlendModeText, (int)mode, Styles.blendModeNames);
// if (EditorGUI.EndChangeCheck())
// {
// m_MaterialEditor.RegisterPropertyChangeUndo("Blend Mode");
// blendMode.floatValue = (float)mode;
// }
if(layerMaterial != null)
{
Shader layerShader = layerMaterial.shader;
int propertyCount = ShaderUtil.GetPropertyCount(layerShader);
for(int i = 0 ; i < propertyCount ; ++i)
{
string propertyName = ShaderUtil.GetPropertyName(layerShader, i);
string layerPropertyName = propertyName + layerIndex;
if(material.HasProperty(layerPropertyName))
{
switch(ShaderUtil.GetPropertyType(layerShader, i))
{
case ShaderUtil.ShaderPropertyType.Color:
{
material.SetColor(layerPropertyName, layerMaterial.GetColor(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.Float:
{
material.SetFloat(layerPropertyName, layerMaterial.GetFloat(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.Vector:
{
material.SetVector(layerPropertyName, layerMaterial.GetVector(propertyName));
break;
}
case ShaderUtil.ShaderPropertyType.TexEnv:
{
material.SetTexture(layerPropertyName, layerMaterial.GetTexture(propertyName));
break;
}
}
}
}
}
}
// EditorGUI.showMixedValue = false;
// }
void InitializeMaterialLayers(AssetImporter materialImporter)
{
if (materialImporter.userData != string.Empty)
{
SerializeableGUIDs layersGUID = JsonUtility.FromJson<SerializeableGUIDs>(materialImporter.userData);
if (layersGUID.GUIDArray.Length > 0)
{
m_MaterialLayers = new Material[layersGUID.GUIDArray.Length];
for (int i = 0; i < layersGUID.GUIDArray.Length; ++i)
{
m_MaterialLayers[i] = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(layersGUID.GUIDArray[i]), typeof(Material)) as Material;
}
}
}
}
// static public void SetupMaterial(Material material)
// {
// // 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)
void SaveMaterialLayers(AssetImporter materialImporter)
{
SerializeableGUIDs layersGUID;
layersGUID.GUIDArray = new string[m_MaterialLayers.Length];
for(int i = 0 ; i < m_MaterialLayers.Length; ++i)
{
if (m_MaterialLayers[i] != null)
layersGUID.GUIDArray[i] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_MaterialLayers[i].GetInstanceID()));
// bool alphaTestEnable = material.GetFloat("_AlphaCutoffEnable") == 1.0;
// SurfaceType surfaceType = (SurfaceType)material.GetFloat("_SurfaceType");
// BlendMode blendMode = (BlendMode)material.GetFloat("_BlendMode");
// DoubleSidedMode doubleSidedMode = (DoubleSidedMode)material.GetFloat("_DoubleSidedMode");
}
// if (surfaceType == SurfaceType.Opaque)
// {
// material.SetOverrideTag("RenderType", alphaTestEnable ? "TransparentCutout" : "");
// material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
// material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
// material.SetInt("_ZWrite", 1);
// material.renderQueue = alphaTestEnable ? (int)UnityEngine.Rendering.RenderQueue.AlphaTest : -1;
// }
// else
// {
// material.SetOverrideTag("RenderType", "Transparent");
// material.SetInt("_ZWrite", 0);
// material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
materialImporter.userData = JsonUtility.ToJson(layersGUID);
}
// switch (blendMode)
// {
// case BlendMode.Lerp:
// material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
// material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
// break;
bool LayersGUI(AssetImporter materialImporter)
{
bool saveMaterialLayers = false;
// case BlendMode.Add:
// material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
// material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
// break;
EditorGUI.indentLevel++;
GUILayout.Label(styles.layers, EditorStyles.boldLabel);
for (int i = 0; i < m_MaterialLayers.Length; i++)
{
EditorGUILayout.BeginHorizontal();
{
EditorGUI.BeginChangeCheck();
m_MaterialLayers[i] = EditorGUILayout.ObjectField(styles.materialLayerLabels[i], m_MaterialLayers[i], typeof(Material), true) as Material;
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(materialImporter, "Change layer material");
SynchronizeLayerProperties(i);
saveMaterialLayers = true;
}
// case BlendMode.SoftAdd:
// material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusDstColor);
// material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
// break;
if (GUILayout.Button(styles.syncButton, GUILayout.Width(kSyncButtonWidth)))
{
SynchronizeLayerProperties(i);
}
}
EditorGUILayout.EndHorizontal();
}
// case BlendMode.Multiply:
// material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
// material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
// break;
if (saveMaterialLayers)
{
SaveMaterialLayers(materialImporter);
}
// case BlendMode.Premultiply:
// material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
// material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
// break;
// }
// }
EditorGUI.indentLevel--;
// if (doubleSidedMode == DoubleSidedMode.None)
// {
// material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Back);
// }
// else
// {
// material.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
// }
return saveMaterialLayers;
}
// if (doubleSidedMode == DoubleSidedMode.DoubleSidedLightingFlip)
// {
// material.EnableKeyword("_DOUBLESIDED_LIGHTING_FLIP");
// material.DisableKeyword("_DOUBLESIDED_LIGHTING_MIRROR");
// }
// else if (doubleSidedMode == DoubleSidedMode.DoubleSidedLightingMirror)
// {
// material.DisableKeyword("_DOUBLESIDED_LIGHTING_FLIP");
// material.EnableKeyword("_DOUBLESIDED_LIGHTING_MIRROR");
// }
// else
// {
// material.DisableKeyword("_DOUBLESIDED_LIGHTING_FLIP");
// material.DisableKeyword("_DOUBLESIDED_LIGHTING_MIRROR");
// }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
{
FindOptionProperties(props);
// SetKeyword(material, "_ALPHATEST_ON", alphaTestEnable);
// SetKeyword(material, "_NORMALMAP", material.GetTexture("_NormalMap"));
// SetKeyword(material, "_NORMALMAP_TANGENT_SPACE", (NormalMapSpace)material.GetFloat("_NormalMapSpace") == NormalMapSpace.TangentSpace);
// SetKeyword(material, "_MASKMAP", material.GetTexture("_MaskMap"));
// SetKeyword(material, "_SPECULAROCCLUSIONMAP", material.GetTexture("_SpecularOcclusionMap"));
// SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", ((SmoothnessMapChannel)material.GetFloat("_SmoothnessTextureChannel")) == SmoothnessMapChannel.AlbedoAlpha);
// SetKeyword(material, "_EMISSIVE_COLOR", ((EmissiveColorMode)material.GetFloat("_EmissiveColorMode")) == EmissiveColorMode.UseEmissiveColor);
// SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture("_EmissiveColorMap"));
// SetKeyword(material, "_HEIGHTMAP", material.GetTexture("_HeightMap"));
// SetKeyword(material, "_HEIGHTMAP_AS_DISPLACEMENT", (HeightmapMode)material.GetFloat("_HeightMapMode") == HeightmapMode.Displacement);
m_MaterialEditor = materialEditor;
// /*
// // Setup lightmap emissive flags
// MaterialGlobalIlluminationFlags flags = material.globalIlluminationFlags;
// if ((flags & (MaterialGlobalIlluminationFlags.BakedEmissive | MaterialGlobalIlluminationFlags.RealtimeEmissive)) != 0)
// {
// flags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack;
// if (!shouldEmissionBeEnabled)
// flags |= MaterialGlobalIlluminationFlags.EmissiveIsBlack;
m_MaterialEditor.serializedObject.Update();
// material.globalIlluminationFlags = flags;
// }
// */
//}
Material material = materialEditor.target as Material;
AssetImporter materialImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(material.GetInstanceID()));
//static bool ShouldEmissionBeEnabled(Material mat, Color color)
//{
// //var realtimeEmission = (mat.globalIlluminationFlags & MaterialGlobalIlluminationFlags.RealtimeEmissive) > 0;
// //return color.maxColorComponent > 0.1f / 255.0f || realtimeEmission;
InitializeMaterialLayers(materialImporter);
// return false;
//}
EditorGUI.BeginChangeCheck();
{
ShaderOptionsGUI();
EditorGUILayout.Space();
//bool HasValidEmissiveKeyword (Material material)
//{
// /*
// // Material animation might be out of sync with the material keyword.
// // So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// // (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
// bool hasEmissionKeyword = material.IsKeywordEnabled ("_EMISSION");
// if (!hasEmissionKeyword && ShouldEmissionBeEnabled (material, emissionColorForRendering.colorValue))
// return false;
// else
// return true;
// */
ShaderInputOptionsGUI();
EditorGUILayout.Space();
}
if (EditorGUI.EndChangeCheck())
{
foreach (var obj in m_MaterialEditor.targets)
MaterialChanged((Material)obj);
}
// return true;
//}
bool saveMaterialLayers = LayersGUI(materialImporter);
//static void MaterialChanged(Material material)
//{
// SetupMaterial(material);
//}
m_MaterialEditor.serializedObject.ApplyModifiedProperties();
//static void SetKeyword(Material m, string keyword, bool state)
//{
// if (state)
// m.EnableKeyword (keyword);
// else
// m.DisableKeyword (keyword);
//}
if (saveMaterialLayers)
{
materialImporter.SaveAndReimport();
}
}
}
} // namespace UnityEditor

139
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitUI.cs


MaterialEditor m_MaterialEditor;
protected MaterialEditor m_MaterialEditor;
public void FindProperties (MaterialProperty[] props)
public void FindOptionProperties (MaterialProperty[] props)
{
surfaceType = FindProperty("_SurfaceType", props);
blendMode = FindProperty("_BlendMode", props);

smoothnessMapChannel = FindProperty("_SmoothnessTextureChannel", props);
emissiveColorMode = FindProperty("_EmissiveColorMode", props);
normalMapSpace = FindProperty("_NormalMapSpace", props);
heightMapMode = FindProperty("_HeightMapMode", props);
}
public void FindInputProperties(MaterialProperty[] props)
{
baseColor = FindProperty("_BaseColor", props);
baseColorMap = FindProperty("_BaseColorMap", props);
metalic = FindProperty("_Metalic", props);

normalMap = FindProperty("_NormalMap", props);
normalMapSpace = FindProperty("_NormalMapSpace", props);
heightMapMode = FindProperty("_HeightMapMode", props);
FindProperties (props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
FindOptionProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
FindInputProperties(props);
ShaderPropertiesGUI (material);
}
protected void ShaderOptionsGUI()
{
EditorGUI.indentLevel++;
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel);
SurfaceTypePopup();
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
{
BlendModePopup();
}
m_MaterialEditor.ShaderProperty(alphaCutoffEnable, Styles.alphaCutoffEnableText.text);
if (alphaCutoffEnable.floatValue == 1.0)
{
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text);
}
m_MaterialEditor.ShaderProperty(doubleSidedMode, Styles.doubleSidedModeText.text);
EditorGUI.indentLevel--;
}
protected void ShaderInputOptionsGUI()
{
EditorGUI.indentLevel++;
GUILayout.Label(Styles.InputsOptionsText, EditorStyles.boldLabel);
m_MaterialEditor.ShaderProperty(smoothnessMapChannel, Styles.smoothnessMapChannelText.text);
m_MaterialEditor.ShaderProperty(emissiveColorMode, Styles.emissiveColorModeText.text);
m_MaterialEditor.ShaderProperty(normalMapSpace, Styles.normalMapSpaceText.text);
m_MaterialEditor.ShaderProperty(heightMapMode, Styles.heightMapModeText.text);
EditorGUI.indentLevel--;
}
protected void ShaderInputGUI()
{
EditorGUI.indentLevel++;
bool isAlbedoAlpha = (SmoothnessMapChannel)smoothnessMapChannel.floatValue == SmoothnessMapChannel.AlbedoAlpha;
bool useEmissiveMask = (EmissiveColorMode)emissiveColorMode.floatValue == EmissiveColorMode.UseEmissiveMask;
GUILayout.Label(Styles.InputsText, EditorStyles.boldLabel);
m_MaterialEditor.TexturePropertySingleLine(isAlbedoAlpha ? Styles.baseColorSmoothnessText : Styles.baseColorText, baseColorMap, baseColor);
m_MaterialEditor.ShaderProperty(metalic, Styles.metalicText);
m_MaterialEditor.ShaderProperty(smoothness, Styles.smoothnessText);
if (isAlbedoAlpha && useEmissiveMask)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapESText, maskMap);
else if (useEmissiveMask)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapEText, maskMap);
else if (isAlbedoAlpha)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapSText, maskMap);
else
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
ShaderPropertiesGUI (material);
m_MaterialEditor.TexturePropertySingleLine(Styles.specularOcclusionMapText, specularOcclusionMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap, heightScale, heightBias);
if (!useEmissiveMask)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor);
}
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
EditorGUI.indentLevel--;
}
public void ShaderPropertiesGUI (Material material)

// Detect any changes to the material
EditorGUI.BeginChangeCheck();
{
GUILayout.Label(Styles.OptionText, EditorStyles.boldLabel);
SurfaceTypePopup();
if ((SurfaceType)surfaceType.floatValue == SurfaceType.Transparent)
{
BlendModePopup();
}
m_MaterialEditor.ShaderProperty(alphaCutoffEnable, Styles.alphaCutoffEnableText.text);
if (alphaCutoffEnable.floatValue == 1.0)
{
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text);
}
m_MaterialEditor.ShaderProperty(doubleSidedMode, Styles.doubleSidedModeText.text);
ShaderOptionsGUI();
EditorGUILayout.Space();
GUILayout.Label(Styles.InputsOptionsText, EditorStyles.boldLabel);
m_MaterialEditor.ShaderProperty(smoothnessMapChannel, Styles.smoothnessMapChannelText.text);
m_MaterialEditor.ShaderProperty(emissiveColorMode, Styles.emissiveColorModeText.text);
ShaderInputOptionsGUI();
bool isAlbedoAlpha = (SmoothnessMapChannel)smoothnessMapChannel.floatValue == SmoothnessMapChannel.AlbedoAlpha;
bool useEmissiveMask = (EmissiveColorMode)emissiveColorMode.floatValue == EmissiveColorMode.UseEmissiveMask;
GUILayout.Label(Styles.InputsText, EditorStyles.boldLabel);
m_MaterialEditor.TexturePropertySingleLine(isAlbedoAlpha ? Styles.baseColorSmoothnessText : Styles.baseColorText, baseColorMap, baseColor);
m_MaterialEditor.ShaderProperty(metalic, Styles.metalicText);
m_MaterialEditor.ShaderProperty(smoothness, Styles.smoothnessText);
if (isAlbedoAlpha && useEmissiveMask)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapESText, maskMap);
else if (useEmissiveMask)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapEText, maskMap);
else if (isAlbedoAlpha)
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapSText, maskMap);
else
m_MaterialEditor.TexturePropertySingleLine(Styles.maskMapText, maskMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.specularOcclusionMapText, specularOcclusionMap);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap);
m_MaterialEditor.ShaderProperty(normalMapSpace, Styles.normalMapSpaceText.text);
m_MaterialEditor.TexturePropertySingleLine(Styles.heightMapText, heightMap, heightScale, heightBias);
m_MaterialEditor.ShaderProperty(heightMapMode, Styles.heightMapModeText.text);
if (!useEmissiveMask)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor);
}
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
EditorGUILayout.Space();
ShaderInputGUI();
foreach (var obj in blendMode.targets)
foreach (var obj in m_MaterialEditor.targets)
MaterialChanged((Material)obj);
}
}

EditorGUI.showMixedValue = false;
}
static public void SetupMaterial(Material material)
protected void SetupMaterial(Material material)
{
// 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)

return true;
}
static void MaterialChanged(Material material)
protected void MaterialChanged(Material material)
{
SetupMaterial(material);
}

8
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered.mat


m_Colors:
- first:
name: _BaseColor0
second: {r: 1, g: 0, b: 0, a: 1}
second: {r: 0, g: 1, b: 0, a: 1}
second: {r: 0, g: 1, b: 0, a: 1}
second: {r: 0.31185117, g: 0.49926907, b: 0.75735295, a: 0.672}
second: {r: 0, g: 0, b: 1, a: 1}
second: {r: 1, g: 0, b: 0, a: 1}
second: {r: 1, g: 1, b: 0, a: 1}
second: {r: 1, g: 0, b: 0, a: 1}
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}

4
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Layered.mat.meta


fileFormatVersion: 2
guid: 6e7fa39a7d1b15c4184c9f51d86eba22
timeCreated: 1475855280
timeCreated: 1476108738
userData:
userData: '{"GUIDArray":["c569253e641dc934db7c3595b31890da","6816da50441b49245843695729d8968c","","6816da50441b49245843695729d8968c"]}'
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存