浏览代码

Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017

/main
Matt Dean 8 年前
当前提交
eeb9f4ff
共有 8 个文件被更改,包括 146 次插入13 次删除
  1. 7
      MaterialGraphProject/Assets/Andre/Nodes/ToggleNode.cs
  2. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs
  4. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/ColorNode.cs
  5. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs
  6. 31
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs
  7. 64
      MaterialGraphProject/Assets/Eduardo/VertexNormalNode.cs
  8. 12
      MaterialGraphProject/Assets/Eduardo/VertexNormalNode.cs.meta

7
MaterialGraphProject/Assets/Andre/Nodes/ToggleNode.cs


UpdateNodeAfterDeserialization();
}
/* public override bool hasPreview
{
get { return true; }
}*/
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector1, Vector2.zero));

public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, 0f, PropertyChunk.HideState.Visible));
visitor.AddShaderProperty(new FloatPropertyChunk(propertyName, description, 0f, FloatPropertyChunk.FloatType.Toggle, PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/ColorNodePresenter.cs


using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{

if (cNode == null)
return;
cNode.color = EditorGUILayout.ColorField("Color", cNode.color);
cNode.exposedState = (PropertyNode.ExposedState)EditorGUILayout.EnumPopup(new GUIContent("Exposed"), cNode.exposedState);
cNode.color = EditorGUILayout.ColorField(new GUIContent ("Color"), cNode.color, true, true, cNode.HDR, new ColorPickerHDRConfig(0f, 8f, 0.125f, 3f));
cNode.HDR = EditorGUILayout.Toggle("HDR", cNode.HDR);
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
return EditorGUIUtility.singleLineHeight + 18 * EditorGUIUtility.standardVerticalSpacing;
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyChunkTests.cs


public void TestColorChunkReturnsValidValues()
{
var expectedPropertyString = "ThePropertyName(\"ThePropertyDescription\", Color) = (1,0,0,1)";
var chunk = new ColorPropertyChunk(kPropertyName, kPropertyDescription, Color.red, PropertyChunk.HideState.Visible);
var chunk = new ColorPropertyChunk(kPropertyName, kPropertyDescription, Color.red, ColorPropertyChunk.ColorType.Default, PropertyChunk.HideState.Visible);
Assert.AreEqual(kPropertyName, chunk.propertyName);
Assert.AreEqual(kPropertyDescription, chunk.propertyDescription);
Assert.AreEqual(expectedPropertyString, chunk.GetPropertyString());

23
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/ColorNode.cs


[Title("Input/Color")]
public class ColorNode : PropertyNode, IGeneratesBodyCode
{
[SerializeField]
[SerializeField]
private bool m_HDR;
[SerializeField]
public bool HDR
{
get { return m_HDR; }
set
{
if (m_HDR == value)
return;
m_HDR = value;
if (onModified != null)
{
onModified(this, ModificationScope.Node);
}
}
}
public ColorNode()
{

public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)
{
if (exposedState == ExposedState.Exposed)
visitor.AddShaderProperty(new ColorPropertyChunk(propertyName, description, color, PropertyChunk.HideState.Visible));
visitor.AddShaderProperty(new ColorPropertyChunk(propertyName, description, color, m_HDR ? ColorPropertyChunk.ColorType.HDR : ColorPropertyChunk.ColorType.Default , PropertyChunk.HideState.Visible));
}
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode)

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ColorPropertyChunk.cs


{
public class ColorPropertyChunk : PropertyChunk
{
public enum ColorType
{
Default,
HDR
}
private ColorType m_colorType;
public ColorPropertyChunk(string propertyName, string propertyDescription, Color defaultColor, HideState hideState)
public ColorPropertyChunk(string propertyName, string propertyDescription, Color defaultColor, ColorType colorType, HideState hideState)
m_colorType = colorType;
m_DefaultColor = defaultColor;
}

public override string GetPropertyString()
{
var result = new StringBuilder();
if(m_colorType == ColorType.HDR)
result.Append ("[HDR]");
result.Append(propertyName);
result.Append("(\"");
result.Append(propertyDescription);

31
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/FloatPropertyChunk.cs


{
public class FloatPropertyChunk : PropertyChunk
{
public enum FloatType
{
Float,
Toggle,
Range,
PowerSlider
}
private readonly FloatType m_FloatType;
private readonly Vector3 m_rangeValues = new Vector3(0f, 1f, 2f);
public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{

public FloatPropertyChunk(string propertyName, string propertyDescription, float defaultValue, FloatType floatType, HideState hideState)
: base(propertyName, propertyDescription, hideState)
{
m_FloatType = floatType;
m_DefaultValue = defaultValue;
}
public float defaultValue
{
get { return m_DefaultValue; }

{
var result = new StringBuilder();
if (m_FloatType == FloatType.Toggle)
result.Append ("[Toggle]");
else if(m_FloatType == FloatType.PowerSlider)
result.Append ("[PowerSlider(" + m_rangeValues.z + ")]");
result.Append("\", Float) = ");
if (m_FloatType == FloatType.Float || m_FloatType == FloatType.Toggle) {
result.Append ("\", Float) = ");
}else if(m_FloatType == FloatType.Range || m_FloatType == FloatType.PowerSlider){
result.Append ("\", Range(");
result.Append (m_rangeValues.x + ", " + m_rangeValues.y);
result.Append (")) = ");
}
result.Append(defaultValue);
return result.ToString();
}

64
MaterialGraphProject/Assets/Eduardo/VertexNormalNode.cs


using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Input/Geometry/Vertex Normal")]
public class VertexNormalNode : AbstractMaterialNode
{
private const string kOutputSlotName = "XYZW";
private const string kOutputSlotNameXYZ = "XYZ";
private const string kOutputSlotNameX = "X";
private const string kOutputSlotNameY = "Y";
private const string kOutputSlotNameZ = "Z";
private const string kOutputSlotNameW = "W";
public const int OutputSlotId = 0;
public const int OutputSlotIdXYZ = 1;
public const int OutputSlotIdX = 2;
public const int OutputSlotIdY = 3;
public const int OutputSlotIdZ = 4;
public const int OutputSlotIdW = 5;
public VertexNormalNode()
{
name = "VertexNormal";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdXYZ, kOutputSlotNameXYZ, kOutputSlotNameXYZ, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdX, kOutputSlotNameX, kOutputSlotNameX, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdY, kOutputSlotNameY, kOutputSlotNameY, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdZ, kOutputSlotNameZ, kOutputSlotNameZ, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotIdW, kOutputSlotNameW, kOutputSlotNameW, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, OutputSlotIdXYZ, OutputSlotIdX, OutputSlotIdY, OutputSlotIdZ, OutputSlotIdW }; }
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlotIdXYZ:
return "v.normal.xyz";
case OutputSlotIdX:
return "v.normal.x";
case OutputSlotIdY:
return "v.normal.y";
case OutputSlotIdZ:
return "v.normal.z";
case OutputSlotIdW:
return "v.normal.w";
default:
return "v.normal";
}
}
}
}

12
MaterialGraphProject/Assets/Eduardo/VertexNormalNode.cs.meta


fileFormatVersion: 2
guid: c5532eff58cce43468e6f88386d8ac1c
timeCreated: 1495660146
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存