浏览代码
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Eduardo Chaves
8 年前
当前提交
c30e0ee9
共有 5 个文件被更改,包括 149 次插入 和 36 次删除
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
116MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs
-
9MaterialGraphProject/Assets/Eduardo.meta
-
47MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/SwizzleNodePresenter.cs.meta
|
|||
using UnityEngine.Graphing; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
public class SwizzleNode : Function2Input |
|||
public class SwizzleNode : Function1Input |
|||
[SerializeField] |
|||
private int[] m_SwizzleChannel = new int[4]; |
|||
|
|||
public SwizzleNode() |
|||
public enum SwizzleChannel |
|||
name = "SwizzleNode"; |
|||
R = 0, |
|||
G = 1, |
|||
B = 2, |
|||
A = 3, |
|||
/* |
|||
public override float GetNodeUIHeight(float width) |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight; |
|||
} |
|||
[SerializeField] |
|||
private SwizzleChannel[] m_SwizzleChannels = new SwizzleChannel[4] { SwizzleChannel.R, SwizzleChannel.G, SwizzleChannel.B, SwizzleChannel.A }; |
|||
public override GUIModificationType NodeUI(Rect drawArea) |
|||
public SwizzleChannel[] swizzleChannels |
|||
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()) |
|||
get { return m_SwizzleChannels; } |
|||
set |
|||
pixelGraph.RevalidateGraph(); |
|||
return GUIModificationType.Repaint; |
|||
if (m_SwizzleChannels == value) |
|||
return; |
|||
|
|||
m_SwizzleChannels = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
return GUIModificationType.None; |
|||
} |
|||
|
|||
public SwizzleNode() |
|||
{ |
|||
name = "SwizzleNode"; |
|||
*/ |
|||
|
|||
protected override string GetFunctionCallBody(string inputValue1, string inputValue2) |
|||
protected override string GetFunctionCallBody(string inputValue) |
|||
string[] inputValues = { inputValue1, inputValue2 }; |
|||
string[] channelNames = { "x", "y", "z", "w" }; |
|||
string s = precision + "4("; |
|||
for (int n = 0; n < 4; n++) |
|||
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) |
|||
int c = m_SwizzleChannel[n]; |
|||
if (c < 2) |
|||
s += c; |
|||
else |
|||
return "1.0"; |
|||
} |
|||
|
|||
string outputString = precision + "4("; |
|||
//float4(1.0,1.0,1.0,1.0)
|
|||
if (numInputChannels == 0) |
|||
{ |
|||
outputString += "1.0, 1.0, 1.0, 1.0)."; |
|||
} |
|||
else |
|||
{ |
|||
//float4(arg1.
|
|||
outputString += inputValue + "."; |
|||
|
|||
//float4(arg1.xy
|
|||
int i = 0; |
|||
for (; i < numInputChannels; ++i) |
|||
c -= 2; |
|||
s += inputValues[c >> 2] + "." + channelNames[c & 3]; |
|||
int channel = (int)m_SwizzleChannels[i]; |
|||
outputString += channelNames[channel]; |
|||
} |
|||
|
|||
//float4(arg1.xy, 1.0, 1.0)
|
|||
for (; i < 4; i++) |
|||
{ |
|||
outputString += ", 1.0"; |
|||
s += (n == 3) ? ")" : ","; |
|||
outputString += ")."; |
|||
return s; |
|||
|
|||
//float4(arg1.xy, 1.0, 1.0).rg
|
|||
for (int j = 0; j < numOutputChannels; ++j) |
|||
{ |
|||
outputString += channelNames[j]; |
|||
} |
|||
return outputString; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f496182509f853041b421f926a6283ee |
|||
folderAsset: yes |
|||
timeCreated: 1495479962 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 53bfb9e60f364eb44a4f0e0fc53f4325 |
|||
timeCreated: 1495474251 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue