浏览代码
Merge branch 'exposed-prop-subgraph'
Merge branch 'exposed-prop-subgraph'
# Conflicts: # MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs/main
Tim Cooper
7 年前
当前提交
f2cae710
共有 74 个文件被更改,包括 1241 次插入 和 1572 次删除
-
7MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/NodeUtils.cs
-
1MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
-
2MaterialGraphProject/Assets/NewNodes/Keep/SamplerStateNode.cs
-
2MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPBR.shader
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateRemapGraph.cs
-
1MaterialGraphProject/Assets/UnityShaderEditor/Editor/AssetCallbacks/CreateShaderSubGraph.cs
-
105MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
-
61MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/RemapMasterNodePresenter.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/PropertyNodePresenter.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewSystem.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/ShaderGraphImporter.cs
-
19MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightSubshaderPBR.template
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightSubshaderUnlit.template
-
2MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/Graphs/Add-Sub-Graph.ShaderSubGraph.meta
-
139MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/AbstractMaterialGraph.cs
-
18MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/AbstractShaderProperty.cs
-
13MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/ColorShaderProperty.cs
-
13MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/FloatShaderProperty.cs
-
9MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/IShaderProperty.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialGraph.cs
-
26MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/MaterialSlot.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/SamplerStateShaderProperty.cs
-
17MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/TextureShaderProperty.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/Vector2ShaderProperty.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/Vector3ShaderProperty.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/Vector4ShaderProperty.cs
-
6MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Graphs/VectorShaderProperty.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Interfaces/IGenerateProperties.cs
-
166MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightMasterNode.cs
-
39MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/AbstractLightweightPBRMasterNode.cs
-
20MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightMetallicMasterNode.cs
-
33MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightSpecularMasterNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/LightweightPipeline/LightweightUnlitMasterNode.cs
-
15MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AbstractMaterialNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/ColorNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Geometry/ViewDirectionNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector1Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector2Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector3Node.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Input/Vector/Vector4Node.cs
-
189MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MasterNode.cs
-
14MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/PropertyNode.cs
-
124MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapGraph.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/MaterialSubGraphAsset.cs
-
106MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraph.cs
-
302MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
-
2MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphOutputNode.cs
-
8MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyCollector.cs
-
263MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporter.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporter.cs.meta
-
41MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporterEditor.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Importers/MasterRemapGraphImporterEditor.cs.meta
-
10MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/IMasterNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/IMasterNode.cs.meta
-
15MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapGraphAsset.cs
-
65MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraph.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraph.cs.meta
-
229MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/AbstractSubGraphNode.cs.meta
-
98MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/MasterRemapNode.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/MasterRemapNode.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphInputNodeInspector.cs.meta
-
85MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors/SubgraphInputNodeInspector.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapInputNode.cs.meta
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/RemapMasterNode.cs.meta
-
93MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapInputNode.cs
-
22MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MaterialRemapAsset.cs
-
140MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/RemapMasterNode.cs
-
12MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs.meta
-
80MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphInputNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Remapper/MasterRemapGraphAsset.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
/* [Serializable] |
|||
class RemapMasterControlPresenter : GraphControlPresenter |
|||
{ |
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
[Serializable] |
|||
class RemapContolPresenter : GraphControlPresenter |
|||
{ |
|||
public override void OnGUIHandler() |
|||
{ |
|||
base.OnGUIHandler(); |
|||
var remapNode = node as RemapMasterNode; |
|||
if (remapNode == null) |
|||
return; |
|||
var remapNode = node as MasterRemapNode; |
|||
if (remapNode == null) |
|||
return; |
|||
remapNode.remapAsset = (MaterialRemapAsset)EditorGUILayout.MiniThumbnailObjectField( |
|||
new GUIContent("Remap Asset"), |
|||
remapNode.remapAsset, |
|||
typeof(MaterialRemapAsset), null); |
|||
} |
|||
remapNode.remapGraphAsset = (MasterRemapGraphAsset)EditorGUILayout.MiniThumbnailObjectField( |
|||
new GUIContent("Remap"), |
|||
remapNode.remapGraphAsset, |
|||
typeof(MasterRemapGraphAsset), null); |
|||
} |
|||
public override float GetHeight() |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
public override float GetHeight() |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; |
|||
} |
|||
} |
|||
[Serializable] |
|||
public class RemapMasterNodePresenter : MasterNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphControlPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<RemapMasterControlPresenter>(); |
|||
instance.Initialize(node); |
|||
var controls = new List<GraphControlPresenter>(base.GetControlData()); |
|||
controls.Add(instance); |
|||
return controls; |
|||
} |
|||
}*/ |
|||
[Serializable] |
|||
public class MasterRemapNodePresenter : MaterialNodePresenter |
|||
{ |
|||
protected override IEnumerable<GraphControlPresenter> GetControlData() |
|||
{ |
|||
var instance = CreateInstance<RemapContolPresenter>(); |
|||
instance.Initialize(node); |
|||
return new List<GraphControlPresenter> { instance }; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e8dfdb83d3043c7499b6cd1edd7b8f8d |
|||
timeCreated: 1503169600 |
|||
licenseType: Pro |
|||
ScriptedImporter: |
|||
userData: |
|||
assetBundleName: |
|
|||
using System.IO; |
|||
using System.Text; |
|||
using UnityEditor.Experimental.AssetImporters; |
|||
using UnityEngine; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
[ScriptedImporter(1, "ShaderRemapGraph")] |
|||
public class MasterRemapGraphImporter : ScriptedImporter |
|||
{ |
|||
public override void OnImportAsset(AssetImportContext ctx) |
|||
{ |
|||
var textGraph = File.ReadAllText(ctx.assetPath, Encoding.UTF8); |
|||
var graph = JsonUtility.FromJson<MasterRemapGraph>(textGraph); |
|||
|
|||
if (graph == null) |
|||
return; |
|||
|
|||
var graphAsset = ScriptableObject.CreateInstance<MasterRemapGraphAsset>(); |
|||
graphAsset.remapGraph = graph; |
|||
ctx.AddObjectToAsset("MainAsset", graphAsset); |
|||
ctx.SetMainObject(graphAsset); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 47e38a0256e24cec8792d9cfae7023b2 |
|||
timeCreated: 1506845544 |
|
|||
using UnityEditor; |
|||
using UnityEditor.Experimental.AssetImporters; |
|||
using UnityEditor.MaterialGraph.Drawing; |
|||
using UnityEngine; |
|||
using Debug = System.Diagnostics.Debug; |
|||
|
|||
[CustomEditor(typeof(MasterRemapGraphImporter))] |
|||
public class MasterRemapGraphImporterEditor : ScriptedImporterEditor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
if (GUILayout.Button("Open Shader Editor")) |
|||
{ |
|||
AssetImporter importer = target as AssetImporter; |
|||
Debug.Assert(importer != null, "importer != null"); |
|||
ShowGraphEditWindow(importer.assetPath); |
|||
} |
|||
} |
|||
|
|||
private static void ShowGraphEditWindow(string path) |
|||
{ |
|||
var asset = AssetDatabase.LoadAssetAtPath<Object>(path); |
|||
var windows = Resources.FindObjectsOfTypeAll<MasterReampGraphEditWindow>(); |
|||
bool foundWindow = false; |
|||
foreach (var w in windows) |
|||
{ |
|||
if (w.selected == asset) |
|||
{ |
|||
foundWindow = true; |
|||
w.Focus(); |
|||
} |
|||
} |
|||
|
|||
if (!foundWindow) |
|||
{ |
|||
var window = CreateInstance<MasterReampGraphEditWindow>(); |
|||
window.Show(); |
|||
window.ChangeSelection(asset); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4dd321ee05034e7a967503617a02c1f4 |
|||
timeCreated: 1506845783 |
|
|||
using System.Collections.Generic; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public interface IMasterNode |
|||
{ |
|||
SurfaceMaterialOptions options { get; } |
|||
IEnumerable<string> GetSubshader(ShaderGraphRequirements graphRequirements, MasterRemapGraph remapper); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 570cf3dfbfc001e46a74d5f1342a3cfc |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public class MasterRemapGraphAsset : ScriptableObject |
|||
{ |
|||
[SerializeField] |
|||
private MasterRemapGraph m_RemapGraph = new MasterRemapGraph(); |
|||
|
|||
public MasterRemapGraph remapGraph |
|||
{ |
|||
get { return m_RemapGraph; } |
|||
set { m_RemapGraph = value; } |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Serializable] |
|||
public class AbstractSubGraph : AbstractMaterialGraph |
|||
, IGeneratesBodyCode |
|||
, IGeneratesFunction |
|||
{ |
|||
public virtual IEnumerable<AbstractMaterialNode> activeNodes { get; } |
|||
|
|||
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(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
foreach (var node in activeNodes) |
|||
{ |
|||
if (node is IGeneratesFunction) |
|||
(node as IGeneratesFunction).GenerateNodeFunction(visitor, 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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f2b67435729448498da7e7b90f052ebd |
|||
timeCreated: 1506844687 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public abstract class AbstractSubGraphNode : AbstractMaterialNode |
|||
, IGeneratesFunction |
|||
, IOnAssetEnabled |
|||
, IMayRequireNormal |
|||
, IMayRequireTangent |
|||
, IMayRequireBitangent |
|||
, IMayRequireMeshUV |
|||
, IMayRequireScreenPosition |
|||
, IMayRequireViewDirection |
|||
, IMayRequirePosition |
|||
, IMayRequireVertexColor |
|||
, IMayRequireTime |
|||
{ |
|||
|
|||
protected virtual 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; } = null; |
|||
|
|||
public virtual void OnEnable() |
|||
{ |
|||
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.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(); |
|||
AddSlot(new MaterialSlot(id, prop.displayName, prop.referenceName, SlotType.Input, slotType, prop.defaultValue)); |
|||
validNames.Add(id); |
|||
} |
|||
|
|||
var subGraphOutputNode = outputNode; |
|||
if (outputNode != null) |
|||
{ |
|||
foreach (var slot in subGraphOutputNode.GetInputSlots<MaterialSlot>()) |
|||
{ |
|||
AddSlot(new MaterialSlot(slot.id, slot.displayName, slot.shaderOutputName, SlotType.Output, slot.valueType, slot.defaultValue)); |
|||
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(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
if (referencedGraph == null) |
|||
return; |
|||
|
|||
referencedGraph.GenerateNodeFunction(visitor, 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()); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bc4cf774a7a6480ba543eb6069cd1c50 |
|||
timeCreated: 1506847426 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Master/Remap-Node")] |
|||
public class MasterRemapNode : AbstractSubGraphNode, IMasterNode |
|||
{ |
|||
[SerializeField] |
|||
protected SurfaceMaterialOptions m_MaterialOptions = new SurfaceMaterialOptions(); |
|||
|
|||
public SurfaceMaterialOptions options |
|||
{ |
|||
get { return m_MaterialOptions; } |
|||
} |
|||
|
|||
public virtual PreviewMode previewMode |
|||
{ |
|||
get { return PreviewMode.Preview3D; } |
|||
} |
|||
|
|||
[SerializeField] |
|||
private string m_SerializedRemapGraph = string.Empty; |
|||
|
|||
[Serializable] |
|||
private class RemapGraphHelper |
|||
{ |
|||
public MasterRemapGraphAsset remapGraph; |
|||
} |
|||
|
|||
protected override AbstractSubGraph referencedGraph |
|||
{ |
|||
get |
|||
{ |
|||
if (remapGraphAsset == null) |
|||
return null; |
|||
|
|||
return remapGraphAsset.remapGraph; |
|||
} |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public MasterRemapGraphAsset remapGraphAsset |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerializedRemapGraph)) |
|||
return null; |
|||
|
|||
var helper = new RemapGraphHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerializedRemapGraph, helper); |
|||
return helper.remapGraph; |
|||
} |
|||
set |
|||
{ |
|||
if (remapGraphAsset == value) |
|||
return; |
|||
|
|||
var helper = new RemapGraphHelper(); |
|||
helper.remapGraph = value; |
|||
m_SerializedRemapGraph = EditorJsonUtility.ToJson(helper, true); |
|||
OnEnable(); |
|||
|
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Topological); |
|||
} |
|||
} |
|||
#else
|
|||
public MaterialSubGraphAsset subGraphAsset {get; set; } |
|||
#endif
|
|||
|
|||
public MasterRemapNode() |
|||
{ |
|||
name = "RemapMaster"; |
|||
} |
|||
|
|||
public IEnumerable<string> GetSubshader(ShaderGraphRequirements graphRequirements, MasterRemapGraph remapper) |
|||
{ |
|||
|
|||
if (referencedGraph == null) |
|||
return new string[]{}; |
|||
|
|||
var masterNodes = referencedGraph.activeNodes.OfType<IMasterNode>().ToList(); |
|||
|
|||
if (masterNodes.Count == 0) |
|||
return new string[]{}; |
|||
|
|||
var results = new List<string>(); |
|||
foreach (var master in masterNodes) |
|||
results.AddRange(master.GetSubshader(graphRequirements, referencedGraph as MasterRemapGraph)); |
|||
|
|||
return results; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 861139fc6f60415cae2eb9a9625aaeb8 |
|||
timeCreated: 1506873607 |
|
|||
fileFormatVersion: 2 |
|||
guid: cd0ffd0e21a6644488dda4d0470a30c6 |
|||
timeCreated: 1483808306 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Linq; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing |
|||
{ |
|||
public class SubgraphInputNodeInspector : BasicNodeInspector |
|||
{ |
|||
protected enum UISlotValueType |
|||
{ |
|||
Vector4, |
|||
Vector3, |
|||
Vector2, |
|||
Vector1 |
|||
} |
|||
|
|||
private static UISlotValueType ToUISlot(SlotValueType slot) |
|||
{ |
|||
switch (slot) |
|||
{ |
|||
case SlotValueType.Vector1: |
|||
return UISlotValueType.Vector1; |
|||
case SlotValueType.Vector2: |
|||
return UISlotValueType.Vector2; |
|||
case SlotValueType.Vector3: |
|||
return UISlotValueType.Vector3; |
|||
case SlotValueType.Vector4: |
|||
return UISlotValueType.Vector4; |
|||
} |
|||
return UISlotValueType.Vector4; |
|||
} |
|||
|
|||
private static SlotValueType ToSlotValueType(UISlotValueType slot) |
|||
{ |
|||
switch (slot) |
|||
{ |
|||
case UISlotValueType.Vector1: |
|||
return SlotValueType.Vector1; |
|||
case UISlotValueType.Vector2: |
|||
return SlotValueType.Vector2; |
|||
case UISlotValueType.Vector3: |
|||
return SlotValueType.Vector3; |
|||
case UISlotValueType.Vector4: |
|||
return SlotValueType.Vector4; |
|||
} |
|||
return SlotValueType.Vector4; |
|||
} |
|||
|
|||
protected override ModificationScope DoSlotsUI() |
|||
{ |
|||
var slots = node.GetSlots<MaterialSlot>(); |
|||
if (!slots.Any()) |
|||
return ModificationScope.Node; |
|||
|
|||
GUILayout.Label("Default Slot Values", EditorStyles.boldLabel); |
|||
|
|||
bool valueChanged = false; |
|||
bool typeChanged = false; |
|||
foreach (var slot in node.GetSlots<MaterialSlot>()) |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
GUILayout.Label(slot.displayName); |
|||
slot.currentValue = EditorGUILayout.Vector4Field("", slot.currentValue); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
valueChanged |= true; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
var result = (UISlotValueType)EditorGUILayout.EnumPopup(ToUISlot(slot.valueType)); |
|||
slot.valueType = ToSlotValueType(result); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
typeChanged |= true; |
|||
} |
|||
|
|||
GUILayout.Space(10); |
|||
|
|||
if (typeChanged) |
|||
return ModificationScope.Topological; |
|||
if (valueChanged) |
|||
return ModificationScope.Node; |
|||
|
|||
return ModificationScope.Node; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 39465109a68463a4b8a1a9c9dd20e46a |
|||
timeCreated: 1481188026 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 8f94baf06fa91ad41bc0184e6d14cb0f |
|||
timeCreated: 1481188026 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
/* |
|||
[Title("Remapper/Remap Input Node")] |
|||
public class MasterRemapInputNode : AbstractSubGraphIONode |
|||
, INodeGroupRemapper |
|||
{ |
|||
[NonSerialized] |
|||
internal RemapMasterNode m_RemapTarget; |
|||
|
|||
public MasterRemapInputNode() |
|||
{ |
|||
name = "Inputs"; |
|||
} |
|||
|
|||
public override int AddSlot() |
|||
{ |
|||
var nextSlotId = GetOutputSlots<ISlot>().Count() + 1; |
|||
AddSlot(new MaterialSlot(-nextSlotId, "Input " + nextSlotId, "Input" + nextSlotId, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
return -nextSlotId; |
|||
} |
|||
|
|||
public override void RemoveSlot() |
|||
{ |
|||
var lastSlotId = GetOutputSlots<ISlot>().Count(); |
|||
if (lastSlotId == 0) |
|||
return; |
|||
|
|||
RemoveSlot(-lastSlotId); |
|||
} |
|||
|
|||
public void DepthFirstCollectNodesFromNodeSlotList(List<INode> nodeList, NodeUtils.IncludeSelf includeSelf) |
|||
{ |
|||
NodeUtils.DepthFirstCollectNodesFromNode(nodeList, m_RemapTarget, NodeUtils.IncludeSelf.Exclude); |
|||
} |
|||
|
|||
public bool IsValidSlotConnection(int slotId) |
|||
{ |
|||
if (m_RemapTarget == null) |
|||
return false; |
|||
|
|||
var slot = m_RemapTarget.FindSlot<MaterialSlot>(slotId); |
|||
if (slot == null) |
|||
return false; |
|||
|
|||
var edge = m_RemapTarget.owner.GetEdges(slot.slotReference).FirstOrDefault(); |
|||
if (edge == null) |
|||
return false; |
|||
|
|||
var outputRef = edge.outputSlot; |
|||
var fromNode = m_RemapTarget.owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid); |
|||
if (fromNode == null) |
|||
return false; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
public override string GetVariableNameForSlot(int slotId) |
|||
{ |
|||
if (m_RemapTarget == null) |
|||
{ |
|||
var defaultValueSlot = FindSlot<MaterialSlot>(slotId); |
|||
if (defaultValueSlot == null) |
|||
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId"); |
|||
|
|||
return defaultValueSlot.GetDefaultValue(GenerationMode.ForReals); |
|||
} |
|||
|
|||
var slot = m_RemapTarget.FindSlot<MaterialSlot>(slotId); |
|||
if (slot == null) |
|||
throw new ArgumentException(string.Format("Attempting to use MaterialSlot({0}) on node of type {1} where this slot can not be found", slotId, this), "slotId"); |
|||
|
|||
if (slot.isOutputSlot) |
|||
throw new Exception(string.Format("Attempting to use OutputSlot({0}) on remap node)", slotId)); |
|||
|
|||
var edge = m_RemapTarget.owner.GetEdges(slot.slotReference).FirstOrDefault(); |
|||
if (edge == null) |
|||
return slot.GetDefaultValue(GenerationMode.ForReals); |
|||
|
|||
var outputRef = edge.outputSlot; |
|||
var fromNode = m_RemapTarget.owner.GetNodeFromGuid<AbstractMaterialNode>(outputRef.nodeGuid); |
|||
if (fromNode == null) |
|||
return slot.GetDefaultValue(GenerationMode.ForReals); |
|||
|
|||
return fromNode.GetVariableNameForSlot(outputRef.slotId); |
|||
} |
|||
}*/ |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
/* public class MaterialRemapAsset : AbstractMaterialGraphAsset |
|||
{ |
|||
[SerializeField] |
|||
private MasterRemapGraph m_MasterRemapGraph = new MasterRemapGraph(); |
|||
|
|||
public override IGraph graph |
|||
{ |
|||
get { return m_MasterRemapGraph; } |
|||
} |
|||
|
|||
public MasterRemapGraph masterRemapGraph |
|||
{ |
|||
get { return m_MasterRemapGraph; } |
|||
} |
|||
}*/ |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text.RegularExpressions; |
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
/* [Serializable] |
|||
[Title("Master/Remapper")] |
|||
public class RemapMasterNode : AbstractMasterNode |
|||
, IOnAssetEnabled |
|||
{ |
|||
[SerializeField] |
|||
private string m_SerialziedRemapGraph = string.Empty; |
|||
|
|||
[Serializable] |
|||
private class RemapGraphHelper |
|||
{ |
|||
public MaterialRemapAsset subGraph; |
|||
} |
|||
|
|||
public override bool allowedInRemapGraph |
|||
{ |
|||
get { return false; } |
|||
} |
|||
|
|||
public override string GetFullShader(GenerationMode mode, string name, out List<PropertyGenerator.TextureInfo> configuredTextures) |
|||
{ |
|||
var shaderTemplateLocation = ShaderGenerator.GetTemplatePath("shader.template"); |
|||
|
|||
if (remapAsset == null || !File.Exists(shaderTemplateLocation)) |
|||
{ |
|||
configuredTextures = new List<PropertyGenerator.TextureInfo>(); |
|||
return string.Empty; |
|||
} |
|||
|
|||
var shaderPropertiesVisitor = new PropertyGenerator(); |
|||
|
|||
// Step 1: Set this node as the remap target
|
|||
// Pass in the shader properties visitor here as
|
|||
// high level properties are shared
|
|||
// this is only used for the header
|
|||
var subShaders = remapAsset.masterRemapGraph.GetSubShadersFor(this, mode, shaderPropertiesVisitor); |
|||
|
|||
var templateText = File.ReadAllText(shaderTemplateLocation); |
|||
var resultShader = templateText.Replace("${ShaderName}", name); |
|||
resultShader = resultShader.Replace("${ShaderPropertiesHeader}", shaderPropertiesVisitor.GetShaderString(2)); |
|||
if (subShaders != null) |
|||
resultShader = resultShader.Replace("${SubShader}", subShaders.Aggregate(string.Empty, (i, j) => i + Environment.NewLine + j)); |
|||
else |
|||
resultShader = resultShader.Replace("${SubShader}", string.Empty); |
|||
|
|||
configuredTextures = shaderPropertiesVisitor.GetConfiguredTexutres(); |
|||
return Regex.Replace(resultShader, @"\r\n|\n\r|\n|\r", Environment.NewLine); |
|||
} |
|||
|
|||
public override string GetSubShader(GenerationMode mode, PropertyGenerator shaderPropertiesVisitor) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
base.CollectPreviewMaterialProperties(properties); |
|||
if (remapAsset == null) |
|||
return; |
|||
|
|||
remapAsset.masterRemapGraph.CollectPreviewMaterialProperties(properties); |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public MaterialRemapAsset remapAsset |
|||
{ |
|||
get |
|||
{ |
|||
if (string.IsNullOrEmpty(m_SerialziedRemapGraph)) |
|||
return null; |
|||
|
|||
var helper = new RemapGraphHelper(); |
|||
EditorJsonUtility.FromJsonOverwrite(m_SerialziedRemapGraph, helper); |
|||
return helper.subGraph; |
|||
} |
|||
set |
|||
{ |
|||
if (remapAsset == value) |
|||
return; |
|||
|
|||
var helper = new RemapGraphHelper(); |
|||
helper.subGraph = value; |
|||
m_SerialziedRemapGraph = EditorJsonUtility.ToJson(helper, true); |
|||
OnEnable(); |
|||
|
|||
if (onModified != null) |
|||
onModified(this, ModificationScope.Topological); |
|||
} |
|||
} |
|||
#else
|
|||
public MaterialSubGraphAsset subGraphAsset {get; set; } |
|||
#endif
|
|||
|
|||
public override PreviewMode previewMode |
|||
{ |
|||
get |
|||
{ |
|||
if (remapAsset == null) |
|||
return PreviewMode.Preview2D; |
|||
|
|||
return PreviewMode.Preview3D; |
|||
} |
|||
} |
|||
|
|||
public RemapMasterNode() |
|||
{ |
|||
name = "Remapper"; |
|||
} |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
var validNames = new List<int>(); |
|||
if (remapAsset == null) |
|||
{ |
|||
RemoveSlotsNameNotMatching(validNames); |
|||
return; |
|||
} |
|||
|
|||
var inputNode = remapAsset.masterRemapGraph.inputNode; |
|||
foreach (var slot in inputNode.GetOutputSlots<MaterialSlot>()) |
|||
{ |
|||
AddSlot(new MaterialSlot(slot.id, slot.displayName, slot.shaderOutputName, SlotType.Input, slot.valueType, slot.defaultValue)); |
|||
validNames.Add(slot.id); |
|||
} |
|||
RemoveSlotsNameNotMatching(validNames); |
|||
} |
|||
}*/ |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: efdb88070ae74e94a9ed2f6ac04e6862 |
|||
timeCreated: 1465559219 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
public class SubGraphInputNode : AbstractSubGraphIONode |
|||
{ |
|||
public SubGraphInputNode() |
|||
{ |
|||
name = "SubGraphInputs"; |
|||
} |
|||
|
|||
public override int AddSlot() |
|||
{ |
|||
var nextSlotId = GetOutputSlots<ISlot>().Count() + 1; |
|||
AddSlot(new MaterialSlot(-nextSlotId, "Input " + nextSlotId, "Input" + nextSlotId, SlotType.Output, SlotValueType.Vector4, Vector4.zero)); |
|||
return -nextSlotId; |
|||
} |
|||
|
|||
public override void RemoveSlot() |
|||
{ |
|||
var lastSlotId = GetOutputSlots<ISlot>().Count(); |
|||
if (lastSlotId == 0) |
|||
return; |
|||
|
|||
RemoveSlot(-lastSlotId); |
|||
} |
|||
|
|||
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) |
|||
{ |
|||
if (!generationMode.IsPreview()) |
|||
return; |
|||
|
|||
foreach (var slot in GetOutputSlots<MaterialSlot>()) |
|||
{ |
|||
IShaderProperty property; |
|||
switch (slot.concreteValueType) |
|||
{ |
|||
case ConcreteSlotValueType.Vector4: |
|||
property = new Vector4ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector3: |
|||
property = new Vector3ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector2: |
|||
property = new Vector2ShaderProperty(); |
|||
break; |
|||
case ConcreteSlotValueType.Vector1: |
|||
property = new FloatShaderProperty(); |
|||
break; |
|||
default: |
|||
throw new ArgumentOutOfRangeException(); |
|||
} |
|||
property.generatePropertyBlock = false; |
|||
properties.AddShaderProperty(property); |
|||
} |
|||
} |
|||
|
|||
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) |
|||
{ |
|||
base.CollectPreviewMaterialProperties(properties); |
|||
foreach (var s in GetOutputSlots<MaterialSlot>()) |
|||
{ |
|||
properties.Add |
|||
( |
|||
new PreviewProperty |
|||
{ |
|||
m_Name = GetVariableNameForSlot(s.id), |
|||
m_PropType = ConvertConcreteSlotValueTypeToPropertyType(s.concreteValueType), |
|||
m_Vector4 = s.currentValue, |
|||
m_Float = s.currentValue.x, |
|||
m_Color = s.currentValue |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue