Tim Cooper
9 年前
当前提交
c522adcc
共有 20 个文件被更改,包括 160 次插入 和 543 次删除
-
90MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/DrawableNode.cs
-
1MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/GraphDataSource.cs
-
4MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/GUIModificationType.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/CombineNodeUI.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbsoluteNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ScreenPosNode.cs
-
123MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SlotValue.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SwizzleNode.cs
-
67MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TimeNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UVNode.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ViewDirectionNode.cs
-
63MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/TextureNodeUI.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/TextureNodeUI.cs.meta
-
96MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/KaleidoscopeNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/KaleidoscopeNode.cs.meta
-
101MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MandelbrotNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MandelbrotNode.cs.meta
-
105MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PerlinNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PerlinNode.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Graphing; |
|||
using UnityEditor.Graphing.Drawing; |
|||
using UnityEngine; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[CustomNodeUI(typeof(TextureNode))] |
|||
public class TextureNodeUI : AbstractMaterialNodeUI |
|||
{ |
|||
public override float GetNodeUiHeight(float width) |
|||
{ |
|||
return base.GetNodeUiHeight(width) + EditorGUIUtility.singleLineHeight * 2; |
|||
} |
|||
|
|||
private string[] m_TextureTypeNames; |
|||
private string[] textureTypeNames |
|||
{ |
|||
get |
|||
{ |
|||
if (m_TextureTypeNames == null) |
|||
m_TextureTypeNames = Enum.GetNames(typeof(TextureType)); |
|||
return m_TextureTypeNames; |
|||
} |
|||
} |
|||
|
|||
public override GUIModificationType Render(Rect area) |
|||
{ |
|||
var node = m_Node as TextureNode; |
|||
if (node == null) |
|||
return base.Render(area); |
|||
|
|||
if (m_Node == null) |
|||
return GUIModificationType.None; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
node.defaultTexture = EditorGUI.MiniThumbnailObjectField(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), new GUIContent("Texture"), node.defaultTexture, typeof(Texture2D), null) as Texture2D; |
|||
var texureChanged = EditorGUI.EndChangeCheck(); |
|||
area.y += EditorGUIUtility.singleLineHeight; |
|||
area.height -= EditorGUIUtility.singleLineHeight; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
node.textureType = (TextureType)EditorGUI.Popup(new Rect(area.x, area.y, area.width, EditorGUIUtility.singleLineHeight), (int)node.textureType, textureTypeNames, EditorStyles.popup); |
|||
var typeChanged = EditorGUI.EndChangeCheck(); |
|||
|
|||
var toReturn = GUIModificationType.None; |
|||
if (typeChanged) |
|||
{ |
|||
toReturn |= GUIModificationType.DataChanged; |
|||
} |
|||
|
|||
if (texureChanged) |
|||
toReturn |= GUIModificationType.Repaint; |
|||
|
|||
area.y += EditorGUIUtility.singleLineHeight; |
|||
area.height -= EditorGUIUtility.singleLineHeight; |
|||
toReturn |= base.Render(area); |
|||
return toReturn; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 18bed0222cc2dfa4db99426806adb913 |
|||
timeCreated: 1465476659 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
/* |
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Fractal/Kaleidoscope Node")] |
|||
class KaleidoscopeNode : BaseMaterialNode, IGeneratesFunction, IGeneratesBodyCode |
|||
{ |
|||
[SerializeField] |
|||
private int m_Iterations = 6; |
|||
|
|||
private const string kPointInputName = "Point"; |
|||
private const string kConstant1InputName = "Constant1"; |
|||
private const string kConstant2InputName = "Constant2"; |
|||
private const string kOutputSlotName = "Output"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
name = "KaleidoscopeNode"; |
|||
base.OnCreate(); |
|||
// AddSlot(new Slot(SlotType.InputSlot, kPointInputName));
|
|||
//AddSlot(new Slot(SlotType.InputSlot, kConstant1InputName));
|
|||
//AddSlot(new Slot(SlotType.InputSlot, kConstant2InputName));
|
|||
//AddSlot(new Slot(SlotType.OutputSlot, kOutputSlotName));
|
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_kaleidoscope_" + precision + " (" + precision + "2 p, " + precision + "4 c1, " + precision + "4 c2, int iterations)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("c1 = c1 * 2 - 1;", false); |
|||
outputString.AddShaderChunk("c2 = c2 * 2 - 1;", false); |
|||
outputString.AddShaderChunk("for (int n = 0; n < iterations; n++)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("p = c1.xy + p * c1.zw + " + precision + "2(dot(p, c2.xy), dot(p, c2.zw));", false); |
|||
outputString.AddShaderChunk("if(p.x < p.y) p.xy = -p.yx;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("return " + precision + "4(p, 1, 1);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputSlot = FindOutputSlot(kOutputSlotName); |
|||
var pointInput = FindInputSlot(kPointInputName); |
|||
var constant1Input = FindInputSlot(kConstant1InputName); |
|||
var constant2Input = FindInputSlot(kConstant2InputName); |
|||
|
|||
if (outputSlot == null || pointInput == null || constant1Input == null || constant2Input == null) |
|||
{ |
|||
Debug.LogError("Invalid slot configuration on node: " + name); |
|||
return; |
|||
} |
|||
|
|||
string pointInputValue = GetSlotValue(pointInput, generationMode); |
|||
string constant1InputValue = GetSlotValue(constant1Input, generationMode); |
|||
string constant2InputValue = GetSlotValue(constant2Input, generationMode); |
|||
|
|||
string outName = GetOutputVariableNameForSlot(outputSlot, generationMode); |
|||
visitor.AddShaderChunk(precision + "4 " + outName + " = unity_kaleidoscope_" + precision + "(" + pointInputValue + ".xy, " + constant1InputValue + ", " + constant2InputValue + ", " + m_Iterations + ");", false); |
|||
} |
|||
|
|||
static float Slider(string title, float value, float from, float to) |
|||
{ |
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.Label(title); |
|||
value = GUILayout.HorizontalSlider(value, from, to, GUILayout.Width(64)); |
|||
GUILayout.EndHorizontal(); |
|||
return value; |
|||
} |
|||
|
|||
/*public override void NodeUI() |
|||
{ |
|||
base.NodeUI(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 50); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
RegeneratePreviewShaders(); |
|||
}* |
|||
} |
|||
} |
|||
*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: dfc00afcda39bfa4fbd9bd6176f53477 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using System; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
/* |
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Fractal/Mandelbrot Node")] |
|||
class MandelbrotNode : BaseMaterialNode, IGeneratesFunction, IGeneratesBodyCode |
|||
{ |
|||
[SerializeField] |
|||
private int m_Iterations = 6; |
|||
|
|||
private const string kPointInputName = "Point"; |
|||
private const string kConstantInputName = "Constant"; |
|||
private const string kOutputSlotName = "Output"; |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
name = "MandelbrotNode"; |
|||
base.OnCreate(); |
|||
//AddSlot(new Slot(SlotType.InputSlot, kPointInputName));
|
|||
//AddSlot(new Slot(SlotType.InputSlot, kConstantInputName));
|
|||
//AddSlot(new Slot(SlotType.OutputSlot, kOutputSlotName));
|
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_mandelbrot_" + precision + " (" + precision + "2 p, " + precision + "2 c, float limit, float scale, int iterations)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + " zr = p.x * 4 - 2, zi = p.y * 4 - 2, dzr = 1, dzi = 0, r = 0, len2;", false); |
|||
outputString.AddShaderChunk("for (int n = 0; n < iterations; n++)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + " tmp1 = 2 * zr * zi + c.y; zr = zr * zr - zi * zi + c.x; zi = tmp1;", false); |
|||
outputString.AddShaderChunk(precision + " tmp2 = 2 * (dzr * zi + dzi * zr); dzr = 2 * (dzr * zr - dzi * zi) + 1; dzi = tmp2;", false); |
|||
outputString.AddShaderChunk("len2 = zr * zr + zi * zi;", false); |
|||
outputString.AddShaderChunk("if (len2 > 1000000 * limit) { r = n; break; }", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("return scale * sqrt(len2 / (dzr * dzr + dzi * dzi)) * log(len2);", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var validSlots = ListPool<Slot>.Get(); |
|||
GetValidInputSlots(validSlots); |
|||
|
|||
var outputSlot = outputSlots.FirstOrDefault(x => x.name == kOutputSlotName); |
|||
var pointInput = validSlots.FirstOrDefault(x => x.name == kPointInputName); |
|||
var constantInput = validSlots.FirstOrDefault(x => x.name == kConstantInputName); |
|||
|
|||
ListPool<Slot>.Release(validSlots); |
|||
|
|||
if (outputSlot == null || pointInput == null || constantInput == null) |
|||
{ |
|||
Debug.LogError("Invalid slot configuration on node: " + name); |
|||
return; |
|||
} |
|||
|
|||
//TODO: This will break if there is NO input connected, use default in that case
|
|||
var pointProvider = pointInput.edges[0].fromSlot.node as BaseMaterialNode; |
|||
var pointName = pointProvider.GetOutputVariableNameForSlot(pointInput.edges[0].fromSlot, generationMode); |
|||
|
|||
var constantProvider = constantInput.edges[0].fromSlot.node as BaseMaterialNode; |
|||
var constantName = constantProvider.GetOutputVariableNameForSlot(constantInput.edges[0].fromSlot, generationMode); |
|||
|
|||
string outName = GetOutputVariableNameForSlot(outputSlot, generationMode); |
|||
visitor.AddShaderChunk(precision + "4 " + outName + " = unity_mandelbrot_" + precision + "(" + pointName + ".xy, " + constantName + ".xy, " + constantName + ".z, " + constantName + ".w, " + m_Iterations + ");", false); |
|||
} |
|||
|
|||
static float Slider(string title, float value, float from, float to) |
|||
{ |
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.Label(title); |
|||
value = GUILayout.HorizontalSlider(value, from, to, GUILayout.Width(64)); |
|||
GUILayout.EndHorizontal(); |
|||
return value; |
|||
} |
|||
|
|||
/*public override void NodeUI() |
|||
{ |
|||
base.NodeUI(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 50); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
RegeneratePreviewShaders(); |
|||
}* |
|||
} |
|||
}*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: 45896ba83118f8548bd9d2f9263bcde5 |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|
|||
using UnityEngine; |
|||
|
|||
/* |
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Fractal/Perlin Node")] |
|||
class PerlinNode : TextureNode, IGeneratesFunction, IGeneratesBodyCode |
|||
{ |
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
[SerializeField] |
|||
private int m_Iterations = 4; |
|||
|
|||
[SerializeField] |
|||
private float m_Decay = 0.5f; |
|||
|
|||
[SerializeField] |
|||
private float m_Frequency = 2.0f; |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
name = "Perlin"; |
|||
base.OnCreate(); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputString = new ShaderGenerator(); |
|||
foreach (var precision in m_PrecisionNames) |
|||
{ |
|||
outputString.AddShaderChunk("inline " + precision + "4 unity_perlin_" + precision + " (" |
|||
+ "sampler2D textureID, " |
|||
+ "int iterations, " |
|||
+ precision + " decay, " |
|||
+ precision + " frequency, " |
|||
+ precision + "2 p" |
|||
+ ")", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk(precision + "4 sum = " + precision + "4(0, 0, 0, 0);", false); |
|||
outputString.AddShaderChunk(precision + " amp = 0.5;", false); |
|||
outputString.AddShaderChunk("for(int n = 0; n < iterations; n++)", false); |
|||
outputString.AddShaderChunk("{", false); |
|||
outputString.Indent(); |
|||
outputString.AddShaderChunk("sum += amp * tex2D (textureID, p);", false); |
|||
outputString.AddShaderChunk("p *= frequency;", false); |
|||
outputString.AddShaderChunk("amp *= decay;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
outputString.AddShaderChunk("return sum;", false); |
|||
outputString.Deindent(); |
|||
outputString.AddShaderChunk("}", false); |
|||
} |
|||
|
|||
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|||
} |
|||
|
|||
/* public override void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var outputSlot = FindOutputSlot(kOutputSlotName); |
|||
if (outputSlot == null) |
|||
return; |
|||
|
|||
var uvSlot = FindInputSlot(kUVSlotName); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var uvName = "IN.meshUV0"; |
|||
if (uvSlot.edges.Count > 0) |
|||
{ |
|||
var fromNode = uvSlot.edges[0].fromSlot.node as BaseMaterialNode; |
|||
uvName = fromNode.GetOutputVariableNameForSlot(uvSlot.edges[0].fromSlot, generationMode); |
|||
} |
|||
|
|||
string body = "unity_perlin_" + precision + "(" + GetPropertyName() + ", " + m_Iterations + ", " + m_Decay + ", " + m_Frequency + ", " + uvName + ".xy)"; |
|||
visitor.AddShaderChunk("float4 " + GetOutputVariableNameForSlot(outputSlot, generationMode) + " = " + body + ";", true); |
|||
} |
|||
* |
|||
static float Slider(string title, float value, float from, float to) |
|||
{ |
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.Label(title); |
|||
value = GUILayout.HorizontalSlider(value, from, to, GUILayout.Width(64)); |
|||
GUILayout.EndHorizontal(); |
|||
return value; |
|||
} |
|||
/* |
|||
public override float GetNodeUIHeight() |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public override bool NodeUI(Rect drawArea) |
|||
{ |
|||
base.NodeUI(drawArea); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Iterations = (int)Slider("Iterations", (float)m_Iterations, 1, 8); |
|||
m_Decay = Slider("Decay", m_Decay, -1f, 1f); |
|||
m_Frequency = Slider("Frequency", m_Frequency, 0f, 5f); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
RegeneratePreviewShaders(); |
|||
}* |
|||
} |
|||
}*/ |
|
|||
fileFormatVersion: 2 |
|||
guid: 6388ec78711fae240b4d5c60bd70d36d |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
撰写
预览
正在加载...
取消
保存
Reference in new issue