浏览代码

[shader graph]

*properly initialize new graphs
*Reenable combine node.
/main
Tim Cooper 9 年前
当前提交
d1eb6888
共有 6 个文件被更改,包括 107 次插入30 次删除
  1. 6
      UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs
  2. 41
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Drawing/MaterialGraphDataSource.cs
  3. 7
      UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraph.cs
  4. 25
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
  5. 21
      UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/CombineNode.cs
  6. 37
      UnityProject/Assets/UnityShaderEditor/Editor/Source/PixelGraph.cs

6
UnityProject/Assets/UnityShaderEditor/Editor/Source/BaseMaterialGraph.cs


RevalidateGraph();
}
public void AddNodeNoValidate(Node node)
{
base.AddNode(node);
AssetDatabase.AddObjectToAsset(node, this);
}
protected void AddMasterNodeNoAddToAsset(Node node)
{
base.AddNode(node);

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


using System.Linq;
using UnityEditor.Experimental;
using UnityEditor.Experimental.Graph;
using UnityEditor.Graphs;
using UnityEngine;
namespace UnityEditor.MaterialGraph

toReturn.AddRange(drawableEdges.Select(x => (CanvasElement)x));
toReturn.AddRange(nullInputSlots.Select(x => (CanvasElement)x));
Debug.LogFormat("REturning {0} nodes", toReturn.Count);
//toReturn.Add(new FloatingPreview(new Rect(Screen.width - 300, Screen.height - 300, 300, 300), pixelGraph.nodes.FirstOrDefault(x => x is PixelShaderNode)));
Debug.LogFormat("Returning {0} nodes", toReturn.Count);
// do nothing here, we want to use the 'correct'
// delete elements.
// do nothing here, we want to use delete elements.
// delete elements ensures that edges are deleted before nodes.
}
public void DeleteElements(List<CanvasElement> elements)

graph.ExportShader(path);
else
EditorUtility.DisplayDialog("Export Shader Error", "Cannot export shader", "Ok");
}
}
public class FloatingPreview : CanvasElement
{
private BaseMaterialNode m_Node;
public FloatingPreview(Rect position, Node node)
{
m_Node = node as BaseMaterialNode;
m_Translation = new Vector2(position.x, position.y);
m_Scale = new Vector3(position.width, position.height, 1);
m_Caps |= Capabilities.Floating | Capabilities.Unselectable;
}
public override void Render(Rect parentRect, Canvas2D canvas)
{
var drawArea = new Rect(0, 0, scale.x, scale.y);
Color backgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.7f);
EditorGUI.DrawRect(drawArea, backgroundColor);
drawArea.width -= 10;
drawArea.height -= 10;
drawArea.x += 5;
drawArea.y += 5;
GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
GUI.DrawTexture(drawArea, m_Node.RenderPreview(new Rect(0, 0, drawArea.width, drawArea.height)), ScaleMode.StretchToFill, false);
GL.sRGBWrite = false;
Invalidate();
canvas.Repaint();
}
}
}

7
UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraph.cs


m_PixelGraph.owner = this;
}
public void OnDisable()
{
// if (m_MaterialProperties != null)
// m_MaterialProperties.OnChangePreviewState -= OnChangePreviewState;
}
m_PixelGraph.AddSubAssetsToAsset();
}
private Material m_Material;

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


return InternalUpdatePreviewShader(resultShader);
}
private static bool ShaderHasError(Shader shader)
{
var hasErrorsCall = typeof(ShaderUtil).GetMethod("GetShaderErrorCount", BindingFlags.Static | BindingFlags.NonPublic);
var result = hasErrorsCall.Invoke(null, new object[] { shader });
return (int)result != 0;
}
// workaround for some internal shader compiler weirdness
// if we are in error we sometimes to not properly clean
// clean out the error flags and will stay in error, even
// if we are now valid
if (m_PreviewShader && ShaderHasError(m_PreviewShader))
{
DestroyImmediate(m_PreviewShader, true);
DestroyImmediate(m_PreviewMaterial, true);
m_PreviewShader = null;
m_PreviewMaterial = null;
}
if (m_PreviewShader == null)
{
m_PreviewShader = ShaderUtil.CreateShaderAsset(resultShader);

}
else
{
var hash = resultShader.GetHashCode();
if (string.CompareOrdinal(resultShader, m_LastShader) != 0)
{
ShaderUtil.UpdateShaderAsset(m_PreviewShader, resultShader);

var hasErrorsCall = typeof(ShaderUtil).GetMethod("GetShaderErrorCount", BindingFlags.Static | BindingFlags.NonPublic);
var result = hasErrorsCall.Invoke(null, new object[] {m_PreviewShader});
return (int)result == 0;
return !ShaderHasError(m_PreviewShader);
}
private static Mesh[] s_Meshes = { null, null, null, null };

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


[SerializeField]
private Operation m_Operation;
private static readonly string[] kOpNames = new string[] {
private static readonly string[] kOpNames = {
"darken", "mul", "cburn", "lburn",
"lighten", "screen", "cdodge", "ldodge",
"overlay", "softl", "hardl", "vividl", "linearl", "pinl", "hardmix",

visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
/* public override void NodeUI()
public override float GetNodeUIHeight(float width)
base.NodeUI();
return EditorGUIUtility.singleLineHeight * 1;
}
public override GUIModificationType NodeUI(Rect drawArea)
{
base.NodeUI(drawArea);
m_Operation = (Operation)EditorGUILayout.EnumPopup(m_Operation);
m_Operation = (Operation)EditorGUI.EnumPopup(drawArea, m_Operation);
RegeneratePreviewShaders();
}*/
{
pixelGraph.RevalidateGraph();
return GUIModificationType.Repaint;
}
return GUIModificationType.None;
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{

37
UnityProject/Assets/UnityShaderEditor/Editor/Source/PixelGraph.cs


{
get
{
if (m_PixelMasterNode == null)
m_PixelMasterNode = nodes.FirstOrDefault(x => x.GetType() == typeof(PixelShaderNode)) as PixelShaderNode;
ConfigureMasterNode(true);
return m_PixelMasterNode;
}
}
private void ConfigureMasterNode(bool addToAsset)
{
if (m_PixelMasterNode == null)
m_PixelMasterNode = nodes.FirstOrDefault(x => x.GetType() == typeof(PixelShaderNode)) as PixelShaderNode;
if (m_PixelMasterNode == null)
{
m_PixelMasterNode = CreateInstance<PixelShaderNode>();
m_PixelMasterNode.hideFlags = HideFlags.HideInHierarchy;
m_PixelMasterNode.OnCreate();
m_PixelMasterNode.position = new Rect(700, pixelMasterNode.position.y, pixelMasterNode.position.width, pixelMasterNode.position.height);
if (m_PixelMasterNode == null)
{
m_PixelMasterNode = CreateInstance<PixelShaderNode>();
m_PixelMasterNode.OnCreate();
m_PixelMasterNode.position = new Rect(700, m_PixelMasterNode.position.y, m_PixelMasterNode.position.width, m_PixelMasterNode.position.height);
if (addToAsset)
}
}
}
return m_PixelMasterNode;
}
public override void OnEnable()
{
base.OnEnable();
ConfigureMasterNode(false);
}
public void AddSubAssetsToAsset()
{
AddNodeNoValidate(m_PixelMasterNode);
}
private List<BaseMaterialNode> m_ActiveNodes = new List<BaseMaterialNode>();

正在加载...
取消
保存