浏览代码

Add HDR Color

- Add HDR Color node
- Add new constructor to ColorShaderProperty
- Add hdr flag to ColorControl
- Add HDR Color property to GraphInspectorView
/main
Matt Dean 7 年前
当前提交
8ea43935
共有 7 个文件被更改,包括 125 次插入6 次删除
  1. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorShaderProperty.cs
  2. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
  4. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  5. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
  6. 94
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/HDRColorNode.cs
  7. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/HDRColorNode.cs.meta

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorShaderProperty.cs


displayName = "Color";
}
public ColorShaderProperty(bool hdr)
{
displayName = "HDR Color";
HDR = hdr;
}
public override PropertyType propertyType
{
get { return PropertyType.Color; }

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs


public class ColorControlAttribute : Attribute, IControlAttribute
{
string m_Label;
bool m_Hdr;
public ColorControlAttribute(string label = null)
public ColorControlAttribute(string label = null, bool hdr = false)
m_Hdr = hdr;
return new ColorControlView(m_Label, node, propertyInfo);
return new ColorControlView(m_Label, m_Hdr, node, propertyInfo);
}
}

PropertyInfo m_PropertyInfo;
public ColorControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
public ColorControlView(string label, bool hdr, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;
m_PropertyInfo = propertyInfo;

if (!string.IsNullOrEmpty(label))
Add(new Label(label));
var colorField = new ColorField { value = (Color)m_PropertyInfo.GetValue(m_Node, null) };
ColorField colorField;
if(hdr)
colorField = new ColorField { value = (Color)m_PropertyInfo.GetValue(m_Node, null), hdr = true };
else
colorField = new ColorField { value = (Color)m_PropertyInfo.GetValue(m_Node, null) };
colorField.OnValueChanged(OnChange);
Add(colorField);
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs


public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (propertyInfo.PropertyType == typeof(Color))
return new ColorControlView(null, node, propertyInfo);
return new ColorControlView(null, false, node, propertyInfo);
if (typeof(Enum).IsAssignableFrom(propertyInfo.PropertyType))
return new EnumControlView(null, node, propertyInfo);
if (propertyInfo.PropertyType == typeof(Texture2D))

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


gm.AddItem(new GUIContent("Vector3"), false, () => AddProperty(new Vector3ShaderProperty()));
gm.AddItem(new GUIContent("Vector4"), false, () => AddProperty(new Vector4ShaderProperty()));
gm.AddItem(new GUIContent("Color"), false, () => AddProperty(new ColorShaderProperty()));
gm.AddItem(new GUIContent("HDR Color"), false, () => AddProperty(new ColorShaderProperty(true)));
gm.AddItem(new GUIContent("Integer"), false, () => AddProperty(new IntegerShaderProperty()));
gm.AddItem(new GUIContent("Texture"), false, () => AddProperty(new TextureShaderProperty()));
gm.AddItem(new GUIContent("Cubemap"), false, () => AddProperty(new CubemapShaderProperty()));

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs


else if (property is ColorShaderProperty)
{
var fProp = (ColorShaderProperty)property;
var colorField = new ColorField { name = "value", value = fProp.value };
ColorField colorField;
if(fProp.HDR)
colorField = new ColorField { name = "value", value = fProp.value, hdr = true };
else
colorField = new ColorField { name = "value", value = fProp.value };
colorField.OnValueChanged(OnColorChanged);
Add(colorField);
}

94
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/HDRColorNode.cs


using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "HDR Color")]
public class HDRColorNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Color m_Color;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public HDRColorNode()
{
name = "HDR Color";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ColorRGBAMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[ColorControl("", true)]
public Color color
{
get { return m_Color; }
set
{
if (m_Color == value)
return;
m_Color = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new ColorShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = color,
HDR = true
});
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(string.Format(
@"{0}4 {1} = IsGammaSpace() ? {0}4({2}, {3}, {4}, {5}) : {0}4(SRGBToLinear({0}3({2}, {3}, {4})), {5});"
, precision
, GetVariableNameForNode()
, color.r
, color.g
, color.b
, color.a), true);
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Color)
{
name = GetVariableNameForNode(),
colorValue = color
});
}
public IShaderProperty AsShaderProperty()
{
return new ColorShaderProperty { value = color, HDR = true };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/HDRColorNode.cs.meta


fileFormatVersion: 2
guid: 948ed387e8c19c14c82965be937d7284
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
正在加载...
取消
保存