浏览代码
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017
/main
bfogerty
8 年前
当前提交
1bba1ba2
共有 10 个文件被更改,包括 372 次插入 和 4 次删除
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
21MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
-
49MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVRotatorNode.cs
-
50MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs
-
12MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs.meta
-
70MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs
-
12MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs.meta
-
141MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
-
12MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 9ab5e16c2083a4fe689209a8c1ae425e |
|||
<<<<<<< HEAD |
|||
timeCreated: 1495529915 |
|||
======= |
|||
>>>>>>> f9e75cae7d0f088d17985a220f4ca7ae3da1222a |
|||
nonModifiableTextures: [] |
|||
nonModifiableTextures: |
|||
- Texture_5537060b_db74_4900_8f2b_178ba97b7f11_Uniform: {fileID: 2800000, guid: 6e8d12f68bae2294da814f9d4c81b29a, |
|||
type: 3} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.MaterialGraph; |
|||
using RMGUI.GraphView; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
[Serializable] |
|||
class AddManyContolPresenter : GraphControlPresenter |
|||
{ |
|||
|
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
|
|||
var addNode = node as UnityEngine.MaterialGraph.AddManyNode; |
|||
if (addNode == null) |
|||
return; |
|||
|
|||
if (GUILayout.Button("Add Slot")) |
|||
{ |
|||
addNode.AddInputSlot(); |
|||
addNode.OnModified(); |
|||
} |
|||
if (GUILayout.Button("Remove Slot")) |
|||
{ |
|||
addNode.RemoveInputSlot(); |
|||
addNode.OnModified(); |
|||
} |
|||
} |
|||
|
|||
public override float GetHeight() |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight * 2 + 10 * EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public class AddManyNodePresenter : MaterialNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphElementPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<AddManyContolPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphElementPresenter> { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0d89e5c0d48973c4ab16793131164a16 |
|||
timeCreated: 1495530357 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
using System.Linq; |
|||
using System.Collections; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Advanced/AddMultiple")] |
|||
public class AddManyNode : FunctionNInNOut, IGeneratesFunction |
|||
{ |
|||
int m_nodeInputCount = 2; |
|||
|
|||
public void AddInputSlot() |
|||
{ |
|||
string inputName = "Input" + GetInputSlots<ISlot>().Count().ToString(); |
|||
AddSlot(inputName, inputName, Graphing.SlotType.Input, SlotValueType.Dynamic); |
|||
} |
|||
|
|||
public AddManyNode() |
|||
{ |
|||
name = "AddMany"; |
|||
for(int i = 0; i < m_nodeInputCount; ++i) |
|||
{ |
|||
AddInputSlot(); |
|||
} |
|||
|
|||
AddSlot("Sum", "finalSum", Graphing.SlotType.Output, SlotValueType.Dynamic); |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public void OnModified() |
|||
{ |
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
|
|||
protected override string GetFunctionName() |
|||
{ |
|||
return "unity_AddMultiple"; |
|||
} |
|||
|
|||
string GetSumOfAllInputs() |
|||
{ |
|||
string sumString = ""; |
|||
int inputsLeft = GetInputSlots<ISlot>().Count(); |
|||
|
|||
foreach (ISlot slot in GetInputSlots<ISlot>()) |
|||
{ |
|||
sumString += GetShaderOutputName(slot.id); |
|||
if (inputsLeft > 1) |
|||
sumString += " + "; |
|||
--inputsLeft; |
|||
} |
|||
|
|||
return sumString; |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetFunctionPrototype(), false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("finalSum = " + GetSumOfAllInputs() + ";", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0518e86ee51c0b844a8721050900863a |
|||
timeCreated: 1495486161 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
using System.Linq; |
|||
using System.Collections; |
|||
using System; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public abstract class FunctionNInNOut : AbstractMaterialNode, IGeneratesBodyCode |
|||
{ |
|||
|
|||
public FunctionNInNOut() |
|||
{ |
|||
name = "FunctionNInNOut"; |
|||
} |
|||
|
|||
public override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
base.UpdateNodeAfterDeserialization(); |
|||
foreach (var slot in GetSlots<MaterialSlot>()) |
|||
{ |
|||
slot.showValue = true; |
|||
} |
|||
} |
|||
|
|||
public int AddSlot(string displayName, string nameInShader, SlotType slotType, SlotValueType valueType) |
|||
{ |
|||
int nextSlotId; |
|||
if (slotType == SlotType.Output) |
|||
nextSlotId = -GetOutputSlots<MaterialSlot>().Count() + 1; |
|||
else |
|||
nextSlotId = GetInputSlots<MaterialSlot>().Count() + 1; |
|||
|
|||
AddSlot(new MaterialSlot(nextSlotId, displayName, nameInShader, slotType, valueType, Vector4.zero, true)); |
|||
return nextSlotId; |
|||
} |
|||
|
|||
public void RemoveOutputSlot() |
|||
{ |
|||
var lastSlotId = -GetOutputSlots<ISlot>().Count(); |
|||
RemoveSlotById(lastSlotId); |
|||
} |
|||
|
|||
public void RemoveInputSlot() |
|||
{ |
|||
var lastSlotId = GetInputSlots<ISlot>().Count(); |
|||
RemoveSlotById(lastSlotId); |
|||
} |
|||
|
|||
private void RemoveSlotById(int slotID) |
|||
{ |
|||
if (slotID == 0) |
|||
return; |
|||
RemoveSlot(slotID); |
|||
} |
|||
|
|||
public string GetSlotTypeName(int slotId) |
|||
{ |
|||
return ConvertConcreteSlotValueTypeToString(FindSlot<MaterialSlot>(slotId).concreteValueType); |
|||
} |
|||
|
|||
protected string GetShaderOutputName(int slotId) |
|||
{ |
|||
return FindSlot<MaterialSlot>(slotId).shaderOutputName; |
|||
} |
|||
|
|||
// Must override this
|
|||
protected abstract string GetFunctionName(); |
|||
|
|||
private string GetFunctionParameters() |
|||
{ |
|||
string param = ""; |
|||
int remainingParams = GetSlots<ISlot>().Count(); |
|||
foreach (ISlot inSlot in GetSlots<ISlot>()) |
|||
{ |
|||
if (inSlot.isOutputSlot) |
|||
param += "out "; |
|||
|
|||
param += precision + GetSlotTypeName(inSlot.id) + " "; |
|||
param += GetShaderOutputName(inSlot.id); |
|||
|
|||
if (remainingParams > 1) |
|||
param += ", "; |
|||
--remainingParams; |
|||
} |
|||
|
|||
return param; |
|||
} |
|||
|
|||
private string GetFunctionCallParameters(GenerationMode generationMode) |
|||
{ |
|||
string param = ""; |
|||
int remainingParams = GetSlots<ISlot>().Count(); |
|||
foreach (ISlot inSlot in GetSlots<ISlot>()) |
|||
{ |
|||
param += GetSlotValue(inSlot.id, generationMode); |
|||
|
|||
if (remainingParams > 1) |
|||
param += ", "; |
|||
--remainingParams; |
|||
} |
|||
|
|||
return param; |
|||
} |
|||
|
|||
protected string GetFunctionPrototype() |
|||
{ |
|||
return "inline " + "void" + " " + GetFunctionName() + |
|||
" (" + |
|||
GetFunctionParameters() + |
|||
")"; |
|||
} |
|||
|
|||
private string GetFunctionCall(GenerationMode generationMode) |
|||
{ |
|||
return GetFunctionName() + |
|||
" (" + |
|||
GetFunctionCallParameters(generationMode) + |
|||
");"; |
|||
} |
|||
|
|||
private string GetOutputDeclaration() |
|||
{ |
|||
string outDeclaration = ""; |
|||
foreach (ISlot outSlot in GetOutputSlots<ISlot>()) |
|||
{ |
|||
outDeclaration += "\n " + precision + GetSlotTypeName(outSlot.id) + " " + GetVariableNameForSlot(outSlot.id) + ";\n"; |
|||
} |
|||
|
|||
return outDeclaration; |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
outputString.AddShaderChunk(GetOutputDeclaration(), false); |
|||
outputString.AddShaderChunk(GetFunctionCall(generationMode), false); |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ef27c8075e4d9594eb52411936ff46cc |
|||
timeCreated: 1495483390 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue