浏览代码
[shader graph]Integtate new non modifiable settings into shader graph. Fix setting properties generation pipe to be simpler.
/main
[shader graph]Integtate new non modifiable settings into shader graph. Fix setting properties generation pipe to be simpler.
/main
Tim Cooper
9 年前
当前提交
6086c6d6
共有 10 个文件被更改,包括 162 次插入 和 180 次删除
-
25UnityProject/Assets/UnityShaderEditor/Editor/Source/MaterialGraph.cs
-
24UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/BaseMaterialNode.cs
-
9UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/ColorNode.cs
-
2UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/PixelShaderNode.cs
-
9UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/TextureNode.cs
-
9UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector1Node.cs
-
213UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector2Node.cs
-
7UnityProject/Assets/UnityShaderEditor/Editor/Source/Nodes/Vector4Node.cs
-
2UnityProject/Assets/UnityShaderEditor/Editor/Source/Prop/TextureProperty.cs
-
42UnityProject/Assets/UnityShaderEditor/Editor/Source/Util/ShaderGenerator.cs
|
|||
using System; |
|||
using UnityEditor.Graphs; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Generate/Vector 2 Node")] |
|||
class Vector2Node : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
private const string kOutputSlotName = "Value"; |
|||
|
|||
[SerializeField] |
|||
private Vector2 m_Value; |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
base.OnCreate(); |
|||
name = "V2Node"; |
|||
} |
|||
|
|||
public override void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
AddSlot(new MaterialGraphSlot(new Slot(SlotType.OutputSlot, kOutputSlotName), SlotValueType.Vector2)); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Vector2; } |
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{} |
|||
|
|||
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode) |
|||
{ |
|||
return GetPropertyName(); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType valueType) |
|||
{ |
|||
if (HasBoundProperty() || !generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk("float2 " + GetPropertyName() + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (HasBoundProperty() || generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + "2 " + GetPropertyName() + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true); |
|||
} |
|||
|
|||
public override float GetNodeUIHeight(float width) |
|||
{ |
|||
return 2*EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public override bool NodeUI(Rect drawArea) |
|||
{ |
|||
base.NodeUI(drawArea); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Value = EditorGUI.Vector2Field(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), "Value", m_Value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
var boundProp = boundProperty as VectorProperty; |
|||
if (boundProp != null) |
|||
{ |
|||
boundProp.defaultVector = m_Value; |
|||
} |
|||
UpdatePreviewProperties(); |
|||
ForwardPreviewMaterialPropertyUpdate(); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public override void BindProperty(ShaderProperty property, bool rebuildShaders) |
|||
{ |
|||
base.BindProperty(property, rebuildShaders); |
|||
|
|||
var vectorProp = property as VectorProperty; |
|||
if (vectorProp) |
|||
{ |
|||
m_Value = vectorProp.defaultVector; |
|||
} |
|||
|
|||
if (rebuildShaders) |
|||
RegeneratePreviewShaders(); |
|||
else |
|||
{ |
|||
UpdatePreviewProperties(); |
|||
ForwardPreviewMaterialPropertyUpdate(); |
|||
} |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = GetPropertyName(), |
|||
m_PropType = PropertyType.Vector2, |
|||
m_Vector4 = m_Value |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
using System; |
|||
using UnityEditor.Graphs; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.MaterialGraph |
|||
{ |
|||
[Title("Generate/Vector 2 Node")] |
|||
class Vector2Node : PropertyNode, IGeneratesBodyCode |
|||
{ |
|||
private const string kOutputSlotName = "Value"; |
|||
|
|||
[SerializeField] |
|||
private Vector2 m_Value; |
|||
|
|||
public override void OnCreate() |
|||
{ |
|||
base.OnCreate(); |
|||
name = "V2Node"; |
|||
} |
|||
|
|||
public override void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
AddSlot(new MaterialGraphSlot(new Slot(SlotType.OutputSlot, kOutputSlotName), SlotValueType.Vector2)); |
|||
} |
|||
|
|||
public override PropertyType propertyType |
|||
{ |
|||
get { return PropertyType.Vector2; } |
|||
} |
|||
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{} |
|||
|
|||
public override string GetOutputVariableNameForSlot(Slot s, GenerationMode generationMode) |
|||
{ |
|||
return GetPropertyName(); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode, ConcreteSlotValueType valueType) |
|||
{ |
|||
if (HasBoundProperty() || !generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk("float2 " + GetPropertyName() + ";", true); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (HasBoundProperty() || generationMode.IsPreview()) |
|||
return; |
|||
|
|||
visitor.AddShaderChunk(precision + "2 " + GetPropertyName() + " = " + precision + "2 (" + m_Value.x + ", " + m_Value.y + ");", true); |
|||
} |
|||
|
|||
public override float GetNodeUIHeight(float width) |
|||
{ |
|||
return 2*EditorGUIUtility.singleLineHeight; |
|||
} |
|||
|
|||
public override bool NodeUI(Rect drawArea) |
|||
{ |
|||
base.NodeUI(drawArea); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
m_Value = EditorGUI.Vector2Field(new Rect(drawArea.x, drawArea.y, drawArea.width, EditorGUIUtility.singleLineHeight), "Value", m_Value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
var boundProp = boundProperty as VectorProperty; |
|||
if (boundProp != null) |
|||
{ |
|||
boundProp.defaultVector = m_Value; |
|||
} |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
public override void BindProperty(ShaderProperty property, bool rebuildShaders) |
|||
{ |
|||
base.BindProperty(property, rebuildShaders); |
|||
|
|||
var vectorProp = property as VectorProperty; |
|||
if (vectorProp) |
|||
{ |
|||
m_Value = vectorProp.defaultVector; |
|||
} |
|||
|
|||
if (rebuildShaders) |
|||
RegeneratePreviewShaders(); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = GetPropertyName(), |
|||
m_PropType = PropertyType.Vector2, |
|||
m_Vector4 = m_Value |
|||
}; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue