浏览代码

SwizzleNode now working

/main
Florent Guinier 8 年前
当前提交
7ae13517
共有 4 个文件被更改,包括 100 次插入32 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  2. 72
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs
  3. 47
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs
  4. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs.meta

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(AbstractSubGraphIONode)] = typeof(SubgraphIONodePresenter);
typeMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterPresenter);
typeMapper[typeof(LevelNode)] = typeof(LevelNodePresenter);
typeMapper[typeof(SwizzleNode)] = typeof(SwizzleNodePresenter);
}
}
}

72
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs


using UnityEngine.Graphing;
using System.Collections.Generic;
using System.Linq;
enum SwizzleChannels
public enum SwizzleChannel
{
R = 0,
G = 1,

[SerializeField]
private SwizzleChannels[] m_SwizzleChannels = new SwizzleChannels[4] { SwizzleChannels.R, SwizzleChannels.G, SwizzleChannels.B, SwizzleChannels.A };
private SwizzleChannel[] m_SwizzleChannels = new SwizzleChannel[4] { SwizzleChannel.R, SwizzleChannel.G, SwizzleChannel.B, SwizzleChannel.A };
public SwizzleNode()
public SwizzleChannel[] swizzleChannels
name = "SwizzleNode";
}
get { return m_SwizzleChannels; }
set
{
if (m_SwizzleChannels == value)
return;
/*
public override float GetNodeUIHeight(float width)
{
return EditorGUIUtility.singleLineHeight;
m_SwizzleChannels = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
public override GUIModificationType NodeUI(Rect drawArea)
public SwizzleNode()
base.NodeUI(drawArea);
string[] channelNames = {"X", "Y", "Z", "W"};
string[] values = {"0", "1", "Input1.x", "Input1.y", "Input1.z", "Input1.w", "Input2.x", "Input2.y", "Input2.z", "Input2.w"};
EditorGUI.BeginChangeCheck();
for (int n = 0; n < 4; n++)
m_SwizzleChannel[n] = EditorGUI.Popup(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), channelNames[n] + "=", m_SwizzleChannel[n], values);
if (EditorGUI.EndChangeCheck())
{
pixelGraph.RevalidateGraph();
return GUIModificationType.Repaint;
}
return GUIModificationType.None;
name = "SwizzleNode";
*/
protected override string GetFunctionName()
{
return "";

{
string[] channelNames = { "x", "y", "z", "w" };
int numInputChannels = (int)FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType;
int numOutputChannels = (int)FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType;
string[] channelNames = { "r", "g", "b", "a" };
var inputSlot = FindInputSlot<MaterialSlot>(InputSlotId);
var outputSlot = FindOutputSlot<MaterialSlot>(OutputSlotId);
if (inputSlot == null)
return "1.0";
if (outputSlot == null)
return "1.0";
int numInputChannels = (int)inputSlot.concreteValueType;
int numOutputChannels = (int)outputSlot.concreteValueType;
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0)
numInputChannels = 0;
if (owner.GetEdges(outputSlot.slotReference).ToList().Count() == 0)
numOutputChannels = 0;
if (numOutputChannels == 0)
{

//float4(1.0,1.0,1.0,1.0)
if (numInputChannels == 0)
{
outputString += "1.0, 1.0, 1.0, 1.0)";
outputString += "1.0, 1.0, 1.0, 1.0).";
}
else
{

//float4(arg1.xy
int i = 0;
for (; i < numInputChannels; i++)
for (; i < numInputChannels; ++i)
{
int channel = (int)m_SwizzleChannels[i];
outputString += channelNames[channel];

}
//float4(arg1.xy, 1.0, 1.0).rg
for (int j = 0; j < numOutputChannels; j++)
for (int j = 0; j < numOutputChannels; ++j)
int channel = (int)m_SwizzleChannels[j];
outputString += channelNames[channel];
outputString += channelNames[j];
}
return outputString;
}

47
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class SwizzleControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as SwizzleNode;
if (tNode == null)
return;
SwizzleNode.SwizzleChannel[] newSwizzleChannels = (SwizzleNode.SwizzleChannel[])tNode.swizzleChannels.Clone();
EditorGUI.BeginChangeCheck();
newSwizzleChannels[0] = (SwizzleNode.SwizzleChannel)EditorGUILayout.EnumPopup("Red output:", newSwizzleChannels[0]);
newSwizzleChannels[1] = (SwizzleNode.SwizzleChannel)EditorGUILayout.EnumPopup("Green output:", newSwizzleChannels[1]);
newSwizzleChannels[2] = (SwizzleNode.SwizzleChannel)EditorGUILayout.EnumPopup("Blue output:", newSwizzleChannels[2]);
newSwizzleChannels[3] = (SwizzleNode.SwizzleChannel)EditorGUILayout.EnumPopup("Alpha output:", newSwizzleChannels[3]);
if (EditorGUI.EndChangeCheck())
{
tNode.swizzleChannels = newSwizzleChannels;
}
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight * 4 + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SwizzleNodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<SwizzleControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs.meta


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