浏览代码

allow specifying the UV channel on the UV node.

/main
Tim Cooper 8 年前
当前提交
0a990a6d
共有 11 个文件被更改,包括 135 次插入47 次删除
  1. 1
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs
  2. 16
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs
  3. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs
  4. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/fresnel.ShaderSubGraph
  5. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
  6. 28
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs
  7. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
  8. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs
  9. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
  10. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/UVNodeDrawData.cs
  11. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/UVNodeDrawData.cs.meta

1
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/Drawer/NodeDrawer.cs


using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using RMGUI.GraphView;
using UnityEngine;

16
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableNode.cs


m_Slots.Add(slot);
slot.owner = this;
if (onModified != null)
{
onModified(this, ModificationScope.Topological);
}
if (onModified != null)
{
onModified(this, ModificationScope.Topological);
}
}
public void RemoveSlot(int slotId)

//remove slots
m_Slots.RemoveAll(x => x.id == slotId);
if (onModified != null)
{
onModified(this, ModificationScope.Topological);
}
if (onModified != null)
{
onModified(this, ModificationScope.Topological);
}
}
public void RemoveSlotsNameNotMatching(IEnumerable<int> slotIds)

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/MaterialGraphDataSource.cs


map(typeof(AbstractMaterialNode), typeof(MaterialNodeDrawData));
map(typeof(ColorNode), typeof(ColorNodeDrawData));
map(typeof(TextureNode), typeof(TextureNodeDrawData));
map(typeof(UVNode), typeof(UVNodeDrawData));
map(typeof(Vector1Node), typeof(Vector1NodeDrawData));
map(typeof(Vector2Node), typeof(Vector2NodeDrawData));
map(typeof(Vector3Node), typeof(Vector3NodeDrawData));

41
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/fresnel.ShaderSubGraph


m_Name: fresnel
m_EditorClassIdentifier:
m_DrawingData:
m_SerializableSelection: []
m_SerializableSelection:
- c125654a-0be6-44c3-b177-54de0b1d84a7
m_MaterialSubGraph:
m_SerializableNodes:
- typeInfo:

