浏览代码

Adding the Add node with dynamic inputs and respective presenter (W.I.P)

/main
Eduardo Chaves 8 年前
当前提交
620b809b
共有 8 个文件被更改,包括 185 次插入12 次删除
  1. 25
      MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs
  2. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  3. 21
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader
  4. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta
  5. 50
      MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs
  6. 12
      MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs.meta
  7. 70
      MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs
  8. 12
      MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs.meta

25
MaterialGraphProject/Assets/Eduardo/FunctionNInNOut.cs


public override void UpdateNodeAfterDeserialization()
{
base.UpdateNodeAfterDeserialization();
foreach (var slot in GetOutputSlots<MaterialSlot>())
foreach (var slot in GetSlots<MaterialSlot>())
{
slot.showValue = true;
}

{
int nextSlotId;
if (slotType == SlotType.Output)
nextSlotId = GetOutputSlots<ISlot>().Count() + 1;
nextSlotId = -GetOutputSlots<MaterialSlot>().Count() + 1;
nextSlotId = GetInputSlots<ISlot>().Count() + 1;
nextSlotId = GetInputSlots<MaterialSlot>().Count() + 1;
AddSlot(new MaterialSlot(-nextSlotId, displayName, nameInShader, slotType, valueType, Vector4.zero, true));
return -nextSlotId;
AddSlot(new MaterialSlot(nextSlotId, displayName, nameInShader, slotType, valueType, Vector4.zero, true));
return nextSlotId;
var lastSlotId = GetOutputSlots<ISlot>().Count();
var lastSlotId = -GetOutputSlots<ISlot>().Count();
RemoveSlotById(lastSlotId);
}

RemoveSlotById(lastSlotId);
}
void RemoveSlotById(int slotID)
private void RemoveSlotById(int slotID)
RemoveSlot(-slotID);
RemoveSlot(slotID);
}
public string GetSlotTypeName(int slotId)

protected string GetShaderOutputName(int slotId)
{
return FindSlot<MaterialSlot>(slotId).shaderOutputName;
}
// Must override this
protected abstract string GetFunctionName();
private string GetFunctionParameters()

param += "out ";
param += precision + GetSlotTypeName(inSlot.id) + " ";
param += FindSlot<MaterialSlot>(inSlot.id).shaderOutputName;
param += GetShaderOutputName(inSlot.id);
if (remainingParams > 1)
param += ", ";

return outDeclaration;
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();

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


typeMapper[typeof(ConstantsNode)] = typeof(ConstantsNodePresenter);
typeMapper[typeof(SwizzleNode)] = typeof(SwizzleNodePresenter);
typeMapper[typeof(BlendModeNode)] = typeof(BlendModeNodePresenter);
typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
}
}
}

21
MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader


Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNode6ab95a24-fc7d-4a4e-8828-a2de989d8143"
Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNodefb4e5d27-b55b-4c39-84a8-ae6dcd6d7631"
[NonModifiableTextureData] Texture_5537060b_db74_4900_8f2b_178ba97b7f11_Uniform("", 2D) = "white" {}
Cubemap_ee09e335_3be2_46ee_9d59_ce2673aeedf9_Uniform("", Cube) = "" {}
}

#pragma glsl
#pragma debug
inline float unity_remap_float (float arg1, float2 arg2, float2 arg3)
{
return arg1 * ((arg3.y - arg3.x) / (arg2.y - arg2.x)) + arg3.x;
}
sampler2D Texture_5537060b_db74_4900_8f2b_178ba97b7f11_Uniform;
samplerCUBE Cubemap_ee09e335_3be2_46ee_9d59_ce2673aeedf9_Uniform;
half4 meshUV0;
float3 worldViewDir;
float3 worldNormal;
};

o.meshUV0 = v.texcoord;
half4 uv0 = IN.meshUV0;
float3 worldSpaceViewDirection = IN.worldViewDir;
float3 worldSpaceNormal = normalize(IN.worldNormal);
float4 Texture_5537060b_db74_4900_8f2b_178ba97b7f11 = tex2D (Texture_5537060b_db74_4900_8f2b_178ba97b7f11_Uniform, uv0.xy);
float Remap_26b4b7a4_1c55_4c03_9830_fc5d53b3a504_Output = unity_remap_float (Texture_5537060b_db74_4900_8f2b_178ba97b7f11.r, float2 (0,1), float2 (7,-2));
float4 Cubemap_ee09e335_3be2_46ee_9d59_ce2673aeedf9 = texCUBElod (Cubemap_ee09e335_3be2_46ee_9d59_ce2673aeedf9_Uniform, float4(reflect(-worldSpaceViewDirection, worldSpaceNormal).xyz,Remap_26b4b7a4_1c55_4c03_9830_fc5d53b3a504_Output));
o.Emission = Cubemap_ee09e335_3be2_46ee_9d59_ce2673aeedf9;
}
ENDCG

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/HelperShader.shader.meta


fileFormatVersion: 2
guid: 9ab5e16c2083a4fe689209a8c1ae425e
timeCreated: 1495526268
timeCreated: 1495529915
nonModifiableTextures: []
nonModifiableTextures:
- Texture_5537060b_db74_4900_8f2b_178ba97b7f11_Uniform: {fileID: 2800000, guid: 6e8d12f68bae2294da814f9d4c81b29a,
type: 3}
userData:
assetBundleName:
assetBundleVariant:

50
MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs


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 };
}
}
}

12
MaterialGraphProject/Assets/Eduardo/Editor/AddManyNodePresenter.cs.meta


fileFormatVersion: 2
guid: 0d89e5c0d48973c4ab16793131164a16
timeCreated: 1495530357
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

70
MaterialGraphProject/Assets/Eduardo/FunctionNAddNode.cs


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);
}
}
}

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


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