浏览代码
cleaned up decal shader, added custom UI for decal shader
/Add-support-for-light-specular-color-tint
cleaned up decal shader, added custom UI for decal shader
/Add-support-for-light-specular-color-tint
Paul Melamed
7 年前
当前提交
a5eb21ff
共有 9 个文件被更改,包括 146 次插入 和 61 次删除
-
23ScriptableRenderPipeline/HDRenderPipeline/Decal/DecalSystem.cs
-
5ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Decal.shader
-
14ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/DecalData.hlsl
-
21ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
-
23ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
-
15ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassDBuffer.hlsl
-
1ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
-
105ScriptableRenderPipeline/HDRenderPipeline/Material/Decal/Editor/DecalUI.cs
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class DecalUI : ShaderGUI |
|||
{ |
|||
protected static class Styles |
|||
{ |
|||
public static string InputsText = "Inputs"; |
|||
|
|||
public static GUIContent baseColorText = new GUIContent("Base Color + Blend", "Albedo (RGB) and Blend Factor (A)"); |
|||
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map (BC7/BC5/DXT5(nm))"); |
|||
public static GUIContent decalBlendText = new GUIContent("Decal Blend", "Combines with Base Color (A)"); |
|||
} |
|||
|
|||
protected MaterialProperty baseColorMap = new MaterialProperty(); |
|||
protected const string kBaseColorMap = "_BaseColorMap"; |
|||
|
|||
protected MaterialProperty normalMap = new MaterialProperty(); |
|||
protected const string kNormalMap = "_NormalMap"; |
|||
|
|||
protected MaterialProperty decalBlend = new MaterialProperty(); |
|||
protected const string kDecalBlend = "_DecalBlend"; |
|||
|
|||
|
|||
|
|||
protected MaterialEditor m_MaterialEditor; |
|||
|
|||
// This is call by the inspector
|
|||
|
|||
void FindMaterialProperties(MaterialProperty[] props) |
|||
{ |
|||
baseColorMap = FindProperty(kBaseColorMap, props); |
|||
normalMap = FindProperty(kNormalMap, props); |
|||
decalBlend = FindProperty(kDecalBlend, props); |
|||
} |
|||
|
|||
static public void SetKeyword(Material m, string keyword, bool state) |
|||
{ |
|||
if (state) |
|||
m.EnableKeyword(keyword); |
|||
else |
|||
m.DisableKeyword(keyword); |
|||
} |
|||
|
|||
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if code change
|
|||
static public void SetupMaterialKeywordsAndPass(Material material) |
|||
{ |
|||
SetKeyword(material, "_COLORMAP", material.GetTexture(kBaseColorMap)); |
|||
SetKeyword(material, "_NORMALMAP", material.GetTexture(kNormalMap)); |
|||
} |
|||
|
|||
protected void SetupMaterialKeywordsAndPassInternal(Material material) |
|||
{ |
|||
SetupMaterialKeywordsAndPass(material); |
|||
} |
|||
|
|||
|
|||
public void ShaderPropertiesGUI(Material material) |
|||
{ |
|||
// Use default labelWidth
|
|||
EditorGUIUtility.labelWidth = 0f; |
|||
|
|||
// Detect any changes to the material
|
|||
EditorGUI.BeginChangeCheck(); |
|||
{ |
|||
EditorGUILayout.LabelField(Styles.InputsText, EditorStyles.boldLabel); |
|||
|
|||
EditorGUI.indentLevel++; |
|||
|
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap); |
|||
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap); |
|||
m_MaterialEditor.ShaderProperty(decalBlend, Styles.decalBlendText); |
|||
|
|||
EditorGUI.indentLevel--; |
|||
|
|||
} |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
foreach (var obj in m_MaterialEditor.targets) |
|||
SetupMaterialKeywordsAndPassInternal((Material)obj); |
|||
} |
|||
} |
|||
|
|||
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) |
|||
{ |
|||
m_MaterialEditor = materialEditor; |
|||
// We should always do this call at the beginning
|
|||
m_MaterialEditor.serializedObject.Update(); |
|||
|
|||
FindMaterialProperties(props); |
|||
|
|||
Material material = materialEditor.target as Material; |
|||
ShaderPropertiesGUI(material); |
|||
|
|||
// We should always do this call at the end
|
|||
m_MaterialEditor.serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue