浏览代码

Merge pull request #304 from Unity-Technologies/sub-graph-preview-fix

Sub graph preview fix
/main
GitHub 7 年前
当前提交
312d23e1
共有 5 个文件被更改,包括 38 次插入1 次删除
  1. 1
      com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs
  2. 10
      com.unity.shadergraph/Editor/Data/SubGraph/SubGraphOutputNode.cs
  3. 15
      com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs
  4. 8
      com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs
  5. 5
      com.unity.shadergraph/Editor/Drawing/PreviewManager.cs

1
com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs


public Vector4MaterialSlot()
{
m_Labels = new[] { "X", "Y", "Z", "W" };
}
public Vector4MaterialSlot(

10
com.unity.shadergraph/Editor/Data/SubGraph/SubGraphOutputNode.cs


name = "SubGraphOutputs";
}
public override bool hasPreview
{
get { return true; }
}
public override PreviewMode previewMode
{
get { return PreviewMode.Preview3D; }
}
public virtual int AddSlot()
{
var index = this.GetInputSlots<ISlot>().Count() + 1;

15
com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs


var slots = new List<MaterialSlot>();
foreach (var activeNode in isUber ? activeNodeList.Where(n => ((AbstractMaterialNode)n).hasPreview) : ((INode)node).ToEnumerable())
{
if (activeNode is IMasterNode)
if (activeNode is IMasterNode || activeNode is SubGraphOutputNode)
slots.AddRange(activeNode.GetInputSlots<MaterialSlot>());
else
slots.AddRange(activeNode.GetOutputSlots<MaterialSlot>());

var outputSlot = activeNode.GetOutputSlots<MaterialSlot>().FirstOrDefault();
if (outputSlot != null)
surfaceDescriptionFunction.AddShaderChunk(String.Format("if ({0} == {1}) {{ surface.PreviewOutput = {2}; return surface; }}", outputIdProperty.referenceName, activeNode.tempId.index, ShaderGenerator.AdaptNodeOutputForPreview(activeNode, outputSlot.id, activeNode.GetVariableNameForSlot(outputSlot.id))), false);
}
// In case of the subgraph output node, the preview is generated
// from the first input to the node.
if (activeNode is SubGraphOutputNode)
{
var inputSlot = activeNode.GetInputSlots<MaterialSlot>().FirstOrDefault();
if (inputSlot != null)
{
var foundEdges = graph.GetEdges(inputSlot.slotReference).ToArray();
string slotValue = foundEdges.Any() ? activeNode.GetSlotValue(inputSlot.id, mode) : inputSlot.GetDefaultValue(mode);
surfaceDescriptionFunction.AddShaderChunk(String.Format("if ({0} == {1}) {{ surface.PreviewOutput = {2}; return surface; }}", outputIdProperty.referenceName, activeNode.tempId.index, slotValue), false);
}
}
activeNode.CollectShaderProperties(shaderProperties, mode);

8
com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs


var amn = masterNode as AbstractMaterialNode;
if (amn != null)
amn.Dirty(scope);
// If currently editing a subgraph, dirty the output node rather than master node.
if (m_Graph is SubGraph)
{
var subgraph = m_Graph as SubGraph;
if (subgraph != null && subgraph.outputNode != null)
subgraph.outputNode.Dirty(scope);
}
}
void OnPreviewChanged()

5
com.unity.shadergraph/Editor/Drawing/PreviewManager.cs


if (masterRenderData.shaderData == null && masterNode != null)
masterRenderData.shaderData = shaderData;
var subGraphOutputNode = node as SubGraphOutputNode;
if (masterRenderData.shaderData == null && subGraphOutputNode != null)
masterRenderData.shaderData = shaderData;
}
void OnNodeModified(INode node, ModificationScope scope)

正在加载...
取消
保存