\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":
\"Assembly-CSharp\"\n },\n \"JSONnodeData\": \"{\\n
\ \\\"m_Id\\\": -1,\\n \\\"m_DisplayName\\\": \\\"Input 1\\\",\\n \\\"m_SlotType\\\":
1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_ValueType\\\": 1,\\n
1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_ValueType\\\": 4,\\n
{\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
{\\n \\\"x\\\": 3.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
4,\\n \\\"m_ShaderOutputName\\\": \\\"Input1\\\",\\n \\\"m_ShowValue\\\":
false\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\":
1,\\n \\\"m_ShaderOutputName\\\": \\\"Input1\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\":
1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_ValueType\\\": 1,\\n
1,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_ValueType\\\": 2,\\n
{\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
4,\\n \\\"m_ShaderOutputName\\\": \\\"Input2\\\",\\n \\\"m_ShowValue\\\":
false\\n}\"\n }\n ]\n}"
{\\n \\\"x\\\": 1.0,\\n \\\"y\\\": 1.0,\\n \\\"z\\\":
1.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
3,\\n \\\"m_ShaderOutputName\\\": \\\"Input2\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n }\n ]\n}"
- typeInfo:
fullName: UnityEngine.MaterialGraph.SubGraphOutputNode
assemblyName: Assembly-CSharp

\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":
\"Assembly-CSharp\"\n },\n \"JSONnodeData\": \"{\\n
\ \\\"m_Id\\\": 1,\\n \\\"m_DisplayName\\\": \\\"Output 1\\\",\\n \\\"m_SlotType\\\":
0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_ValueType\\\": 1,\\n
0,\\n \\\"m_Priority\\\": 2147483647,\\n \\\"m_ValueType\\\": 2,\\n
4,\\n \\\"m_ShaderOutputName\\\": \\\"Output1\\\",\\n \\\"m_ShowValue\\\":
false\\n}\"\n }\n ]\n}"
3,\\n \\\"m_ShaderOutputName\\\": \\\"Output1\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n }\n ]\n}"
- typeInfo:
fullName: UnityEngine.MaterialGraph.WorldSpaceViewDirectionNode
assemblyName: Assembly-CSharp

0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
1,\\n \\\"m_ShaderOutputName\\\": \\\"Value\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n }\n ],\n \"m_PropertyName\": \"\",\n \"m_Description\":
\"\",\n \"m_Exposed\": 1,\n \"m_Value\": 1.0299999713897706\n}"
\"\",\n \"m_Exposed\": 1,\n \"m_Value\": 1.0\n}"
- typeInfo:
fullName: UnityEngine.MaterialGraph.SubtractNode
assemblyName: Assembly-CSharp

0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_CurrentValue\\\":
{\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
4,\\n \\\"m_ShaderOutputName\\\": \\\"Input1\\\",\\n \\\"m_ShowValue\\\":
1,\\n \\\"m_ShaderOutputName\\\": \\\"Input1\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\":
\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":
\"Assembly-CSharp\"\n },\n \"JSONnodeData\": \"{\\n

0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_CurrentValue\\\":
{\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
4,\\n \\\"m_ShaderOutputName\\\": \\\"Input2\\\",\\n \\\"m_ShowValue\\\":
1,\\n \\\"m_ShaderOutputName\\\": \\\"Input2\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\":
\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":
\"Assembly-CSharp\"\n },\n \"JSONnodeData\": \"{\\n

0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_CurrentValue\\\":
{\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
4,\\n \\\"m_ShaderOutputName\\\": \\\"Output\\\",\\n \\\"m_ShowValue\\\":
1,\\n \\\"m_ShaderOutputName\\\": \\\"Output\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n }\n ]\n}"
- typeInfo:
fullName: UnityEngine.MaterialGraph.MultiplyNode

0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_CurrentValue\\\":
{\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
4,\\n \\\"m_ShaderOutputName\\\": \\\"Input1\\\",\\n \\\"m_ShowValue\\\":
3,\\n \\\"m_ShaderOutputName\\\": \\\"Input1\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\":
\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":
\"Assembly-CSharp\"\n },\n \"JSONnodeData\": \"{\\n

0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_CurrentValue\\\":
{\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
4,\\n \\\"m_ShaderOutputName\\\": \\\"Input2\\\",\\n \\\"m_ShowValue\\\":
3,\\n \\\"m_ShaderOutputName\\\": \\\"Input2\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n },\n {\n \"typeInfo\": {\n \"fullName\":
\"UnityEngine.MaterialGraph.MaterialSlot\",\n \"assemblyName\":
\"Assembly-CSharp\"\n },\n \"JSONnodeData\": \"{\\n

0.0,\\n \\\"z\\\": 0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_CurrentValue\\\":
{\\n \\\"x\\\": 0.0,\\n \\\"y\\\": 0.0,\\n \\\"z\\\":
0.0,\\n \\\"w\\\": 0.0\\n },\\n \\\"m_ConcreteValueType\\\":
4,\\n \\\"m_ShaderOutputName\\\": \\\"Output\\\",\\n \\\"m_ShowValue\\\":
3,\\n \\\"m_ShaderOutputName\\\": \\\"Output\\\",\\n \\\"m_ShowValue\\\":
true\\n}\"\n }\n ]\n}"
m_SerializableEdges:
- typeInfo:

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs


if (uvSlot == null)
return;
var uvName = string.Format("{0}.xy", ShaderGeneratorNames.UV[0]);
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName());
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)

public override PropertyType propertyType { get { return PropertyType.Texture2D; } }
public bool RequiresMeshUV(int index)
public bool RequiresMeshUV(UVChannel channel)
if (index != 0)
if (channel != UVChannel.uv0)
{
return false;
}

28
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs


{
interface IMayRequireMeshUV
{
bool RequiresMeshUV(int index);
bool RequiresMeshUV(UVChannel channel);
}
[Title("Input/UV Node")]

private const string kOutputSlotName = "UV";
public override bool hasPreview { get { return true; } }
[SerializeField]
private UVChannel m_OutputChannel;
public UVChannel uvChannel
{
get { return m_OutputChannel; }
set
{
if (m_OutputChannel == value)
return;
m_OutputChannel = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public override bool hasPreview { get { return true; } }
public UVNode()
{
name = "UV";

public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + ShaderGeneratorNames.UV[0] + ";", true);
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + m_OutputChannel.GetUVName() + ";", true);
public bool RequiresMeshUV(int index)
public bool RequiresMeshUV(UVChannel channel)
return index == 0;
return channel == uvChannel;
}
}
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs


foreach (var slot in GetInputSlots<MaterialSlot>())
{
var varName = subGraphInputNode.GetVariableNameForSlot(slot.id);
var varValue = GetSlotValue(slot.id, GenerationMode.ForReals);
var varValue = GetSlotValue(slot.id, generationMode);
var outDimension = ConvertConcreteSlotValueTypeToString(slot.concreteValueType);
outputString.AddShaderChunk(

return subGraph.activeNodes.OfType<IMayRequireNormal>().Any(x => x.RequiresNormal());
}
public bool RequiresMeshUV(int index)
public bool RequiresMeshUV(UVChannel channel)
return subGraph.activeNodes.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(index));
return subGraph.activeNodes.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(channel));
}
public bool RequiresScreenPosition()

7
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SurfaceModel/AbstractSurfaceMasterNode.cs


// always add color because why not.
shaderInputVisitor.AddShaderChunk("float4 color : COLOR;", true);
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UV.Length; ++uvIndex)
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UVCount; ++uvIndex)
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(uvIndex)))
var channel = (UVChannel)uvIndex;
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(channel)))
shaderBody.AddShaderChunk(string.Format("half4 {0} = IN.meshUV{1};", ShaderGeneratorNames.UV[uvIndex], uvIndex), true);
shaderBody.AddShaderChunk(string.Format("half4 {0} = IN.meshUV{1};", channel.GetUVName(), uvIndex), true);
}
}

