浏览代码

[shader graph]

*All inputs should go through the adaptor. This stops weird implicit swizzles.
*Adaptor now uses swizzles instead of new vector.
/main
Tim Cooper 9 年前
当前提交
c1c5d22d
共有 4 个文件被更改,包括 28 次插入52 次删除
  1. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  2. 15
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function1Input.cs
  3. 9
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs
  4. 47
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs

9
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs


}
}
public struct OutputSlotVariable
{
public string name;
public ConcreteSlotValueType slotType;
}
public virtual string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode)
{
if (s.isInputSlot) Debug.LogError("Attempting to use input slot (" + s + ") for output!");

string inputValue;
if (pointInputConnected)
{
var dataProvider = inputSlot.edges[0].fromSlot.node as BaseMaterialNode;
inputValue = dataProvider.GetOutputVariableNameForSlot(inputSlot.edges[0].fromSlot, generationMode);
inputValue = ShaderGenerator.AdaptNodeOutput(inputSlot.edges[0].fromSlot, generationMode, concreteInputSlotValueTypes[inputSlot.name]);
}
else
{

15
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Function1Input.cs


return;
}
bool inputConnected = inputSlot.edges.Count > 0;
string inputValue;
if (inputConnected)
{
var inputDateProvider = inputSlot.edges[0].fromSlot.node as BaseMaterialNode;
inputValue = inputDateProvider.GetOutputVariableNameForSlot(inputSlot.edges[0].fromSlot, generationMode);
}
else
{
var defaultValue = GetSlotDefaultValue(inputSlot.name);
inputValue = defaultValue.GetDefaultValue(generationMode, concreteInputSlotValueTypes[inputSlot.name]);
}
var inputValue = GetSlotValue(inputSlot, generationMode);
visitor.AddShaderChunk(precision + outputDimension + " " + GetOutputVariableNameForSlot(outputSlot, generationMode) + " = " + GetFunctionCallBody(inputValue) + ";", true);
}

9
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs


var uvName = "IN.meshUV0.xy";
if (uvSlot.edges.Count > 0)
{
var fromNode = uvSlot.edges[0].fromSlot.node as BaseMaterialNode;
uvName = fromNode.GetOutputVariableNameForSlot(uvSlot.edges[0].fromSlot, generationMode);
uvName = ShaderGenerator.AdaptNodeOutput(uvSlot.edges[0].fromSlot, generationMode, ConcreteSlotValueType.Vector2);
if ()
}
string body = "tex2D (" + propertyName + ", " + uvName + ".xy)";
string body = "tex2D (" + propertyName + ", " + uvName + ")";
if (m_TextureType == TextureType.Bump)
body = precision + "4(UnpackNormal(" + body + "), 0)";
visitor.AddShaderChunk("float4 " + GetOutputVariableNameForNode() + " = " + body + ";", true);

47
UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs


return result;
}
private static string AdaptNodeOutput(BaseMaterialNode node, GenerationMode mode, ConcreteSlotValueType previewChannelConcreteType)
public static string AdaptNodeOutput(BaseMaterialNode node, GenerationMode mode, ConcreteSlotValueType convertToType)
if (outputSlot == null)
return AdaptNodeOutput(outputSlot, mode, convertToType);
}
private const string kErrorString = @"ERROR!";
public static string AdaptNodeOutput(Slot outputSlot, GenerationMode mode, ConcreteSlotValueType convertToType)
{
if (outputSlot == null)
var outputConcreteType = node.GetConcreteOutputSlotValueType(outputSlot);
var node = outputSlot.node as BaseMaterialNode;
var convertFromType = node.GetConcreteOutputSlotValueType(outputSlot);
if (outputConcreteType == previewChannelConcreteType)
if (convertFromType == convertToType)
switch (previewChannelConcreteType)
switch (convertToType)
switch (outputConcreteType)
switch (convertFromType)
return string.Format("half2(({0}).x, ({0}).x)", rawOutput);
return string.Format("({0})", rawOutput);
return string.Format("half2(({0}).x, ({0}).y)", rawOutput);
return string.Format("({0}.xy)", rawOutput);
return string.Empty;
return kErrorString;
switch (outputConcreteType)
switch (convertFromType)
return string.Format("half3(({0}).x, ({0}).x, ({0}).x)", rawOutput);
case ConcreteSlotValueType.Vector2:
return string.Format("half3(({0}).x, ({0}).y, 0.0f)", rawOutput);
return string.Format("({0})", rawOutput);
return string.Format("half3(({0}).x, ({0}).y, ({0}).z)", rawOutput);
return string.Format("({0}.xyz)", rawOutput);
return string.Empty;
return kErrorString;
switch (outputConcreteType)
switch (convertFromType)
return string.Format("half4(({0}).x, ({0}).x, ({0}).x, ({0}).x)", rawOutput);
case ConcreteSlotValueType.Vector2:
return string.Format("half4(({0}).x, ({0}).y, 0.0f, 0.0f)", rawOutput);
case ConcreteSlotValueType.Vector3:
return string.Format("half4(({0}).x, ({0}).y, ({0}).z, 0.0f)", rawOutput);
return string.Format("({0})", rawOutput);
return string.Empty;
return kErrorString;
return string.Empty;
return kErrorString;
}
}

正在加载...
取消
保存