浏览代码

Fix combine node and update split test to also use combine node

/main
Peter Bay Bastian 7 年前
当前提交
ce4b9371
共有 5 个文件被更改,包括 120 次插入92 次删除
  1. 96
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/CombineNode.cs
  2. 91
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/SplitCombine.ShaderGraph
  3. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/SplitCombine.ShaderGraph.meta
  4. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Split.ShaderGraph
  5. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Split.ShaderGraph.meta

96
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/CombineNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public class CombineNode : AbstractMaterialNode, IGeneratesBodyCode
public class CombineNode : CodeFunctionNode
protected const string kInputSlot0Name = "Input1";
protected const string kInputSlot1Name = "Input2";
protected const string kInputSlot2Name = "Input3";
protected const string kInputSlot3Name = "Input4";
protected const string kOutputSlotName = "Output";
public const int InputSlot0Id = 0;
public const int InputSlot1Id = 1;
public const int InputSlot2Id = 2;
public const int InputSlot3Id = 3;
public const int OutputSlotId = 4;
UpdateNodeAfterDeserialization();
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new MaterialSlot(InputSlot0Id, kInputSlot0Name, kInputSlot0Name, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot1Id, kInputSlot1Name, kInputSlot1Name, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot2Id, kInputSlot2Name, kInputSlot2Name, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(InputSlot3Id, kInputSlot3Name, kInputSlot3Name, SlotType.Input, SlotValueType.Dynamic, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { InputSlot0Id, InputSlot1Id, InputSlot2Id, InputSlot3Id, OutputSlotId}; }
}
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlot0Id, InputSlot1Id, InputSlot2Id, InputSlot3Id }, new[] { OutputSlotId });
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(OutputSlotId) + " = " + GetNodeBody(generationMode) + ";", true);
}
private int GetChannelCountForInput(int inputSlotId)
{
var inputSlot = FindInputSlot<MaterialSlot>(inputSlotId);
if (inputSlot == null)
return 0;
int numInputChannels = (int)inputSlot.concreteValueType;
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0)
numInputChannels = 0;
return numInputChannels;
}
private void AddChannelsFromInputSlot(GenerationMode generationMode, int inputSlot, ref string outputString, ref int freeChannel)
protected override MethodInfo GetFunctionToConvert()
string[] channelNames = { "r", "g", "b", "a" };
int numChannel = GetChannelCountForInput(inputSlot);
numChannel = Math.Min(freeChannel, numChannel);
if (numChannel <= 0)
return;
string channelInputName = GetSlotValue(inputSlot, generationMode);
outputString += channelInputName;
freeChannel -= numChannel;
if (freeChannel != 0)
outputString += ",";
return GetType().GetMethod("Unity_Combine", BindingFlags.Static | BindingFlags.NonPublic);
protected string GetNodeBody(GenerationMode generationMode)
static string Unity_Combine(
[Slot(0, Binding.None)] Vector1 first,
[Slot(1, Binding.None)] Vector1 second,
[Slot(2, Binding.None)] Vector1 third,
[Slot(3, Binding.None)] Vector1 fourth,
[Slot(4, Binding.None)] out Vector4 result)
string outputString = precision + "4(";
int freeChannels = 4;
AddChannelsFromInputSlot(generationMode, InputSlot0Id, ref outputString, ref freeChannels);
AddChannelsFromInputSlot(generationMode, InputSlot1Id, ref outputString, ref freeChannels);
AddChannelsFromInputSlot(generationMode, InputSlot2Id, ref outputString, ref freeChannels);
AddChannelsFromInputSlot(generationMode, InputSlot3Id, ref outputString, ref freeChannels);
for (int i = freeChannels; i > 0; --i)
{
outputString += "0.0";
if (i > 1)
outputString += ", ";
}
outputString += ")";
return outputString;
result = Vector4.zero;
return @"
{
result = float4(first, second, third, fourth);
}
";
}
}
}

91
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/SplitCombine.ShaderGraph
文件差异内容过多而无法显示
查看文件

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/SplitCombine.ShaderGraph.meta


fileFormatVersion: 2
guid: 3782c62dd61732042aed83e579a22e5f
timeCreated: 1504702334
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures:
- Texture2D_Texture2D_FCC444C7_Uniform: {fileID: 2800000, guid: 9c50a18d04437449b86568cfcbb668a7,
type: 3}
userData:
assetBundleName:
assetBundleVariant:

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Split.ShaderGraph
文件差异内容过多而无法显示
查看文件

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Split.ShaderGraph.meta


fileFormatVersion: 2
guid: 5636d831c461a5e47984f2a939e1b1b9
timeCreated: 1504697124
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存