Tim Cooper
7 年前
当前提交
5a5f791f
共有 30 个文件被更改,包括 387 次插入 和 452 次删除
-
34MaterialGraphProject/Assets/NewNodes/Editor/Keep/TextureSamplerNode.cs
-
19MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BitangentMaterialSlot.cs
-
40MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
-
57MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix2MaterialSlot.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix3MaterialSlot.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Matrix4MaterialSlot.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/NormalMaterialSlot.cs
-
17MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/PositionMaterialSlot.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerStateMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SerializableTexture.cs
-
17MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TangentMaterialSlot.cs
-
16MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Texture2DMaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/UVMaterialSlot.cs
-
28MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs
-
26MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs
-
25MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs
-
26MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs
-
17MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ViewDirectionMaterialSlot.cs
-
25MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
219MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Texture/TextureNode.cs
-
64MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/MaterialNodeView.cs
-
36MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SpaceMaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SpaceMaterialSlot.cs.meta
-
72MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
/* [Title("Input/Texture/Texture")] |
|||
public class TextureNode : PropertyNode, IGeneratesBodyCode, IMayRequireMeshUV |
|||
{ |
|||
protected const string kUVSlotName = "UV"; |
|||
protected const string kOutputSlotRGBAName = "RGBA"; |
|||
protected const string kOutputSlotRName = "R"; |
|||
protected const string kOutputSlotGName = "G"; |
|||
protected const string kOutputSlotBName = "B"; |
|||
protected const string kOutputSlotAName = "A"; |
|||
public const int UvSlotId = 0; |
|||
public const int OutputSlotRgbaId = 1; |
|||
public const int OutputSlotRId = 2; |
|||
public const int OutputSlotGId = 3; |
|||
public const int OutputSlotBId = 4; |
|||
public const int OutputSlotAId = 5; |
|||
|
|||
[SerializeField] |
|||
private string m_SerializedTexture; |
|||
|
|||
[SerializeField] |
|||
private TextureType m_TextureType; |
|||
|
|||
[Serializable] |
|||
private class TextureHelper |
|||
{ |
|||
public Texture texture; |
|||
} |
|||
|
|||
public override bool hasPreview { get { return true; } } |
|||
|
|||
#if UNITY_EDITOR
|
|||
public Texture defaultTexture |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedTexture)) |
|||
return null; |
|||
|
|||
var tex = new TextureHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, tex); |
|||
return tex.texture; |
|||
} |
|||
set |
|||
{ |
|||
if (defaultTexture == value) |
|||
return; |
|||
|
|||
var tex = new TextureHelper(); |
|||
tex.texture = value; |
|||
m_SerializedTexture = EditorJsonUtility.ToJson(tex, true); |
|||
|
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
#else
|
|||
public Texture defaultTexture {get; set; } |
|||
#endif
|
|||
|
|||
public TextureType textureType |
|||
{ |
|||
get { return m_TextureType; } |
|||
set |
|||
{ |
|||
if (m_TextureType == value) |
|||
return; |
|||
|
|||
|
|||
m_TextureType = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public TextureNode() |
|||
{ |
|||
name = "Texture"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new MaterialSlot(OutputSlotRgbaId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero)); |
|||
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero, false)); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] {OutputSlotRgbaId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, UvSlotId}; } |
|||
} |
|||
|
|||
// Node generations
|
|||
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId); |
|||
if (uvSlot == null) |
|||
return; |
|||
|
|||
var uvName = string.Format("{0}.xy", UVChannel.uv0.GetUVName()); |
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
|
|||
if (edges.Count > 0) |
|||
{ |
|||
var edge = edges[0]; |
|||
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|||
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true); |
|||
} |
|||
|
|||
string body = "tex2D (" + propertyName + ", " + uvName + ")"; |
|||
if (m_TextureType == TextureType.Bump) |
|||
body = precision + "4(UnpackNormal(" + body + "), 0)"; |
|||
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + body + ";", true); |
|||
} |
|||
|
|||
public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
string slotOutput; |
|||
switch (slotId) |
|||
{ |
|||
case OutputSlotRId: |
|||
slotOutput = ".r"; |
|||
break; |
|||
case OutputSlotGId: |
|||
slotOutput = ".g"; |
|||
break; |
|||
case OutputSlotBId: |
|||
slotOutput = ".b"; |
|||
break; |
|||
case OutputSlotAId: |
|||
slotOutput = ".a"; |
|||
break; |
|||
default: |
|||
slotOutput = ""; |
|||
break; |
|||
} |
|||
return GetVariableNameForNode() + slotOutput; |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
properties.Add(GetPreviewProperty()); |
|||
} |
|||
|
|||
// Properties
|
|||
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderProperty( |
|||
new TexturePropertyChunk( |
|||
propertyName, |
|||
description, |
|||
defaultTexture, m_TextureType, |
|||
PropertyChunk.HideState.Visible, |
|||
exposedState == ExposedState.Exposed ? |
|||
TexturePropertyChunk.ModifiableState.Modifiable |
|||
: TexturePropertyChunk.ModifiableState.NonModifiable)); |
|||
} |
|||
|
|||
public override void GeneratePropertyUsages(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk("sampler2D " + propertyName + ";", true); |
|||
} |
|||
|
|||
/* |
|||
public override bool DrawSlotDefaultInput(Rect rect, Slot inputSlot) |
|||
{ |
|||
var uvSlot = FindInputSlot(kUVSlotName); |
|||
if (uvSlot != inputSlot) |
|||
return base.DrawSlotDefaultInput(rect, inputSlot); |
|||
|
|||
|
|||
var rectXmax = rect.xMax; |
|||
rect.x = rectXmax - 70; |
|||
rect.width = 70; |
|||
|
|||
EditorGUI.DrawRect(rect, new Color(0.0f, 0.0f, 0.0f, 0.7f)); |
|||
GUI.Label(rect, "From Mesh"); |
|||
|
|||
return false; |
|||
} |
|||
* |
|||
|
|||
public override PreviewProperty GetPreviewProperty() |
|||
{ |
|||
return new PreviewProperty |
|||
{ |
|||
m_Name = propertyName, |
|||
m_PropType = PropertyType.Texture, |
|||
m_Texture = defaultTexture |
|||
}; |
|||
} |
|||
|
|||
public override PropertyType propertyType { get { return PropertyType.Texture; } } |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
if (channel != UVChannel.uv0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId); |
|||
if (uvSlot == null) |
|||
return true; |
|||
|
|||
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|||
return edges.Count == 0; |
|||
} |
|||
}*/ |
|||
} |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public abstract class SpaceMaterialSlot : Vector3MaterialSlot |
|||
{ |
|||
[SerializeField] |
|||
private CoordinateSpace m_Space = CoordinateSpace.World; |
|||
|
|||
public CoordinateSpace space |
|||
{ |
|||
get { return m_Space; } |
|||
set { m_Space = value; } |
|||
} |
|||
|
|||
protected SpaceMaterialSlot() |
|||
{} |
|||
|
|||
protected SpaceMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden) |
|||
{ |
|||
this.space = space; |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as NormalMaterialSlot; |
|||
if (slot != null) |
|||
space = slot.space; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 66199806246c45e493afdfc09208cbdc |
|||
timeCreated: 1509290088 |
|
|||
using System; |
|||
using UnityEditor.Graphing; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class Texture2DInputMaterialSlot : Texture2DMaterialSlot |
|||
{ |
|||
[SerializeField] |
|||
private SerializableTexture m_Texture = new SerializableTexture(); |
|||
|
|||
public Texture texture |
|||
{ |
|||
get { return m_Texture.texture; } |
|||
set { m_Texture.texture = value; } |
|||
} |
|||
|
|||
public Texture2DInputMaterialSlot() |
|||
{} |
|||
|
|||
public Texture2DInputMaterialSlot( |
|||
int slotId, |
|||
string displayName, |
|||
string shaderOutputName, |
|||
ShaderStage shaderStage = ShaderStage.Dynamic, |
|||
bool hidden = false) |
|||
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStage, hidden) |
|||
{} |
|||
|
|||
public override string GetDefaultValue(GenerationMode generationMode) |
|||
{ |
|||
var matOwner = owner as AbstractMaterialNode; |
|||
if (matOwner == null) |
|||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); |
|||
|
|||
return matOwner.GetVariableNameForSlot(id); |
|||
} |
|||
|
|||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
var matOwner = owner as AbstractMaterialNode; |
|||
if (matOwner == null) |
|||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); |
|||
|
|||
var prop = new TextureShaderProperty(); |
|||
prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id); |
|||
prop.modifiable = false; |
|||
prop.generatePropertyBlock = true; |
|||
prop.value.texture = texture; |
|||
properties.AddShaderProperty(prop); |
|||
} |
|||
|
|||
public override PreviewProperty GetPreviewProperty(string name) |
|||
{ |
|||
var pp = new PreviewProperty |
|||
{ |
|||
m_Name = name, |
|||
m_PropType = PropertyType.Texture, |
|||
m_Texture = texture |
|||
}; |
|||
return pp; |
|||
} |
|||
|
|||
public override void CopyValuesFrom(MaterialSlot foundSlot) |
|||
{ |
|||
var slot = foundSlot as Texture2DInputMaterialSlot; |
|||
if (slot != null) |
|||
m_Texture = slot.m_Texture; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ebeb3a21d05d49caa5d3318fb49b7612 |
|||
timeCreated: 1509276977 |
撰写
预览
正在加载...
取消
保存
Reference in new issue