25
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs


{
public static class ShaderGeneratorNames
{
private static string[] UV = {"uv0", "uv1", "uv2", "uv3"};
public static int UVCount = 4;
public const string WorldSpaceNormal = "worldSpaceNormal";
public const string WorldSpaceBitangent = "worldSpaceBitangent";
public const string WorldSpaceTangent = "worldSpaceTangent";

public const string VertexColor = "vertexColor";
public static string[] UV = { "uv0", "uv1", "uv2", "uv3" };
public static string GetUVName(this UVChannel channel)
{
return UV[(int) channel];
}
}
public enum UVChannel
{
uv0 = 0,
uv1 = 1,
uv2 = 2,
uv3 = 3,
}
public class ShaderGenerator

shaderBodyVisitor.AddShaderChunk("float3 " + ShaderGeneratorNames.WorldSpaceNormal + " = normalize(IN.worldNormal);", true);
}
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UV.Length; ++uvIndex)
for (int uvIndex = 0; uvIndex < ShaderGeneratorNames.UVCount; ++uvIndex)
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(uvIndex)))
var channel = (UVChannel) uvIndex;
if (activeNodeList.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(channel)))
shaderBodyVisitor.AddShaderChunk(string.Format("half4 {0} = IN.meshUV{1};", ShaderGeneratorNames.UV[uvIndex], uvIndex), true);
shaderBodyVisitor.AddShaderChunk(string.Format("half4 {0} = IN.meshUV{1};", channel.GetUVName(), uvIndex), true);
}
}

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/UVNodeDrawData.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class UVNodeContolDrawData : ControlDrawData
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var cNode = node as UVNode;
if (cNode == null)
return;
cNode.uvChannel = (UVChannel) EditorGUILayout.EnumPopup("Channel", cNode.uvChannel);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class UVNodeDrawData : MaterialNodeDrawData
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<UVNodeContolDrawData>();
instance.Initialize(node);
return new List<GraphElementPresenter> { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/DrawData/UVNodeDrawData.cs.meta


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