浏览代码

[Shader Graph] Previews rendering.

/main
Tim Cooper 9 年前
当前提交
5a34322a
共有 17 个文件被更改,包括 60 次插入39 次删除
  1. 32
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs
  2. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs
  3. 20
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/SimpleWidgets.cs
  4. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/AddNode.cs
  5. 3
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  6. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BlendNode.cs
  7. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs
  8. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorizeNode.cs
  9. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/CombineNode.cs
  10. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/KaleidoscopeNode.cs
  11. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/MandelbrotNode.cs
  12. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PerlinNode.cs
  13. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
  14. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SplatNode.cs
  15. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SwizzleNode.cs
  16. 2
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs
  17. 4
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs

32
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/DrawableMaterialNode.cs


private Type m_OutputType;
public BaseMaterialNode m_Node;
public DrawableMaterialNode(BaseMaterialNode node, float size, Type outputType, MaterialGraphDataSource data)
: base(node.position.min, size)
private Rect previewArea;
public DrawableMaterialNode(BaseMaterialNode node, float width, Type outputType, MaterialGraphDataSource data)
: base(node.position.min, width)
AddManipulator(new IMGUIContainer());
m_Node = node;
m_Title = node.name;
m_OutputType = outputType;

}
// output port
pos.x = size - 20.0f;
pos.x = width;
pos.y += 22;
pos.y += 22;
scale = new Vector3(scale.x, pos.y + 12.0f, 0.0f);
if (node.hasPreview)
{
previewArea = new Rect(10, pos.y, width - 20, width - 20);
pos.y += width;
}
scale = new Vector3(pos.x, pos.y, 0.0f);
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
base.Render(parentRect, canvas);
if (m_Node.hasPreview)
{
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(previewArea, m_Node.RenderPreview(new Rect(0, 0, previewArea.width, previewArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
}
}
}

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs


{
// add the nodes
var bmn = node as BaseMaterialNode;
drawableNodes.Add(new DrawableMaterialNode(bmn, 200.0f, typeof(Vector4), this));
drawableNodes.Add(new DrawableMaterialNode(bmn, (bmn is PixelShaderNode) ? 600.0f : 200.0f, typeof(Vector4), this));
}
// Add the edges now

20
UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/SimpleWidgets.cs


public class SimpleBox : CanvasElement
{
protected string m_Title = "simpleBox";
public SimpleBox(Vector2 position, float size)
public SimpleBox(Vector2 position, float width)
scale = new Vector2(size, size);
scale = new Vector2(width, width);
}
public override void Render(Rect parentRect, Canvas2D canvas)

public class MoveableBox : SimpleBox
{
public MoveableBox(Vector2 position, float size)
: base(position,size)
public MoveableBox(Vector2 position, float width)
: base(position,width)
{
m_Title = "Drag me!";
AddManipulator(new Draggable());

class ResizableBox : SimpleBox
{
public ResizableBox(Vector2 position, float size)
: base(position, size)
public ResizableBox(Vector2 position, float width)
: base(position, width)
{
m_Title = "Resize me!";
AddManipulator(new Resizable());

WWW www = null;
private float timeToNextPicture = 0.0f;
public WWWImageBox(Vector2 position, float size)
: base(position, size)
public WWWImageBox(Vector2 position, float width)
: base(position, width)
{
m_Title = "I cause repaints every frame!";
AddManipulator(new Draggable());

private bool m_Toggle = true;
private Texture2D m_aTexture = null;
public IMGUIControls(Vector2 position, float size)
: base(position, size)
public IMGUIControls(Vector2 position, float width)
: base(position, width)
{
m_Caps = Capabilities.Unselectable;

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/AddNode.cs


return Vector4.zero;
}
public override void NodeUI(Graphs.GraphGUI host)
public override void NodeUI()
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_DefaultValue = EditorGUILayout.FloatField("", m_DefaultValue, GUILayout.Width(64));

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


}
}
public override void NodeUI(GraphGUI host)
public virtual void NodeUI()
base.NodeUI(host);
if (hasPreview)
OnPreviewGUI();
}

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BlendNode.cs


visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public override void NodeUI(Graphs.GraphGUI host)
public override void NodeUI()
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_Blend = GUILayout.HorizontalSlider(m_Blend, 0f, 1f, GUILayout.Width(64));

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs


visitor.AddShaderChunk(precision + "4 " + GetPropertyName() + " = " + precision + "4 (" + m_Color.r + ", " + m_Color.g + ", " + m_Color.b + ", " + m_Color.a + ");", true);
}
public override void NodeUI(Graphs.GraphGUI host)
public override void NodeUI()
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_Color = EditorGUILayout.ColorField(m_Color);

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorizeNode.cs


return value;
}
public override void NodeUI(Graphs.GraphGUI host)
public override void NodeUI()
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_Color = EditorGUILayout.ColorField("Tint", m_Color);

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/CombineNode.cs


visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
public override void NodeUI(Graphs.GraphGUI host)
public override void NodeUI()
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_Operation = (Operation)EditorGUILayout.EnumPopup(m_Operation);

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/KaleidoscopeNode.cs


return value;
}
public override void NodeUI(Graphs.GraphGUI host)
public override void NodeUI()
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 50);

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/MandelbrotNode.cs


return value;
}
public override void NodeUI(Graphs.GraphGUI host)
public override void NodeUI()
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 50);

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PerlinNode.cs


public override void NodeUI(GraphGUI host)
{
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 8);

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs


public override void NodeUI(GraphGUI host)
{
base.NodeUI(host);
base.NodeUI();
var lightFunctions = GetLightFunctions();
var lightFunction = GetLightFunction();

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SplatNode.cs


public override void NodeUI(GraphGUI host)
{
base.NodeUI(host);
base.NodeUI();
string[] values = {"x", "y", "z", "w"};
EditorGUI.BeginChangeCheck();
m_SwizzleChannel = EditorGUILayout.Popup("Channel", m_SwizzleChannel, values);

2
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/SwizzleNode.cs


public override void NodeUI(GraphGUI host)
{
base.NodeUI(host);
base.NodeUI();
string[] channelNames = { "X", "Y", "Z", "W" };
string[] values = { "0", "1", "Input1.x", "Input1.y", "Input1.z", "Input1.w", "Input2.x", "Input2.y", "Input2.z", "Input2.w" };
EditorGUI.BeginChangeCheck();

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


{
LoadTextureTypes();
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_DefaultTexture = EditorGUILayout.ObjectField(GUIContent.none, m_DefaultTexture, typeof(Texture2D), false) as Texture2D;

4
UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs


visitor.AddShaderChunk(precision + "4 " + GetPropertyName() + " = " + precision + "4 (" + m_Value.x + ", " + m_Value.y + ", " + m_Value.z + ", " + m_Value.w + ");", true);
}
public override void NodeUI(Graphs.GraphGUI host)
public override void NodeUI()
base.NodeUI(host);
base.NodeUI();
EditorGUI.BeginChangeCheck();
m_Value = EditorGUILayout.Vector4Field("Value", m_Value, GUILayout.Width(170));

正在加载...
取消
保存