浏览代码

Fix split node and add test for it (#62)

/main
Peter Bay Bastian 7 年前
当前提交
8dc11b9a
共有 5 个文件被更改,包括 140 次插入74 次删除
  1. 95
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs
  2. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Split.ShaderGraph
  3. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Split.ShaderGraph.meta
  4. 39
      ShaderTemplates/Split.ShaderGraph.png
  5. 68
      ShaderTemplates/Split.ShaderGraph.shader

95
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Channel/SplitNode.cs


[Title("Channel/Split")]
public class SplitNode : AbstractMaterialNode, IGeneratesBodyCode
{
protected const string kInputSlotName = "Input";
protected const string kOutputSlotRName = "R";
protected const string kOutputSlotGName = "G";
protected const string kOutputSlotBName = "B";
protected const string kOutputSlotAName = "A";
protected const string kOutputSlotRGBName = "RGB";
protected const string kOutputSlotRGName = "RG";
const string kInputSlotName = "Input";
const string kOutputSlotRName = "R";
const string kOutputSlotGName = "G";
const string kOutputSlotBName = "B";
const string kOutputSlotAName = "A";
public const int InputSlotId = 0;
public const int OutputSlotRId = 1;

public const int OutputSlotRGBId = 5;
public const int OutputSlotRGId = 6;
public SplitNode()
{

AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRGBId, kOutputSlotRGBName, kOutputSlotRGBName, SlotType.Output, SlotValueType.Vector3, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotRGId, kOutputSlotRGName, kOutputSlotRGName, SlotType.Output, SlotValueType.Vector2, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
RemoveSlotsNameNotMatching(s_ValidSlots);
protected int[] validSlots
{
get { return new[] { InputSlotId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, OutputSlotRGBId, OutputSlotRGId }; }
}
static int[] s_ValidSlots = { InputSlotId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId };
static int[] s_OutputSlots = {OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId};
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotRGBId, OutputSlotRGId });
string inputValue = GetSlotValue(InputSlotId, generationMode);
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + GetNodeBody(inputValue) + ";", true);
}
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlotRId, OutputSlotGId, OutputSlotBId });
var inputValue = GetSlotValue(InputSlotId, generationMode);
protected string GetNodeBody(string inputValue)
{
string[] channelNames = { "r", "g", "b", "a" };
if (inputSlot == null)
return "1.0";
int numInputChannels = (int)SlotValueHelper.GetChannelCount(inputSlot.concreteValueType);
if (numInputChannels > 4)
numInputChannels = 0;
var numInputChannels = 0;
if (inputSlot != null)
{
numInputChannels = (int)SlotValueHelper.GetChannelCount(inputSlot.concreteValueType);
if (numInputChannels > 4)
numInputChannels = 0;
if (owner.GetEdges(inputSlot.slotReference).ToList().Count() == 0)
numInputChannels = 0;
string outputString = precision + "4(";
if (numInputChannels == 0)
{
outputString += "1.0, 1.0, 1.0, 1.0)";
if (!owner.GetEdges(inputSlot.slotReference).Any())
numInputChannels = 0;
else
{
//float4(arg1, 1.0, 1.0)
outputString += inputValue;
for (int i = numInputChannels; i < 4; i++)
{
outputString += ", 1.0";
}
outputString += ")";
}
return outputString;
}
public override string GetVariableNameForSlot(int slotId)
{
string slotOutput;
switch (slotId)
for (var i = 0; i < 4; i++)
case OutputSlotRId:
slotOutput = ".r";
break;
case OutputSlotGId:
slotOutput = ".g";
break;
case OutputSlotBId:
slotOutput = ".b";
break;
case OutputSlotAId:
slotOutput = ".a";
break;
case OutputSlotRGBId:
slotOutput = ".rgb";
break;
case OutputSlotRGId:
slotOutput = ".rg";
break;
default:
slotOutput = "";
break;
var outputValue = i >= numInputChannels ? "1.0" : string.Format("{0}[{1}]", inputValue, i);
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", precision, GetVariableNameForSlot(s_OutputSlots[i]), outputValue), true);
return GetVariableNameForNode() + slotOutput;
}
}
}

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:

39
ShaderTemplates/Split.ShaderGraph.png

之前 之后
宽度: 256  |  高度: 256  |  大小: 20 KiB

68
ShaderTemplates/Split.ShaderGraph.shader


Shader "Split"
{
Properties
{
}
SubShader
{
Tags
{
"RenderType"="Opaque"
"Queue"="Geometry"
}
Blend One Zero
Cull Back
ZTest LEqual
ZWrite On
LOD 200
CGPROGRAM
#pragma target 3.0
#pragma surface surf Standard vertex:vert
#pragma glsl
#pragma debug
struct Input
{
float4 color : COLOR;
};
void vert (inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
float3 Vector3_Vector3_3E03E6E5_Uniform = float3 (0.25, 0.5, 0.75);
float Split_CDE20F4C_R = Vector3_Vector3_3E03E6E5_Uniform[0];
float Split_CDE20F4C_G = Vector3_Vector3_3E03E6E5_Uniform[1];
float Split_CDE20F4C_B = Vector3_Vector3_3E03E6E5_Uniform[2];
float Split_CDE20F4C_A = 1.0;
o.Albedo = Split_CDE20F4C_A;
o.Emission = Split_CDE20F4C_R;
o.Metallic = Split_CDE20F4C_B;
o.Smoothness = Split_CDE20F4C_G;
}
ENDCG
}
FallBack "Diffuse"
CustomEditor "LegacyIlluminShaderGUI"
}
正在加载...
取消
保存