Tim Cooper
7 年前
当前提交
259c7ce1
共有 38 个文件被更改,包括 416 次插入 和 497 次删除
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractShaderProperty.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/BitangentMaterialSlot.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ColorShaderProperty.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/CubemapShaderProperty.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/FloatShaderProperty.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/IShaderProperty.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/NormalMaterialSlot.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/PositionMaterialSlot.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/SamplerStateShaderProperty.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ScreenPositionMaterialSlot.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TangentMaterialSlot.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/TextureShaderProperty.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/UVMaterialSlot.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2ShaderProperty.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3ShaderProperty.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/VectorShaderProperty.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/VertexColorMaterialSlot.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/ViewDirectionMaterialSlot.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Interfaces/NeededCoordinateSpace.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Normal/NormalUnpackNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/BitangentVectorNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/NormalVectorNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/PositionNode.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ScreenPositionNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/TangentVectorNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/UVNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/VertexColorNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ViewDirectionNode.cs
-
323MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/SubGraphNode.cs
-
103MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraph.cs
-
17MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphOutputNode.cs
-
34MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/GraphUtil.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Util/ShaderGenerator.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/MaterialGraphEditWindow.cs
-
65MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraph.cs
-
250MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
[Serializable] |
|||
public class AbstractSubGraph : AbstractMaterialGraph |
|||
, IGeneratesBodyCode |
|||
, IGeneratesFunction |
|||
{ |
|||
public virtual IEnumerable<AbstractMaterialNode> activeNodes { get { return Enumerable.Empty<AbstractMaterialNode>(); } } |
|||
|
|||
public PreviewMode previewMode |
|||
{ |
|||
get { return activeNodes.Any(x => x.previewMode == PreviewMode.Preview3D) ? PreviewMode.Preview3D : PreviewMode.Preview2D; } |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
foreach (var node in activeNodes) |
|||
{ |
|||
if (node is IGeneratesBodyCode) |
|||
(node as IGeneratesBodyCode).GenerateNodeCode(visitor, generationMode); |
|||
} |
|||
} |
|||
|
|||
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode) |
|||
{ |
|||
foreach (var node in activeNodes) |
|||
{ |
|||
if (node is IGeneratesFunction) |
|||
(node as IGeneratesFunction).GenerateNodeFunction(registry, generationMode); |
|||
} |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) |
|||
{ |
|||
// if we are previewing the graph we need to
|
|||
// export 'exposed props' if we are 'for real'
|
|||
// then we are outputting the graph in the
|
|||
// nested context and the needed values will
|
|||
// be copied into scope.
|
|||
if (generationMode == GenerationMode.Preview) |
|||
{ |
|||
foreach (var prop in properties) |
|||
collector.AddShaderProperty(prop); |
|||
} |
|||
|
|||
foreach (var node in activeNodes) |
|||
{ |
|||
if (node is IGenerateProperties) |
|||
(node as IGenerateProperties).CollectShaderProperties(collector, generationMode); |
|||
} |
|||
} |
|||
|
|||
public IEnumerable<PreviewProperty> GetPreviewProperties() |
|||
{ |
|||
List<PreviewProperty> props = new List<PreviewProperty>(); |
|||
foreach (var node in activeNodes) |
|||
node.CollectPreviewMaterialProperties(props); |
|||
return props; |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
using UnityEditor.Graphing; |
|||
|
|||
namespace UnityEditor.ShaderGraph |
|||
{ |
|||
public abstract class AbstractSubGraphNode : AbstractMaterialNode |
|||
, IGeneratesFunction |
|||
, IMayRequireNormal |
|||
, IMayRequireTangent |
|||
, IMayRequireBitangent |
|||
, IMayRequireMeshUV |
|||
, IMayRequireScreenPosition |
|||
, IMayRequireViewDirection |
|||
, IMayRequirePosition |
|||
, IMayRequireVertexColor |
|||
, IMayRequireTime |
|||
{ |
|||
protected abstract AbstractSubGraph referencedGraph { get; } |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return referencedGraph != null; } |
|||
} |
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get |
|||
{ |
|||
if (referencedGraph == null) |
|||
return PreviewMode.Preview2D; |
|||
|
|||
return PreviewMode.Preview3D; |
|||
} |
|||
} |
|||
|
|||
public virtual INode outputNode |
|||
{ |
|||
get { return null; } |
|||
} |
|||
|
|||
public virtual void UpdateSlots() |
|||
{ |
|||
var validNames = new List<int>(); |
|||
if (referencedGraph == null) |
|||
{ |
|||
RemoveSlotsNameNotMatching(validNames); |
|||
return; |
|||
} |
|||
|
|||
var props = referencedGraph.properties; |
|||
foreach (var prop in props) |
|||
{ |
|||
var propType = prop.propertyType; |
|||
SlotValueType slotType; |
|||
|
|||
switch (propType) |
|||
{ |
|||
case PropertyType.Color: |
|||
slotType = SlotValueType.Vector4; |
|||
break; |
|||
case PropertyType.Texture: |
|||
slotType = SlotValueType.Texture2D; |
|||
break; |
|||
case PropertyType.Cubemap: |
|||
slotType = SlotValueType.Cubemap; |
|||
break; |
|||
case PropertyType.Float: |
|||
slotType = SlotValueType.Vector1; |
|||
break; |
|||
case PropertyType.Vector2: |
|||
slotType = SlotValueType.Vector2; |
|||
break; |
|||
case PropertyType.Vector3: |
|||
slotType = SlotValueType.Vector3; |
|||
break; |
|||
case PropertyType.Vector4: |
|||
slotType = SlotValueType.Vector4; |
|||
break; |
|||
case PropertyType.Matrix2: |
|||
slotType = SlotValueType.Matrix2; |
|||
break; |
|||
case PropertyType.Matrix3: |
|||
slotType = SlotValueType.Matrix3; |
|||
break; |
|||
case PropertyType.Matrix4: |
|||
slotType = SlotValueType.Matrix4; |
|||
break; |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
|
|||
var id = prop.guid.GetHashCode(); |
|||
MaterialSlot slot = MaterialSlot.CreateMaterialSlot(slotType, id, prop.displayName, prop.referenceName, SlotType.Input, prop.defaultValue); |
|||
// copy default for texture for niceness
|
|||
if (slotType == SlotValueType.Texture2D && propType == PropertyType.Texture) |
|||
{ |
|||
var tSlot = slot as Texture2DInputMaterialSlot; |
|||
var tProp = prop as TextureShaderProperty; |
|||
if (tSlot != null && tProp != null) |
|||
tSlot.texture = tProp.value.texture; |
|||
} |
|||
// copy default for cubemap for niceness
|
|||
else if (slotType == SlotValueType.Cubemap && propType == PropertyType.Cubemap) |
|||
{ |
|||
var tSlot = slot as CubemapInputMaterialSlot; |
|||
var tProp = prop as CubemapShaderProperty; |
|||
if (tSlot != null && tProp != null) |
|||
tSlot.cubemap = tProp.value.cubemap; |
|||
} |
|||
AddSlot(slot); |
|||
validNames.Add(id); |
|||
} |
|||
|
|||
var subGraphOutputNode = outputNode; |
|||
if (outputNode != null) |
|||
{ |
|||
foreach (var slot in subGraphOutputNode.GetInputSlots<MaterialSlot>()) |
|||
{ |
|||
AddSlot(MaterialSlot.CreateMaterialSlot(slot.valueType, slot.id, slot.RawDisplayName(), slot.shaderOutputName, SlotType.Output, Vector4.zero)); |
|||
validNames.Add(slot.id); |
|||
} |
|||
} |
|||
|
|||
RemoveSlotsNameNotMatching(validNames); |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector visitor, GenerationMode generationMode) |
|||
{ |
|||
base.CollectShaderProperties(visitor, generationMode); |
|||
|
|||
if (referencedGraph == null) |
|||
return; |
|||
|
|||
referencedGraph.CollectShaderProperties(visitor, GenerationMode.ForReals); |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
base.CollectPreviewMaterialProperties(properties); |
|||
|
|||
if (referencedGraph == null) |
|||
return; |
|||
|
|||
properties.AddRange(referencedGraph.GetPreviewProperties()); |
|||
} |
|||
|
|||
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode) |
|||
{ |
|||
if (referencedGraph == null) |
|||
return; |
|||
|
|||
referencedGraph.GenerateNodeFunction(registry, GenerationMode.ForReals); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal() |
|||
{ |
|||
if (referencedGraph == null) |
|||
return NeededCoordinateSpace.None; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequireNormal>().Aggregate(NeededCoordinateSpace.None, (mask, node) => |
|||
{ |
|||
mask |= node.RequiresNormal(); |
|||
return mask; |
|||
}); |
|||
} |
|||
|
|||
public bool RequiresMeshUV(UVChannel channel) |
|||
{ |
|||
if (referencedGraph == null) |
|||
return false; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequireMeshUV>().Any(x => x.RequiresMeshUV(channel)); |
|||
} |
|||
|
|||
public bool RequiresScreenPosition() |
|||
{ |
|||
if (referencedGraph == null) |
|||
return false; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequireScreenPosition>().Any(x => x.RequiresScreenPosition()); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresViewDirection() |
|||
{ |
|||
if (referencedGraph == null) |
|||
return NeededCoordinateSpace.None; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequireViewDirection>().Aggregate(NeededCoordinateSpace.None, (mask, node) => |
|||
{ |
|||
mask |= node.RequiresViewDirection(); |
|||
return mask; |
|||
}); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresPosition() |
|||
{ |
|||
if (referencedGraph == null) |
|||
return NeededCoordinateSpace.None; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequirePosition>().Aggregate(NeededCoordinateSpace.None, (mask, node) => |
|||
{ |
|||
mask |= node.RequiresPosition(); |
|||
return mask; |
|||
}); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresTangent() |
|||
{ |
|||
if (referencedGraph == null) |
|||
return NeededCoordinateSpace.None; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequireTangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => |
|||
{ |
|||
mask |= node.RequiresTangent(); |
|||
return mask; |
|||
}); |
|||
} |
|||
|
|||
public bool RequiresTime() |
|||
{ |
|||
if (referencedGraph == null) |
|||
return false; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequireTime>().Any(x => x.RequiresTime()); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresBitangent() |
|||
{ |
|||
if (referencedGraph == null) |
|||
return NeededCoordinateSpace.None; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequireBitangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => |
|||
{ |
|||
mask |= node.RequiresBitangent(); |
|||
return mask; |
|||
}); |
|||
} |
|||
|
|||
public bool RequiresVertexColor() |
|||
{ |
|||
if (referencedGraph == null) |
|||
return false; |
|||
|
|||
return referencedGraph.activeNodes.OfType<IMayRequireVertexColor>().Any(x => x.RequiresVertexColor()); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue