浏览代码

-When we validate a subgraph node we also need to validate the subgraph (generates the concrete values).

-Allow promotion of vector types. v2->v3/v4 v3->v4. Rule is alpha channel gets 1, other channels get 0.
/main
Tim Cooper 7 年前
当前提交
2888f1c2
共有 4 个文件被更改,包括 38 次插入29 次删除
  1. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
  2. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/SubGraphNode.cs
  3. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs
  4. 27
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs


return inputType == SlotValueType.Cubemap;
case SlotValueType.Dynamic:
case SlotValueType.Vector4:
return inputType == SlotValueType.Vector4
|| inputType == SlotValueType.Vector3
|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
return inputType == SlotValueType.Vector3
|| inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
return inputType == SlotValueType.Vector2
|| inputType == SlotValueType.Vector1
|| inputType == SlotValueType.Dynamic;
case SlotValueType.Vector1:
return inputType == SlotValueType.Vector4
|| inputType == SlotValueType.Vector3

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/SubGraphNode.cs


RemoveSlotsNameNotMatching(validNames);
}
public override void ValidateNode()
{
if (referencedGraph != null)
{
referencedGraph.OnEnable();
referencedGraph.ValidateGraph();
if (referencedGraph.GetNodes<INode>().Any(x => x.hasError))
hasError = true;
}
base.ValidateNode();
}
public override void CollectShaderProperties(PropertyCollector visitor, GenerationMode generationMode)
{
base.CollectShaderProperties(visitor, generationMode);

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs


switch (convertFromType)
{
case ConcreteSlotValueType.Vector1:
return string.Format("({0}{1})", rawOutput, ".xx");
return string.Format("({0}.xx)", rawOutput);
case ConcreteSlotValueType.Vector3:
case ConcreteSlotValueType.Vector4:
return string.Format("({0}.xy)", rawOutput);

switch (convertFromType)
{
case ConcreteSlotValueType.Vector1:
return string.Format("({0}{1})", rawOutput, ".xxx");
return string.Format("({0}.xxx)", rawOutput);
case ConcreteSlotValueType.Vector2:
return string.Format("({0}3({1}.x, {1}.y, 0.0))", node.precision, rawOutput);
case ConcreteSlotValueType.Vector4:
return string.Format("({0}.xyz)", rawOutput);
default:

switch (convertFromType)
{
case ConcreteSlotValueType.Vector1:
return string.Format("({0}{1})", rawOutput, ".xxxx");
return string.Format("({0}.xxxx)", rawOutput);
case ConcreteSlotValueType.Vector2:
return string.Format("({0}4({1}.x, {1}.y, 0.0, 1.0))", node.precision, rawOutput);
case ConcreteSlotValueType.Vector3:
return string.Format("({0}4({1}.x, {1}.y, {1}.z, 1.0))", node.precision, rawOutput);
default:
return kErrorString;
}

var convertFromType = slot.concreteValueType;
// preview is always dimension 4, and we always ignore alpha
// preview is always dimension 4
switch (convertFromType)
{
case ConcreteSlotValueType.Vector1:

27
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs


m_DirtyPreviews.UnionWith(m_TimeDependentPreviews);
PropagateNodeSet(m_DirtyPreviews);
m_NodesWith3DPreview.Clear();
foreach (var index in m_DirtyPreviews)
{
var node = (AbstractMaterialNode)m_Graph.GetNodeFromTempId(m_Identifiers[index]);
if (node.previewMode == PreviewMode.Preview3D)
m_NodesWith3DPreview.Add(node.tempId.index);
}
PropagateNodeSet(m_NodesWith3DPreview);
foreach (var index in m_DirtyPreviews)
{
var renderData = m_RenderDatas[index];
renderData.previewMode = m_NodesWith3DPreview.Contains(renderData.shaderData.node.tempId.index) ? PreviewMode.Preview3D : PreviewMode.Preview2D;
}
// Find nodes we need properties from
m_PropertyNodes.Clear();
m_PropertyNodes.UnionWith(m_DirtyPreviews);

if (m_DirtyShaders.Any())
{
PropagateNodeSet(m_DirtyShaders);
m_NodesWith3DPreview.Clear();
foreach (var index in m_DirtyShaders)
{
var node = (AbstractMaterialNode)m_Graph.GetNodeFromTempId(m_Identifiers[index]);
if (node.previewMode == PreviewMode.Preview3D)
m_NodesWith3DPreview.Add(node.tempId.index);
}
PropagateNodeSet(m_NodesWith3DPreview);
foreach (var index in m_DirtyShaders)
{
var renderData = m_RenderDatas[index];
renderData.previewMode = m_NodesWith3DPreview.Contains(renderData.shaderData.node.tempId.index) ? PreviewMode.Preview3D : PreviewMode.Preview2D;
}
var masterNodes = new List<MasterNode>();
var uberNodes = new List<INode>();

正在加载...
取消
保存