浏览代码

Add HDR color support to Blackboard

/main
Matt Dean 7 年前
当前提交
affdcadf
共有 7 个文件被更改,包括 31 次插入26 次删除
  1. 20
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorShaderProperty.cs
  2. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ColorNode.cs
  3. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/HDRColorNode.cs
  4. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardFieldPropertyView.cs
  5. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ColorControl.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs

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


public class ColorShaderProperty : AbstractShaderProperty<Color>
{
[SerializeField]
private bool m_HDR;
private ColorMode m_ColorMode;
public bool HDR
public ColorMode colorMode
get { return m_HDR; }
get { return m_ColorMode; }
if (m_HDR == value)
if (m_ColorMode == value)
m_HDR = value;
m_ColorMode = value;
}
}

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

return string.Empty;
var result = new StringBuilder();
if (HDR)
if (colorMode == ColorMode.HDR)
result.Append("[HDR]");
result.Append(referenceName);
result.Append("(\"");

public override INode ToConcreteNode()
{
if(colorMode == ColorMode.HDR)
return new HDRColorNode { color = value };
return new ColorNode { color = value };
}
}

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


namespace UnityEditor.ShaderGraph
{
public enum ColorMode
{
Default,
HDR
}
[Title("Input", "Basic", "Color")]
public class ColorNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{

overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = color,
HDR = false
colorMode = ColorMode.Default
});
}

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


overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = color,
HDR = true
colorMode = ColorMode.HDR
});
}

public IShaderProperty AsShaderProperty()
{
return new ColorShaderProperty { value = color, HDR = true };
return new ColorShaderProperty { value = color, colorMode = ColorMode.HDR };
}
public int outputSlotId { get { return OutputSlotId; } }

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Blackboard/BlackboardFieldPropertyView.cs


else if (property is ColorShaderProperty)
{
var colorProperty = (ColorShaderProperty)property;
var field = new ColorField { value = property.defaultValue, hdr = colorProperty.HDR };
field.OnValueChanged(evt =>
var colorField = new ColorField { value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR };
colorField.OnValueChanged(evt =>
AddRow("Default", field);
AddRow("Default", colorField);
var colorModeField = new EnumField((Enum)colorProperty.colorMode);
colorModeField.OnValueChanged(evt =>
{
colorProperty.colorMode = (ColorMode)evt.newValue;
colorField.hdr = colorProperty.colorMode == ColorMode.HDR;
colorField.DoRepaint();
DirtyNodes();
});
AddRow("Mode", colorModeField);
}
else if (property is TextureShaderProperty)
{

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


namespace UnityEditor.ShaderGraph.Drawing.Controls
{
public enum ColorMode
{
Default,
HDR
}
[AttributeUsage(AttributeTargets.Property)]
public class ColorControlAttribute : Attribute, IControlAttribute
{

2
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("HDR Color"), false, () => AddProperty(new ColorShaderProperty() {colorMode = ColorMode.HDR}));
gm.AddItem(new GUIContent("Integer"), false, () => AddProperty(new IntegerShaderProperty()));
gm.AddItem(new GUIContent("Slider"), false, () => AddProperty(new SliderShaderProperty()));
gm.AddItem(new GUIContent("Boolean"), false, () => AddProperty(new BooleanShaderProperty()));

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


{
var fProp = (ColorShaderProperty)property;
ColorField colorField;
if(fProp.HDR)
if(fProp.colorMode == ColorMode.HDR)
colorField = new ColorField { name = "value", value = fProp.value, hdr = true };
else
colorField = new ColorField { name = "value", value = fProp.value };

正在加载...
取消
保存