initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,10 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unity.ShaderGraph.Editor.Tests")]
|
||||
[assembly: InternalsVisibleTo("Unity.RenderPipelines.Universal.Editor")]
|
||||
[assembly: InternalsVisibleTo("Unity.ShaderGraph.GraphicsTests")]
|
||||
[assembly: InternalsVisibleTo("Unity.ShaderGraph.Editor.GraphicsTests")]
|
||||
[assembly: InternalsVisibleTo("Unity.RenderPipelines.HighDefinition.Editor")]
|
||||
[assembly: InternalsVisibleTo("Unity.VisualEffectGraph.Editor")]
|
||||
[assembly: InternalsVisibleTo("Unity.Industrial.Materials.AVRD.Editor")]
|
||||
[assembly: InternalsVisibleTo("Unity.VisualEffectGraph.EditorTests")]
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d15809863a4410e409c1b23c81a2e5f4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d0b60652dca71b49a137663137e38ea
|
||||
folderAsset: yes
|
||||
timeCreated: 1464264920
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
static class CreateShaderGraph
|
||||
{
|
||||
[MenuItem("Assets/Create/Shader Graph/Blank Shader Graph", priority = CoreUtils.Sections.section1 + CoreUtils.Priorities.assetsCreateShaderMenuPriority)]
|
||||
public static void CreateBlankShaderGraph()
|
||||
{
|
||||
GraphUtil.CreateNewGraph();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 14e8f865381f1714ab38debdb40a5989
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,28 @@
|
|||
using System.IO;
|
||||
using UnityEditor.ProjectWindowCallback;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
class CreateShaderSubGraph : EndNameEditAction
|
||||
{
|
||||
[MenuItem("Assets/Create/Shader Graph/Sub Graph", priority = CoreUtils.Sections.section1 + CoreUtils.Priorities.assetsCreateShaderMenuPriority + 1)]
|
||||
public static void CreateMaterialSubGraph()
|
||||
{
|
||||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateShaderSubGraph>(),
|
||||
string.Format("New Shader Sub Graph.{0}", ShaderSubGraphImporter.Extension), null, null);
|
||||
}
|
||||
|
||||
public override void Action(int instanceId, string pathName, string resourceFile)
|
||||
{
|
||||
var graph = new GraphData { isSubGraph = true };
|
||||
var outputNode = new SubGraphOutputNode();
|
||||
graph.AddNode(outputNode);
|
||||
graph.outputNode = outputNode;
|
||||
outputNode.AddSlot(ConcreteSlotValueType.Vector4);
|
||||
graph.path = "Sub Graphs";
|
||||
FileUtilities.WriteShaderGraphToDisk(pathName, graph);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: beb456cc86fd0ea4a9943f78665a8ec2
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -0,0 +1,25 @@
|
|||
#if VFX_GRAPH_10_0_0_OR_NEWER
|
||||
using System;
|
||||
using UnityEditor.ShaderGraph;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
static class CreateVFXShaderGraph
|
||||
{
|
||||
[MenuItem("Assets/Create/Shader Graph/VFX Shader Graph", priority = CoreUtils.Sections.section2 + CoreUtils.Priorities.assetsCreateShaderMenuPriority)]
|
||||
public static void CreateVFXGraph()
|
||||
{
|
||||
var target = (VFXTarget)Activator.CreateInstance(typeof(VFXTarget));
|
||||
|
||||
var blockDescriptors = new[]
|
||||
{
|
||||
BlockFields.SurfaceDescription.BaseColor,
|
||||
BlockFields.SurfaceDescription.Alpha,
|
||||
};
|
||||
|
||||
GraphUtil.CreateNewGraphWithOutputs(new[] {target}, blockDescriptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4aed1be68a7498d468a7ea49a3280138
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f56929b05da66c942ad2e3fe376346fa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9abbc5074e3b457c98f721847723bf2e
|
||||
timeCreated: 1614895611
|
|
@ -0,0 +1,173 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.ShaderGraph.Drawing;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEditor.ShaderGraph.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
class ConvertToPropertyAction : IGraphDataAction
|
||||
{
|
||||
void ConvertToProperty(GraphData graphData)
|
||||
{
|
||||
AssertHelpers.IsNotNull(graphData, "GraphData is null while carrying out ConvertToPropertyAction");
|
||||
AssertHelpers.IsNotNull(inlinePropertiesToConvert, "InlinePropertiesToConvert is null while carrying out ConvertToPropertyAction");
|
||||
graphData.owner.RegisterCompleteObjectUndo("Convert to Property");
|
||||
|
||||
var defaultCategory = graphData.categories.FirstOrDefault();
|
||||
AssertHelpers.IsNotNull(defaultCategory, "Default Category is null while carrying out ConvertToPropertyAction");
|
||||
|
||||
foreach (var converter in inlinePropertiesToConvert)
|
||||
{
|
||||
var convertedProperty = converter.AsShaderProperty();
|
||||
var node = converter as AbstractMaterialNode;
|
||||
|
||||
graphData.AddGraphInput(convertedProperty);
|
||||
|
||||
// Also insert this input into the default category
|
||||
if (defaultCategory != null)
|
||||
{
|
||||
var addItemToCategoryAction = new AddItemToCategoryAction();
|
||||
addItemToCategoryAction.categoryGuid = defaultCategory.categoryGuid;
|
||||
addItemToCategoryAction.itemToAdd = convertedProperty;
|
||||
graphData.owner.graphDataStore.Dispatch(addItemToCategoryAction);
|
||||
}
|
||||
|
||||
// Add reference to converted property for use in responding to this action later
|
||||
convertedPropertyReferences.Add(convertedProperty);
|
||||
|
||||
var propNode = new PropertyNode();
|
||||
propNode.drawState = node.drawState;
|
||||
propNode.group = node.group;
|
||||
graphData.AddNode(propNode);
|
||||
propNode.property = convertedProperty;
|
||||
|
||||
var oldSlot = node.FindSlot<MaterialSlot>(converter.outputSlotId);
|
||||
var newSlot = propNode.FindSlot<MaterialSlot>(PropertyNode.OutputSlotId);
|
||||
|
||||
foreach (var edge in graphData.GetEdges(oldSlot.slotReference))
|
||||
graphData.Connect(newSlot.slotReference, edge.inputSlot);
|
||||
|
||||
graphData.RemoveNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
public Action<GraphData> modifyGraphDataAction => ConvertToProperty;
|
||||
|
||||
public IList<IPropertyFromNode> inlinePropertiesToConvert { get; set; } = new List<IPropertyFromNode>();
|
||||
|
||||
public IList<AbstractShaderProperty> convertedPropertyReferences { get; set; } = new List<AbstractShaderProperty>();
|
||||
|
||||
public Vector2 nodePsition { get; set; }
|
||||
}
|
||||
|
||||
class ConvertToInlineAction : IGraphDataAction
|
||||
{
|
||||
void ConvertToInline(GraphData graphData)
|
||||
{
|
||||
AssertHelpers.IsNotNull(graphData, "GraphData is null while carrying out ConvertToInlineAction");
|
||||
AssertHelpers.IsNotNull(propertyNodesToConvert, "PropertyNodesToConvert is null while carrying out ConvertToInlineAction");
|
||||
graphData.owner.RegisterCompleteObjectUndo("Convert to Inline Node");
|
||||
|
||||
foreach (var propertyNode in propertyNodesToConvert)
|
||||
graphData.ReplacePropertyNodeWithConcreteNode(propertyNode);
|
||||
}
|
||||
|
||||
public Action<GraphData> modifyGraphDataAction => ConvertToInline;
|
||||
|
||||
public IEnumerable<PropertyNode> propertyNodesToConvert { get; set; } = new List<PropertyNode>();
|
||||
}
|
||||
|
||||
class DragGraphInputAction : IGraphDataAction
|
||||
{
|
||||
void DragGraphInput(GraphData graphData)
|
||||
{
|
||||
AssertHelpers.IsNotNull(graphData, "GraphData is null while carrying out DragGraphInputAction");
|
||||
AssertHelpers.IsNotNull(graphInputBeingDraggedIn, "GraphInputBeingDraggedIn is null while carrying out DragGraphInputAction");
|
||||
graphData.owner.RegisterCompleteObjectUndo("Drag Graph Input");
|
||||
|
||||
switch (graphInputBeingDraggedIn)
|
||||
{
|
||||
case AbstractShaderProperty property:
|
||||
{
|
||||
if (property is MultiJsonInternal.UnknownShaderPropertyType)
|
||||
break;
|
||||
|
||||
// This could be from another graph, in which case we add a copy of the ShaderInput to this graph.
|
||||
if (graphData.properties.FirstOrDefault(p => p == property) == null)
|
||||
{
|
||||
var copyShaderInputAction = new CopyShaderInputAction();
|
||||
copyShaderInputAction.shaderInputToCopy = property;
|
||||
graphData.owner.graphDataStore.Dispatch(copyShaderInputAction);
|
||||
property = (AbstractShaderProperty)copyShaderInputAction.copiedShaderInput;
|
||||
}
|
||||
|
||||
var node = new PropertyNode();
|
||||
var drawState = node.drawState;
|
||||
drawState.position = new Rect(nodePosition, drawState.position.size);
|
||||
node.drawState = drawState;
|
||||
graphData.AddNode(node);
|
||||
|
||||
// Setting the guid requires the graph to be set first.
|
||||
node.property = property;
|
||||
break;
|
||||
}
|
||||
case ShaderKeyword keyword:
|
||||
{
|
||||
// This could be from another graph, in which case we add a copy of the ShaderInput to this graph.
|
||||
if (graphData.keywords.FirstOrDefault(k => k == keyword) == null)
|
||||
{
|
||||
var copyShaderInputAction = new CopyShaderInputAction();
|
||||
copyShaderInputAction.shaderInputToCopy = keyword;
|
||||
graphData.owner.graphDataStore.Dispatch(copyShaderInputAction);
|
||||
keyword = (ShaderKeyword)copyShaderInputAction.copiedShaderInput;
|
||||
}
|
||||
|
||||
var node = new KeywordNode();
|
||||
var drawState = node.drawState;
|
||||
drawState.position = new Rect(nodePosition, drawState.position.size);
|
||||
node.drawState = drawState;
|
||||
graphData.AddNode(node);
|
||||
|
||||
// Setting the guid requires the graph to be set first.
|
||||
node.keyword = keyword;
|
||||
break;
|
||||
}
|
||||
case ShaderDropdown dropdown:
|
||||
{
|
||||
if (graphData.IsInputAllowedInGraph(dropdown))
|
||||
{
|
||||
// This could be from another graph, in which case we add a copy of the ShaderInput to this graph.
|
||||
if (graphData.dropdowns.FirstOrDefault(d => d == dropdown) == null)
|
||||
{
|
||||
var copyShaderInputAction = new CopyShaderInputAction();
|
||||
copyShaderInputAction.shaderInputToCopy = dropdown;
|
||||
graphData.owner.graphDataStore.Dispatch(copyShaderInputAction);
|
||||
dropdown = (ShaderDropdown)copyShaderInputAction.copiedShaderInput;
|
||||
}
|
||||
|
||||
var node = new DropdownNode();
|
||||
var drawState = node.drawState;
|
||||
drawState.position = new Rect(nodePosition, drawState.position.size);
|
||||
node.drawState = drawState;
|
||||
graphData.AddNode(node);
|
||||
|
||||
// Setting the guid requires the graph to be set first.
|
||||
node.dropdown = dropdown;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
public Action<GraphData> modifyGraphDataAction => DragGraphInput;
|
||||
|
||||
public ShaderInput graphInputBeingDraggedIn { get; set; }
|
||||
|
||||
public Vector2 nodePosition { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c23c319581174ecdbc4573a81ed6b598
|
||||
timeCreated: 1614895651
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 08871a332c049d44d9bf2563943a52c0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
class BuiltinKeywordAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9c9d769f1b8c48746bca5318ac6d2dfb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
|
||||
internal abstract class ContextFilterableAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e74ce62c866dd564fb6420aabd9beacf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class InspectableAttribute : Attribute
|
||||
{
|
||||
// String value to use in the Property name TextLabel
|
||||
public string labelName { get; private set; }
|
||||
|
||||
// The default value of this property
|
||||
public object defaultValue { get; private set; }
|
||||
|
||||
// String value to supply if you wish to use a custom style when drawing this property
|
||||
public string customStyleName { get; private set; }
|
||||
|
||||
public InspectableAttribute(string labelName, object defaultValue, string customStyleName = "")
|
||||
{
|
||||
this.labelName = labelName;
|
||||
this.defaultValue = defaultValue;
|
||||
this.customStyleName = customStyleName;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 135160e3cb114b679f9d5363c349b289
|
||||
timeCreated: 1587157677
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
||||
internal class NeverAllowedByTargetAttribute : ContextFilterableAttribute
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c583d077fd8e8e479fe6e4e74df4bee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Drawing
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class SGPropertyDrawerAttribute : Attribute
|
||||
{
|
||||
public Type propertyType { get; private set; }
|
||||
|
||||
public SGPropertyDrawerAttribute(Type propertyType)
|
||||
{
|
||||
this.propertyType = propertyType;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 291f21a1598748ba8fe53ab69eb10b5e
|
||||
timeCreated: 1588090538
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[GenerationAPI]
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
||||
internal class SRPFilterAttribute : ContextFilterableAttribute
|
||||
{
|
||||
public Type[] srpTypes = null;
|
||||
public SRPFilterAttribute(params Type[] WorksWithSRP)
|
||||
{
|
||||
srpTypes = WorksWithSRP;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9bdc66ff87a9fb141b0cb9e8aa3ae0bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[GenerationAPI]
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
||||
internal class SubTargetFilterAttribute : ContextFilterableAttribute
|
||||
{
|
||||
public Type[] subTargetTypes = null;
|
||||
public SubTargetFilterAttribute(params Type[] WorksWithSubTargets)
|
||||
{
|
||||
subTargetTypes = WorksWithSubTargets;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d2c11681665d4bbdbfb8e733b901fde5
|
||||
timeCreated: 1615524028
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEditor.ShaderGraph.Serialization;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
sealed class ContextData
|
||||
{
|
||||
[SerializeField]
|
||||
Vector2 m_Position;
|
||||
|
||||
[SerializeField]
|
||||
List<JsonRef<BlockNode>> m_Blocks = new List<JsonRef<BlockNode>>();
|
||||
|
||||
[NonSerialized]
|
||||
ShaderStage m_ShaderStage;
|
||||
|
||||
public ContextData()
|
||||
{
|
||||
}
|
||||
|
||||
public List<JsonRef<BlockNode>> blocks => m_Blocks;
|
||||
|
||||
public Vector2 position
|
||||
{
|
||||
get => m_Position;
|
||||
set => m_Position = value;
|
||||
}
|
||||
|
||||
public ShaderStage shaderStage
|
||||
{
|
||||
get => m_ShaderStage;
|
||||
set => m_ShaderStage = value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8dfa4982c4e3ac6429fc1c375d3ceea2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 55b9824914ca013428dfb7a5c38fc2de
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Internal
|
||||
{
|
||||
// ------------------------------------------------------------------------------------------
|
||||
//
|
||||
// The general use of precision follows this data flow
|
||||
//
|
||||
// Precision -- user selectable precision setting on each node
|
||||
// == apply precision inherit rules based on node inputs ==>
|
||||
// GraphPrecision -- where "GraphPrecision.Graph" means use the graph default setting
|
||||
// == fallback to graph defaults ==>
|
||||
// GraphPrecision -- where "GraphPrecision.Graph" means it is switchable when in a subgraph
|
||||
// == shadergraph concretization ==>
|
||||
// ConcretePrecision -- the actual precision used by the node, half or single
|
||||
//
|
||||
// We could at some point separate the two GraphPrecision uses into separate enums,
|
||||
// but they're close enough we're using one enum for both uses at the moment
|
||||
//
|
||||
// ------------------------------------------------------------------------------------------
|
||||
|
||||
// this is generally used for user-selectable precision
|
||||
[Serializable]
|
||||
enum Precision
|
||||
{
|
||||
Inherit, // automatically choose the precision based on the inputs
|
||||
Single, // force single precision (float)
|
||||
Half, // force half precision
|
||||
Graph, // use the graph default (for subgraphs this will properly switch based on the subgraph node setting)
|
||||
}
|
||||
|
||||
// this is used when calculating precision within a graph
|
||||
// it basically represents the precision after applying the automatic inheritance rules
|
||||
// but before applying the fallback to the graph default
|
||||
// tracking this explicitly helps us build subgraph switchable precision behavior (any node using Graph can be switched)
|
||||
public enum GraphPrecision
|
||||
{
|
||||
Single = 0, // the ordering is different here so we can use the min function to resolve inherit/automatic behavior
|
||||
Graph = 1,
|
||||
Half = 2
|
||||
}
|
||||
|
||||
// this is the actual set of precisions we have, a shadergraph must resolve every node to one of these
|
||||
// in subgraphs, this concrete precision is only used for preview, and may not represent the actual precision of those nodes
|
||||
// when used in a shader graph
|
||||
[Serializable]
|
||||
public enum ConcretePrecision
|
||||
{
|
||||
Single,
|
||||
Half,
|
||||
}
|
||||
|
||||
// inherit(auto) rules for combining input types
|
||||
|
||||
// half + half ==> half
|
||||
// single + single ==> single
|
||||
// single + half ==> single
|
||||
// single + graph ==> single
|
||||
// half + graph ==> graph
|
||||
// single + half + graph ==> single
|
||||
//
|
||||
// basically: take the min when arranged like so: single(0), graph(1), half(2)
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b0d282a8ab4ff6742a3ec739e59675ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f329b5b280b7f6f449659f05937ac2f2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,3 @@
|
|||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f69ae4bd132ba4c4990a5f2ec28e5932
|
||||
timeCreated: 1482920380
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,308 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Internal
|
||||
{
|
||||
[Serializable]
|
||||
public abstract class AbstractShaderProperty : ShaderInput
|
||||
{
|
||||
public abstract PropertyType propertyType { get; }
|
||||
|
||||
internal override ConcreteSlotValueType concreteShaderValueType => propertyType.ToConcreteShaderValueType();
|
||||
|
||||
// user selected precision setting
|
||||
[SerializeField]
|
||||
Precision m_Precision = Precision.Inherit;
|
||||
|
||||
[Obsolete("AbstractShaderProperty.gpuInstanced is no longer used")]
|
||||
public bool gpuInstanced
|
||||
{
|
||||
get { return false; }
|
||||
set { }
|
||||
}
|
||||
|
||||
internal virtual string GetHLSLVariableName(bool isSubgraphProperty, GenerationMode mode)
|
||||
{
|
||||
if (mode == GenerationMode.VFX)
|
||||
{
|
||||
// Per-element exposed properties are provided by the properties structure filled by VFX.
|
||||
if (overrideHLSLDeclaration)
|
||||
return $"PROP.{referenceName}";
|
||||
// For un-exposed global properties, just read from the cbuffer.
|
||||
else
|
||||
return referenceName;
|
||||
}
|
||||
|
||||
return referenceName;
|
||||
}
|
||||
|
||||
internal string GetConnectionStateHLSLVariableName()
|
||||
{
|
||||
return GetConnectionStateVariableName(referenceName + "_" + objectId);
|
||||
}
|
||||
|
||||
// NOTE: this does not tell you the HLSLDeclaration of the entire property...
|
||||
// instead, it tells you what the DEFAULT HLSL Declaration would be, IF the property makes use of the default
|
||||
// to check ACTUAL HLSL Declaration types, enumerate the HLSL Properties and check their HLSLDeclarations...
|
||||
internal virtual HLSLDeclaration GetDefaultHLSLDeclaration()
|
||||
{
|
||||
if (overrideHLSLDeclaration)
|
||||
return hlslDeclarationOverride;
|
||||
// default Behavior switches between UnityPerMaterial and Global based on Exposed checkbox
|
||||
if (generatePropertyBlock)
|
||||
return HLSLDeclaration.UnityPerMaterial;
|
||||
else
|
||||
return HLSLDeclaration.Global;
|
||||
}
|
||||
|
||||
// by default we disallow UI from choosing "DoNotDeclare"
|
||||
// it needs a bit more UI support to disable property node output slots before we make it public
|
||||
internal virtual bool AllowHLSLDeclaration(HLSLDeclaration decl) => (decl != HLSLDeclaration.DoNotDeclare);
|
||||
|
||||
[SerializeField]
|
||||
internal bool overrideHLSLDeclaration = false;
|
||||
|
||||
[SerializeField]
|
||||
internal HLSLDeclaration hlslDeclarationOverride;
|
||||
|
||||
internal Precision precision
|
||||
{
|
||||
get => m_Precision;
|
||||
set => m_Precision = value;
|
||||
}
|
||||
|
||||
ConcretePrecision m_ConcretePrecision = ConcretePrecision.Single;
|
||||
public ConcretePrecision concretePrecision => m_ConcretePrecision;
|
||||
internal void SetupConcretePrecision(ConcretePrecision defaultPrecision)
|
||||
{
|
||||
m_ConcretePrecision = precision.ToConcrete(defaultPrecision, defaultPrecision);
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool m_Hidden = false;
|
||||
public bool hidden
|
||||
{
|
||||
get => m_Hidden;
|
||||
set => m_Hidden = value;
|
||||
}
|
||||
|
||||
internal string hideTagString => hidden ? "[HideInInspector]" : "";
|
||||
|
||||
// reference names are the HLSL declaration name / property block ref name
|
||||
internal virtual void GetPropertyReferenceNames(List<string> result)
|
||||
{
|
||||
result.Add(referenceName);
|
||||
}
|
||||
|
||||
// display names are used as the UI name in the property block / show up in the Material Inspector
|
||||
internal virtual void GetPropertyDisplayNames(List<string> result)
|
||||
{
|
||||
result.Add(displayName);
|
||||
}
|
||||
|
||||
// the simple interface for simple properties
|
||||
internal virtual string GetPropertyBlockString()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
// the more complex interface for complex properties (defaulted for simple properties)
|
||||
internal virtual void AppendPropertyBlockStrings(ShaderStringBuilder builder)
|
||||
{
|
||||
builder.AppendLine(GetPropertyBlockString());
|
||||
}
|
||||
|
||||
internal abstract void ForeachHLSLProperty(Action<HLSLProperty> action);
|
||||
|
||||
internal virtual string GetPropertyAsArgumentStringForVFX(string precisionString)
|
||||
{
|
||||
return GetPropertyAsArgumentString(precisionString);
|
||||
}
|
||||
|
||||
internal abstract string GetPropertyAsArgumentString(string precisionString);
|
||||
internal abstract AbstractMaterialNode ToConcreteNode();
|
||||
internal abstract PreviewProperty GetPreviewMaterialProperty();
|
||||
|
||||
public virtual string GetPropertyTypeString()
|
||||
{
|
||||
string depString = $" (Deprecated{(ShaderGraphPreferences.allowDeprecatedBehaviors ? " V" + sgVersion : "")})";
|
||||
return propertyType.ToString() + (sgVersion < latestVersion ? depString : "");
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public abstract class AbstractShaderProperty<T> : AbstractShaderProperty
|
||||
{
|
||||
[SerializeField]
|
||||
T m_Value;
|
||||
|
||||
public virtual T value
|
||||
{
|
||||
get => m_Value;
|
||||
set => m_Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
// class for extracting deprecated data from older versions of AbstractShaderProperty
|
||||
class LegacyShaderPropertyData
|
||||
{
|
||||
// indicates user wishes to support the HYBRID renderer GPU instanced path
|
||||
[SerializeField]
|
||||
public bool m_GPUInstanced = false;
|
||||
|
||||
// converts the old m_GPUInstanced data into the new override HLSLDeclaration system.
|
||||
public static void UpgradeToHLSLDeclarationOverride(string json, AbstractShaderProperty property)
|
||||
{
|
||||
// this maintains the old behavior for versioned properties:
|
||||
// old exposed GPUInstanced properties are declared hybrid (becomes override in new system)
|
||||
// old unexposed GPUInstanced properties are declared global (becomes override in new system)
|
||||
// old exposed properties are declared UnityPerMaterial (default behavior, no override necessary)
|
||||
// old unexposed properties are declared Global (default behavior, no override necessary)
|
||||
// moving forward, users can use the overrides directly to control what it does
|
||||
|
||||
var legacyShaderPropertyData = new LegacyShaderPropertyData();
|
||||
JsonUtility.FromJsonOverwrite(json, legacyShaderPropertyData);
|
||||
if (legacyShaderPropertyData.m_GPUInstanced)
|
||||
{
|
||||
property.overrideHLSLDeclaration = true;
|
||||
if (property.generatePropertyBlock)
|
||||
property.hlslDeclarationOverride = HLSLDeclaration.HybridPerInstance;
|
||||
else
|
||||
property.hlslDeclarationOverride = HLSLDeclaration.Global;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum HLSLType
|
||||
{
|
||||
// value types
|
||||
_float,
|
||||
_float2,
|
||||
_float3,
|
||||
_float4,
|
||||
_matrix4x4,
|
||||
|
||||
// object types
|
||||
FirstObjectType,
|
||||
_Texture2D = FirstObjectType,
|
||||
_Texture3D,
|
||||
_TextureCube,
|
||||
_Texture2DArray,
|
||||
_SamplerState,
|
||||
|
||||
// custom type
|
||||
_CUSTOM
|
||||
}
|
||||
|
||||
// describes the different ways we can generate HLSL declarations
|
||||
[Flags]
|
||||
internal enum HLSLDeclaration
|
||||
{
|
||||
DoNotDeclare, // NOT declared in HLSL
|
||||
Global, // declared in the global scope, mainly for use with state coming from Shader.SetGlobal*()
|
||||
UnityPerMaterial, // declared in the UnityPerMaterial cbuffer, populated by Material or MaterialPropertyBlock
|
||||
HybridPerInstance, // declared using HybridRenderer path (v1 or v2) to get DOTS GPU instancing
|
||||
}
|
||||
|
||||
internal struct HLSLProperty
|
||||
{
|
||||
public string name;
|
||||
public HLSLType type;
|
||||
public ConcretePrecision precision;
|
||||
public HLSLDeclaration declaration;
|
||||
public Action<ShaderStringBuilder> customDeclaration;
|
||||
|
||||
public HLSLProperty(HLSLType type, string name, HLSLDeclaration declaration, ConcretePrecision precision = ConcretePrecision.Single)
|
||||
{
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.declaration = declaration;
|
||||
this.precision = precision;
|
||||
this.customDeclaration = null;
|
||||
}
|
||||
|
||||
public bool ValueEquals(HLSLProperty other)
|
||||
{
|
||||
if ((name != other.name) ||
|
||||
(type != other.type) ||
|
||||
(precision != other.precision) ||
|
||||
(declaration != other.declaration) ||
|
||||
((customDeclaration == null) != (other.customDeclaration == null)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (customDeclaration != null)
|
||||
{
|
||||
var ssb = new ShaderStringBuilder();
|
||||
var ssbother = new ShaderStringBuilder();
|
||||
customDeclaration(ssb);
|
||||
other.customDeclaration(ssbother);
|
||||
if (ssb.ToCodeBlock() != ssbother.ToCodeBlock())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static string[,] kValueTypeStrings = new string[(int)HLSLType.FirstObjectType, 2]
|
||||
{
|
||||
{"float", "half"},
|
||||
{"float2", "half2"},
|
||||
{"float3", "half3"},
|
||||
{"float4", "half4"},
|
||||
{"float4x4", "half4x4"}
|
||||
};
|
||||
|
||||
static string[] kObjectTypeStrings = new string[(int)HLSLType._CUSTOM - (int)HLSLType.FirstObjectType]
|
||||
{
|
||||
"TEXTURE2D",
|
||||
"TEXTURE3D",
|
||||
"TEXTURECUBE",
|
||||
"TEXTURE2D_ARRAY",
|
||||
"SAMPLER",
|
||||
};
|
||||
|
||||
public bool IsObjectType()
|
||||
{
|
||||
return type == HLSLType._SamplerState ||
|
||||
type == HLSLType._Texture2D ||
|
||||
type == HLSLType._Texture3D ||
|
||||
type == HLSLType._TextureCube ||
|
||||
type == HLSLType._Texture2DArray;
|
||||
}
|
||||
|
||||
public string GetValueTypeString()
|
||||
{
|
||||
if (type < HLSLType.FirstObjectType)
|
||||
return kValueTypeStrings[(int)type, (int)precision];
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AppendTo(ShaderStringBuilder ssb, Func<string, string> nameModifier = null)
|
||||
{
|
||||
var mName = nameModifier?.Invoke(name) ?? name;
|
||||
|
||||
if (type < HLSLType.FirstObjectType)
|
||||
{
|
||||
ssb.Append(kValueTypeStrings[(int)type, (int)precision]);
|
||||
ssb.Append(" ");
|
||||
ssb.Append(mName);
|
||||
ssb.Append(";");
|
||||
}
|
||||
else if (type < HLSLType._CUSTOM)
|
||||
{
|
||||
ssb.Append(kObjectTypeStrings[type - HLSLType.FirstObjectType]);
|
||||
ssb.Append("(");
|
||||
ssb.Append(mName);
|
||||
ssb.Append(");");
|
||||
}
|
||||
else
|
||||
{
|
||||
customDeclaration(ssb);
|
||||
}
|
||||
//ssb.Append(" // ");
|
||||
//ssb.Append(declaration.ToString());
|
||||
ssb.AppendNewLine();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b1411039ed1342fa8efff6fa8a4c179d
|
||||
timeCreated: 1505346915
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class BitangentMaterialSlot : SpaceMaterialSlot, IMayRequireBitangent
|
||||
{
|
||||
public BitangentMaterialSlot() : base()
|
||||
{ }
|
||||
|
||||
public BitangentMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, space, stageCapability, hidden)
|
||||
{ }
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new LabelSlotControlView(space + " Space");
|
||||
}
|
||||
|
||||
public override string GetDefaultValue(GenerationMode generationMode)
|
||||
{
|
||||
return string.Format("IN.{0}", space.ToVariableName(InterpolatorType.BiTangent));
|
||||
}
|
||||
|
||||
public NeededCoordinateSpace RequiresBitangent(ShaderStageCapability stageCapability)
|
||||
{
|
||||
if (isConnected)
|
||||
return NeededCoordinateSpace.None;
|
||||
return space.ToNeededCoordinateSpace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67f66fefcaac3e04388ec470163bf127
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,105 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class BooleanMaterialSlot : MaterialSlot, IMaterialSlotHasValue<bool>
|
||||
{
|
||||
[SerializeField]
|
||||
private bool m_Value;
|
||||
|
||||
[SerializeField]
|
||||
private bool m_DefaultValue;
|
||||
|
||||
public BooleanMaterialSlot()
|
||||
{ }
|
||||
|
||||
public BooleanMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
bool value,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
|
||||
{
|
||||
m_DefaultValue = value;
|
||||
m_Value = value;
|
||||
}
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new BooleanSlotControlView(this);
|
||||
}
|
||||
|
||||
public bool defaultValue { get { return m_DefaultValue; } }
|
||||
|
||||
public bool value
|
||||
{
|
||||
get { return m_Value; }
|
||||
set { m_Value = value; }
|
||||
}
|
||||
|
||||
public override bool isDefaultValue => value.Equals(defaultValue);
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
return (value ? 1 : 0).ToString();
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
if (!generationMode.IsPreview())
|
||||
return;
|
||||
|
||||
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 property = new BooleanShaderProperty()
|
||||
{
|
||||
overrideReferenceName = matOwner.GetVariableNameForSlot(id),
|
||||
generatePropertyBlock = false,
|
||||
value = value
|
||||
};
|
||||
properties.AddShaderProperty(property);
|
||||
}
|
||||
|
||||
public override SlotValueType valueType { get { return SlotValueType.Boolean; } }
|
||||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Boolean; } }
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
var pp = new PreviewProperty(PropertyType.Boolean)
|
||||
{
|
||||
name = name,
|
||||
booleanValue = value
|
||||
};
|
||||
properties.Add(pp);
|
||||
}
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{
|
||||
var slot = foundSlot as BooleanMaterialSlot;
|
||||
if (slot != null)
|
||||
value = slot.value;
|
||||
}
|
||||
|
||||
public override void CopyDefaultValue(MaterialSlot other)
|
||||
{
|
||||
base.CopyDefaultValue(other);
|
||||
if (other is IMaterialSlotHasValue<bool> ms)
|
||||
{
|
||||
m_DefaultValue = ms.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: efad93f5b8245a54fb4fee128fc0f3f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Controls;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Internal
|
||||
{
|
||||
[Serializable]
|
||||
[FormerName("UnityEditor.ShaderGraph.BooleanShaderProperty")]
|
||||
[BlackboardInputInfo(20)]
|
||||
public sealed class BooleanShaderProperty : AbstractShaderProperty<bool>
|
||||
{
|
||||
internal BooleanShaderProperty()
|
||||
{
|
||||
displayName = "Boolean";
|
||||
}
|
||||
|
||||
public override PropertyType propertyType => PropertyType.Boolean;
|
||||
|
||||
internal override bool isExposable => true;
|
||||
internal override bool isRenamable => true;
|
||||
|
||||
internal override string GetPropertyAsArgumentString(string precisionString)
|
||||
{
|
||||
return $"{concreteShaderValueType.ToShaderString(precisionString)} {referenceName}";
|
||||
}
|
||||
|
||||
internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
|
||||
{
|
||||
HLSLDeclaration decl = GetDefaultHLSLDeclaration();
|
||||
action(new HLSLProperty(HLSLType._float, referenceName, decl, concretePrecision));
|
||||
}
|
||||
|
||||
internal override string GetPropertyBlockString()
|
||||
{
|
||||
return $"{hideTagString}[ToggleUI]{referenceName}(\"{displayName}\", Float) = {(value == true ? 1 : 0)}";
|
||||
}
|
||||
|
||||
internal override AbstractMaterialNode ToConcreteNode()
|
||||
{
|
||||
return new BooleanNode { value = new ToggleData(value) };
|
||||
}
|
||||
|
||||
internal override PreviewProperty GetPreviewMaterialProperty()
|
||||
{
|
||||
return new PreviewProperty(propertyType)
|
||||
{
|
||||
name = referenceName,
|
||||
booleanValue = value
|
||||
};
|
||||
}
|
||||
|
||||
internal override ShaderInput Copy()
|
||||
{
|
||||
return new BooleanShaderProperty()
|
||||
{
|
||||
displayName = displayName,
|
||||
value = value,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8891f9466e6b01c498c3f4b2c6abc0eb
|
||||
timeCreated: 1505346922
|
|
@ -0,0 +1,132 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEditor.ShaderGraph.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
class CategoryData : JsonObject
|
||||
{
|
||||
[SerializeField]
|
||||
string m_Name;
|
||||
|
||||
public string name
|
||||
{
|
||||
get => m_Name;
|
||||
set => m_Name = value;
|
||||
}
|
||||
public string categoryGuid => this.objectId;
|
||||
|
||||
[SerializeField]
|
||||
List<JsonRef<ShaderInput>> m_ChildObjectList = new List<JsonRef<ShaderInput>>();
|
||||
|
||||
public RefValueEnumerable<ShaderInput> Children => m_ChildObjectList.SelectValue();
|
||||
|
||||
// We expose the object list as a HashSet of their objectIDs for faster existence checks
|
||||
HashSet<string> m_ChildObjectIDSet = new HashSet<string>();
|
||||
|
||||
public int childCount => m_ChildObjectIDSet.Count;
|
||||
|
||||
public void InsertItemIntoCategory(ShaderInput itemToAdd, int insertionIndex = -1)
|
||||
{
|
||||
if (itemToAdd == null)
|
||||
{
|
||||
AssertHelpers.Fail("Tried to insert item into category that was null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (insertionIndex == -1)
|
||||
{
|
||||
m_ChildObjectList.Add(itemToAdd);
|
||||
m_ChildObjectIDSet.Add(itemToAdd.objectId);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ChildObjectList.Insert(insertionIndex, itemToAdd);
|
||||
m_ChildObjectIDSet.Add(itemToAdd.objectId);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveItemFromCategory(ShaderInput itemToRemove)
|
||||
{
|
||||
if (IsItemInCategory(itemToRemove))
|
||||
{
|
||||
m_ChildObjectList.Remove(itemToRemove);
|
||||
m_ChildObjectIDSet.Remove(itemToRemove.objectId);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveItemInCategory(ShaderInput itemToMove, int newIndex)
|
||||
{
|
||||
int oldIndex = m_ChildObjectList.IndexOf(itemToMove);
|
||||
if (newIndex == oldIndex)
|
||||
return;
|
||||
m_ChildObjectList.RemoveAt(oldIndex);
|
||||
m_ChildObjectIDSet.Remove(itemToMove.objectId);
|
||||
// The actual index could have shifted due to the removal
|
||||
if (newIndex > oldIndex)
|
||||
newIndex--;
|
||||
InsertItemIntoCategory(itemToMove, newIndex);
|
||||
}
|
||||
|
||||
public bool IsItemInCategory(ShaderInput itemToCheck)
|
||||
{
|
||||
return m_ChildObjectIDSet.Contains(itemToCheck.objectId);
|
||||
}
|
||||
|
||||
public bool IsNamedCategory()
|
||||
{
|
||||
return name != String.Empty;
|
||||
}
|
||||
|
||||
public override void OnAfterDeserialize()
|
||||
{
|
||||
if (m_ChildObjectList != null)
|
||||
{
|
||||
for (int index = 0; index < m_ChildObjectList.Count; ++index)
|
||||
{
|
||||
var childObject = m_ChildObjectList[index];
|
||||
if (childObject.value != null)
|
||||
m_ChildObjectIDSet.Add(childObject.value.objectId);
|
||||
else
|
||||
m_ChildObjectList.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
base.OnAfterDeserialize();
|
||||
}
|
||||
|
||||
public CategoryData()
|
||||
{
|
||||
foreach (var childObject in m_ChildObjectList)
|
||||
{
|
||||
m_ChildObjectIDSet.Add(childObject.value.objectId);
|
||||
}
|
||||
}
|
||||
|
||||
public CategoryData(string inName, List<ShaderInput> categoryChildren = null)
|
||||
{
|
||||
name = inName;
|
||||
if (categoryChildren != null)
|
||||
{
|
||||
foreach (var childObject in categoryChildren)
|
||||
{
|
||||
m_ChildObjectList.Add(childObject);
|
||||
m_ChildObjectIDSet.Add(childObject.objectId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CategoryData(CategoryData categoryToCopy)
|
||||
{
|
||||
this.name = categoryToCopy.name;
|
||||
}
|
||||
|
||||
public static CategoryData DefaultCategory(List<ShaderInput> categoryChildren = null)
|
||||
{
|
||||
return new CategoryData(String.Empty, categoryChildren);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 332fa5bbacd1429da13c8290552956d3
|
||||
timeCreated: 1614033426
|
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
class ColorRGBAMaterialSlot : Vector4MaterialSlot
|
||||
{
|
||||
public ColorRGBAMaterialSlot() { }
|
||||
|
||||
public ColorRGBAMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
Vector4 value,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, value, stageCapability, hidden: hidden)
|
||||
{
|
||||
}
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new ColorRGBASlotControlView(this);
|
||||
}
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
return string.Format("IsGammaSpace() ? $precision4({0}, {1}, {2}, {3}) : $precision4 (SRGBToLinear($precision3({0}, {1}, {2})), {3})"
|
||||
, NodeUtils.FloatToShaderValue(value.x)
|
||||
, NodeUtils.FloatToShaderValue(value.y)
|
||||
, NodeUtils.FloatToShaderValue(value.z)
|
||||
, NodeUtils.FloatToShaderValue(value.w));
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
if (!generationMode.IsPreview())
|
||||
return;
|
||||
|
||||
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 property = new ColorShaderProperty()
|
||||
{
|
||||
overrideReferenceName = matOwner.GetVariableNameForSlot(id),
|
||||
generatePropertyBlock = false,
|
||||
value = value
|
||||
};
|
||||
properties.AddShaderProperty(property);
|
||||
}
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
var pp = new PreviewProperty(PropertyType.Color)
|
||||
{
|
||||
name = name,
|
||||
colorValue = new Color(value.x, value.y, value.z, value.w),
|
||||
};
|
||||
properties.Add(pp);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89d670f0d46a47d08be1209a78765617
|
||||
timeCreated: 1510659340
|
|
@ -0,0 +1,88 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
class ColorRGBMaterialSlot : Vector3MaterialSlot
|
||||
{
|
||||
[SerializeField]
|
||||
ColorMode m_ColorMode = ColorMode.Default;
|
||||
|
||||
[SerializeField]
|
||||
private Color m_DefaultColor = Color.grey;
|
||||
|
||||
public ColorRGBMaterialSlot() { }
|
||||
|
||||
public ColorRGBMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
Color value,
|
||||
ColorMode colorMode,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, (Vector4)value, stageCapability, hidden: hidden)
|
||||
{
|
||||
m_ColorMode = colorMode;
|
||||
m_DefaultColor = value;
|
||||
}
|
||||
|
||||
public ColorMode colorMode
|
||||
{
|
||||
get { return m_ColorMode; }
|
||||
set { m_ColorMode = value; }
|
||||
}
|
||||
|
||||
public Color defaultColor => m_DefaultColor;
|
||||
|
||||
public override bool isDefaultValue => value.Equals((Vector4)defaultColor);
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new ColorRGBSlotControlView(this);
|
||||
}
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
return string.Format(m_ColorMode == ColorMode.Default ? "IsGammaSpace() ? $precision3({0}, {1}, {2}) : SRGBToLinear($precision3({0}, {1}, {2}))" : "$precision3({0}, {1}, {2})"
|
||||
, NodeUtils.FloatToShaderValue(value.x)
|
||||
, NodeUtils.FloatToShaderValue(value.y)
|
||||
, NodeUtils.FloatToShaderValue(value.z));
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
if (!generationMode.IsPreview())
|
||||
return;
|
||||
|
||||
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 property = new ColorShaderProperty()
|
||||
{
|
||||
overrideReferenceName = matOwner.GetVariableNameForSlot(id),
|
||||
generatePropertyBlock = false,
|
||||
value = new Color(value.x, value.y, value.z)
|
||||
};
|
||||
properties.AddShaderProperty(property);
|
||||
}
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
var pp = new PreviewProperty(PropertyType.Color)
|
||||
{
|
||||
name = name,
|
||||
colorValue = new Color(value.x, value.y, value.z, 1),
|
||||
};
|
||||
properties.Add(pp);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a29c1f6321a430d439c5623e2a44f397
|
||||
timeCreated: 1510659340
|
|
@ -0,0 +1,143 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Internal
|
||||
{
|
||||
[Serializable]
|
||||
[FormerName("UnityEditor.ShaderGraph.ColorShaderProperty")]
|
||||
[BlackboardInputInfo(10)]
|
||||
public sealed class ColorShaderProperty : AbstractShaderProperty<Color>
|
||||
{
|
||||
// 0 - original (broken color space)
|
||||
// 1 - fixed color space
|
||||
// 2 - original (broken color space) with HLSLDeclaration override
|
||||
// 3 - fixed color space with HLSLDeclaration override
|
||||
public override int latestVersion => 3;
|
||||
public const int deprecatedVersion = 2;
|
||||
|
||||
internal ColorShaderProperty()
|
||||
{
|
||||
displayName = "Color";
|
||||
}
|
||||
|
||||
internal ColorShaderProperty(int version) : this()
|
||||
{
|
||||
this.sgVersion = version;
|
||||
}
|
||||
|
||||
public override PropertyType propertyType => PropertyType.Color;
|
||||
|
||||
internal override bool isExposable => true;
|
||||
internal override bool isRenamable => true;
|
||||
|
||||
[SerializeField]
|
||||
internal bool isMainColor = false;
|
||||
|
||||
internal string hdrTagString => colorMode == ColorMode.HDR ? "[HDR]" : "";
|
||||
|
||||
internal string mainColorString => isMainColor ? "[MainColor]" : "";
|
||||
|
||||
internal override string GetPropertyBlockString()
|
||||
{
|
||||
return $"{hideTagString}{hdrTagString}{mainColorString}{referenceName}(\"{displayName}\", Color) = ({NodeUtils.FloatToShaderValueShaderLabSafe(value.r)}, {NodeUtils.FloatToShaderValueShaderLabSafe(value.g)}, {NodeUtils.FloatToShaderValueShaderLabSafe(value.b)}, {NodeUtils.FloatToShaderValueShaderLabSafe(value.a)})";
|
||||
}
|
||||
|
||||
internal override string GetPropertyAsArgumentString(string precisionString)
|
||||
{
|
||||
return $"{concreteShaderValueType.ToShaderString(precisionString)} {referenceName}";
|
||||
}
|
||||
|
||||
internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
|
||||
{
|
||||
HLSLDeclaration decl = GetDefaultHLSLDeclaration();
|
||||
action(new HLSLProperty(HLSLType._float4, referenceName, decl, concretePrecision));
|
||||
}
|
||||
|
||||
public override string GetOldDefaultReferenceName()
|
||||
{
|
||||
return $"Color_{objectId}";
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
ColorMode m_ColorMode;
|
||||
|
||||
public ColorMode colorMode
|
||||
{
|
||||
get => m_ColorMode;
|
||||
set => m_ColorMode = value;
|
||||
}
|
||||
|
||||
internal override AbstractMaterialNode ToConcreteNode()
|
||||
{
|
||||
return new ColorNode { color = new ColorNode.Color(value, colorMode) };
|
||||
}
|
||||
|
||||
internal override PreviewProperty GetPreviewMaterialProperty()
|
||||
{
|
||||
UnityEngine.Color propColor = value;
|
||||
if (colorMode == ColorMode.Default)
|
||||
{
|
||||
if (PlayerSettings.colorSpace == ColorSpace.Linear)
|
||||
propColor = propColor.linear;
|
||||
}
|
||||
else if (colorMode == ColorMode.HDR)
|
||||
{
|
||||
// conversion from linear to active color space is handled in the shader code (see PropertyNode.cs)
|
||||
}
|
||||
|
||||
// we use Vector4 type to avoid all of the automatic color conversions of PropertyType.Color
|
||||
return new PreviewProperty(PropertyType.Vector4)
|
||||
{
|
||||
name = referenceName,
|
||||
vector4Value = propColor
|
||||
};
|
||||
}
|
||||
|
||||
internal override string GetHLSLVariableName(bool isSubgraphProperty, GenerationMode mode)
|
||||
{
|
||||
HLSLDeclaration decl = GetDefaultHLSLDeclaration();
|
||||
if (decl == HLSLDeclaration.HybridPerInstance)
|
||||
return $"UNITY_ACCESS_HYBRID_INSTANCED_PROP({referenceName}, {concretePrecision.ToShaderString()}4)";
|
||||
else
|
||||
return base.GetHLSLVariableName(isSubgraphProperty, mode);
|
||||
}
|
||||
|
||||
internal override ShaderInput Copy()
|
||||
{
|
||||
return new ColorShaderProperty()
|
||||
{
|
||||
sgVersion = sgVersion,
|
||||
displayName = displayName,
|
||||
value = value,
|
||||
colorMode = colorMode,
|
||||
isMainColor = isMainColor
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnAfterDeserialize(string json)
|
||||
{
|
||||
if (sgVersion < 2)
|
||||
{
|
||||
LegacyShaderPropertyData.UpgradeToHLSLDeclarationOverride(json, this);
|
||||
// version 0 upgrades to 2
|
||||
// version 1 upgrades to 3
|
||||
ChangeVersion((sgVersion == 0) ? 2 : 3);
|
||||
}
|
||||
}
|
||||
|
||||
internal override void OnBeforePasteIntoGraph(GraphData graph)
|
||||
{
|
||||
if (isMainColor)
|
||||
{
|
||||
ColorShaderProperty existingMain = graph.GetMainColor();
|
||||
if (existingMain != null && existingMain != this)
|
||||
{
|
||||
isMainColor = false;
|
||||
}
|
||||
}
|
||||
base.OnBeforePasteIntoGraph(graph);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 47cf9e64b21b48b09320f42eb82ac3c3
|
||||
timeCreated: 1505346940
|
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
[HasDependencies(typeof(MinimalCubemapInputMaterialSlot))]
|
||||
class CubemapInputMaterialSlot : CubemapMaterialSlot
|
||||
{
|
||||
[SerializeField]
|
||||
private SerializableCubemap m_Cubemap = new SerializableCubemap();
|
||||
|
||||
public Cubemap cubemap
|
||||
{
|
||||
get { return m_Cubemap.cubemap; }
|
||||
set { m_Cubemap.cubemap = value; }
|
||||
}
|
||||
|
||||
public override bool isDefaultValue => cubemap == null;
|
||||
|
||||
public CubemapInputMaterialSlot()
|
||||
{ }
|
||||
|
||||
public CubemapInputMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, SlotType.Input, stageCapability, hidden)
|
||||
{ }
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new CubemapSlotControlView(this);
|
||||
}
|
||||
|
||||
public override string GetDefaultValue(GenerationMode generationMode)
|
||||
{
|
||||
var nodeOwner = owner as AbstractMaterialNode;
|
||||
if (nodeOwner == null)
|
||||
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
|
||||
|
||||
return $"UnityBuildTextureCubeStruct({nodeOwner.GetVariableNameForSlot(id)})";
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
var nodeOwner = owner as AbstractMaterialNode;
|
||||
if (nodeOwner == 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 CubemapShaderProperty();
|
||||
prop.overrideReferenceName = nodeOwner.GetVariableNameForSlot(id);
|
||||
prop.modifiable = false;
|
||||
prop.generatePropertyBlock = true;
|
||||
prop.value.cubemap = cubemap;
|
||||
properties.AddShaderProperty(prop);
|
||||
}
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
var pp = new PreviewProperty(PropertyType.Cubemap)
|
||||
{
|
||||
name = name,
|
||||
cubemapValue = cubemap
|
||||
};
|
||||
properties.Add(pp);
|
||||
}
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{
|
||||
var slot = foundSlot as CubemapInputMaterialSlot;
|
||||
if (slot != null)
|
||||
{
|
||||
m_Cubemap = slot.m_Cubemap;
|
||||
bareResource = slot.bareResource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MinimalCubemapInputMaterialSlot : IHasDependencies
|
||||
{
|
||||
[SerializeField]
|
||||
private SerializableCubemap m_Cubemap = null;
|
||||
|
||||
public void GetSourceAssetDependencies(AssetCollection assetCollection)
|
||||
{
|
||||
var guidString = m_Cubemap.guid;
|
||||
if (!string.IsNullOrEmpty(guidString) && GUID.TryParse(guidString, out var guid))
|
||||
{
|
||||
assetCollection.AddAssetDependency(guid, AssetCollection.Flags.IncludeInExportPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7b961f6f7e2617446afb6a8e329d84d4
|
||||
timeCreated: 1509276977
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class CubemapMaterialSlot : MaterialSlot
|
||||
{
|
||||
public CubemapMaterialSlot()
|
||||
{ }
|
||||
|
||||
public CubemapMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
|
||||
{ }
|
||||
|
||||
[SerializeField]
|
||||
bool m_BareResource = false;
|
||||
internal override bool bareResource
|
||||
{
|
||||
get { return m_BareResource; }
|
||||
set { m_BareResource = value; }
|
||||
}
|
||||
|
||||
public override void AppendHLSLParameterDeclaration(ShaderStringBuilder sb, string paramName)
|
||||
{
|
||||
if (m_BareResource)
|
||||
{
|
||||
sb.Append("TEXTURECUBE(");
|
||||
sb.Append(paramName);
|
||||
sb.Append(")");
|
||||
}
|
||||
else
|
||||
base.AppendHLSLParameterDeclaration(sb, paramName);
|
||||
}
|
||||
|
||||
public override SlotValueType valueType { get { return SlotValueType.Cubemap; } }
|
||||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Cubemap; } }
|
||||
public override bool isDefaultValue => true;
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{ }
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{ }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ada5a840e90db5e4d901c686dca382ab
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,89 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Internal
|
||||
{
|
||||
[Serializable]
|
||||
[FormerName("UnityEditor.ShaderGraph.CubemapShaderProperty")]
|
||||
[BlackboardInputInfo(53)]
|
||||
public sealed class CubemapShaderProperty : AbstractShaderProperty<SerializableCubemap>
|
||||
{
|
||||
internal CubemapShaderProperty()
|
||||
{
|
||||
displayName = "Cubemap";
|
||||
value = new SerializableCubemap();
|
||||
}
|
||||
|
||||
public override PropertyType propertyType => PropertyType.Cubemap;
|
||||
|
||||
internal override bool isExposable => true;
|
||||
internal override bool isRenamable => true;
|
||||
|
||||
internal string modifiableTagString => modifiable ? "" : "[NonModifiableTextureData]";
|
||||
|
||||
internal override string GetPropertyBlockString()
|
||||
{
|
||||
return $"{hideTagString}{modifiableTagString}[NoScaleOffset]{referenceName}(\"{displayName}\", CUBE) = \"\" {{}}";
|
||||
}
|
||||
|
||||
internal override bool AllowHLSLDeclaration(HLSLDeclaration decl) => false; // disable UI, nothing to choose
|
||||
|
||||
internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
|
||||
{
|
||||
action(new HLSLProperty(HLSLType._TextureCube, referenceName, HLSLDeclaration.Global));
|
||||
action(new HLSLProperty(HLSLType._SamplerState, "sampler" + referenceName, HLSLDeclaration.Global));
|
||||
}
|
||||
|
||||
internal override string GetPropertyAsArgumentString(string precisionString)
|
||||
{
|
||||
return "UnityTextureCube " + referenceName;
|
||||
}
|
||||
|
||||
internal override string GetPropertyAsArgumentStringForVFX(string precisionString)
|
||||
{
|
||||
return "TEXTURECUBE(" + referenceName + ")";
|
||||
}
|
||||
|
||||
internal override string GetHLSLVariableName(bool isSubgraphProperty, GenerationMode mode)
|
||||
{
|
||||
if (isSubgraphProperty)
|
||||
return referenceName;
|
||||
else
|
||||
return $"UnityBuildTextureCubeStruct({referenceName})";
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool m_Modifiable = true;
|
||||
|
||||
internal bool modifiable
|
||||
{
|
||||
get => m_Modifiable;
|
||||
set => m_Modifiable = value;
|
||||
}
|
||||
|
||||
internal override AbstractMaterialNode ToConcreteNode()
|
||||
{
|
||||
return new CubemapAssetNode { cubemap = value.cubemap };
|
||||
}
|
||||
|
||||
internal override PreviewProperty GetPreviewMaterialProperty()
|
||||
{
|
||||
return new PreviewProperty(propertyType)
|
||||
{
|
||||
name = referenceName,
|
||||
cubemapValue = value.cubemap
|
||||
};
|
||||
}
|
||||
|
||||
internal override ShaderInput Copy()
|
||||
{
|
||||
return new CubemapShaderProperty()
|
||||
{
|
||||
displayName = displayName,
|
||||
value = value,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ca5ddce766d5ae24f8be282b4f7a21bd
|
||||
timeCreated: 1505346949
|
|
@ -0,0 +1,29 @@
|
|||
using UnityEditor.ShaderGraph;
|
||||
using ActionType = UnityEditor.ShaderGraph.IGraphDataAction;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
class DataStore<T>
|
||||
{
|
||||
Action<T, ActionType> m_Reducer;
|
||||
internal T State { get; private set; }
|
||||
|
||||
public Action<T, ActionType> Subscribe;
|
||||
|
||||
internal DataStore(Action<T, ActionType> reducer, T initialState)
|
||||
{
|
||||
m_Reducer = reducer;
|
||||
State = initialState;
|
||||
}
|
||||
|
||||
public void Dispatch(ActionType action)
|
||||
{
|
||||
m_Reducer(State, action);
|
||||
// Note: This would only work with reference types, as value types would require creating a new copy, this works given that we use GraphData which is a heap object
|
||||
// Notifies any listeners about change in state
|
||||
Subscribe?.Invoke(State, action);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 94728d99bee7bc94fbcf158448fc21a0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,129 @@
|
|||
using System;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class DynamicMatrixMaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4>
|
||||
{
|
||||
[SerializeField]
|
||||
private Matrix4x4 m_Value = Matrix4x4.identity;
|
||||
|
||||
[SerializeField]
|
||||
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
|
||||
|
||||
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Matrix4;
|
||||
|
||||
public DynamicMatrixMaterialSlot()
|
||||
{
|
||||
}
|
||||
|
||||
public DynamicMatrixMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
|
||||
{
|
||||
m_Value = value;
|
||||
}
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new LabelSlotControlView("Identity");
|
||||
}
|
||||
|
||||
public Matrix4x4 defaultValue { get { return m_DefaultValue; } }
|
||||
|
||||
public Matrix4x4 value
|
||||
{
|
||||
get { return m_Value; }
|
||||
set { m_Value = value; }
|
||||
}
|
||||
|
||||
public override bool isDefaultValue => value.Equals(defaultValue);
|
||||
|
||||
public override SlotValueType valueType { get { return SlotValueType.DynamicMatrix; } }
|
||||
|
||||
public override ConcreteSlotValueType concreteValueType
|
||||
{
|
||||
get { return m_ConcreteValueType; }
|
||||
}
|
||||
|
||||
public void SetConcreteType(ConcreteSlotValueType valueType)
|
||||
{
|
||||
m_ConcreteValueType = valueType;
|
||||
}
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
var channelCount = (int)SlotValueHelper.GetMatrixDimension(concreteValueType);
|
||||
var values = "";
|
||||
bool isFirst = true;
|
||||
for (var r = 0; r < channelCount; r++)
|
||||
{
|
||||
for (var c = 0; c < channelCount; c++)
|
||||
{
|
||||
if (!isFirst)
|
||||
values += ", ";
|
||||
isFirst = false;
|
||||
values += value.GetRow(r)[c];
|
||||
}
|
||||
}
|
||||
return string.Format("$precision{0}x{0}({1})", channelCount, values);
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
if (!generationMode.IsPreview())
|
||||
return;
|
||||
|
||||
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)));
|
||||
|
||||
AbstractShaderProperty property;
|
||||
switch (concreteValueType)
|
||||
{
|
||||
case ConcreteSlotValueType.Matrix4:
|
||||
property = new Matrix4ShaderProperty();
|
||||
break;
|
||||
case ConcreteSlotValueType.Matrix3:
|
||||
property = new Matrix3ShaderProperty();
|
||||
break;
|
||||
case ConcreteSlotValueType.Matrix2:
|
||||
property = new Matrix2ShaderProperty();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
property.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
|
||||
property.generatePropertyBlock = false;
|
||||
properties.AddShaderProperty(property);
|
||||
}
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{
|
||||
var slot = foundSlot as DynamicMatrixMaterialSlot;
|
||||
if (slot != null)
|
||||
value = slot.value;
|
||||
}
|
||||
|
||||
public override void CopyDefaultValue(MaterialSlot other)
|
||||
{
|
||||
base.CopyDefaultValue(other);
|
||||
if (other is IMaterialSlotHasValue<Matrix4x4> ms)
|
||||
{
|
||||
m_DefaultValue = ms.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e985385869ccee4ca3c6fd2fd15174c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,170 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class DynamicValueMaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4>
|
||||
{
|
||||
[SerializeField]
|
||||
private Matrix4x4 m_Value;
|
||||
|
||||
[SerializeField]
|
||||
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
|
||||
|
||||
static readonly string[] k_Labels = { "X", "Y", "Z", "W" };
|
||||
|
||||
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Vector4;
|
||||
|
||||
public DynamicValueMaterialSlot()
|
||||
{
|
||||
}
|
||||
|
||||
public DynamicValueMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
Matrix4x4 value,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
|
||||
{
|
||||
m_Value = value;
|
||||
}
|
||||
|
||||
public Matrix4x4 defaultValue { get { return m_DefaultValue; } }
|
||||
|
||||
public Matrix4x4 value
|
||||
{
|
||||
get { return m_Value; }
|
||||
set { m_Value = value; }
|
||||
}
|
||||
|
||||
public override bool isDefaultValue => value.Equals(defaultValue);
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
var labels = k_Labels.Take(concreteValueType.GetChannelCount()).ToArray();
|
||||
return new MultiFloatSlotControlView(owner, labels, () => value.GetRow(0), (newValue) =>
|
||||
value = new Matrix4x4()
|
||||
{
|
||||
m00 = newValue.x,
|
||||
m01 = newValue.y,
|
||||
m02 = newValue.z,
|
||||
m03 = newValue.w,
|
||||
m10 = value.m10,
|
||||
m11 = value.m11,
|
||||
m12 = value.m12,
|
||||
m13 = value.m13,
|
||||
m20 = value.m20,
|
||||
m21 = value.m21,
|
||||
m22 = value.m22,
|
||||
m23 = value.m23,
|
||||
m30 = value.m30,
|
||||
m31 = value.m31,
|
||||
m32 = value.m32,
|
||||
m33 = value.m33,
|
||||
});
|
||||
}
|
||||
|
||||
public override SlotValueType valueType { get { return SlotValueType.Dynamic; } }
|
||||
|
||||
public override ConcreteSlotValueType concreteValueType
|
||||
{
|
||||
get { return m_ConcreteValueType; }
|
||||
}
|
||||
|
||||
public void SetConcreteType(ConcreteSlotValueType valueType)
|
||||
{
|
||||
m_ConcreteValueType = valueType;
|
||||
}
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
var propType = concreteValueType.ToPropertyType();
|
||||
var pp = new PreviewProperty(propType) { name = name };
|
||||
if (propType == PropertyType.Float)
|
||||
pp.floatValue = value.m00;
|
||||
else
|
||||
pp.vector4Value = new Vector4(value.m00, value.m01, value.m02, value.m03);
|
||||
properties.Add(pp);
|
||||
}
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
var channelCount = SlotValueHelper.GetChannelCount(concreteValueType);
|
||||
string values = NodeUtils.FloatToShaderValue(value.m00);
|
||||
if (channelCount == 1)
|
||||
return values;
|
||||
for (var i = 1; i < channelCount; i++)
|
||||
values += ", " + NodeUtils.FloatToShaderValue(value.GetRow(0)[i]);
|
||||
return string.Format("$precision{0}({1})", channelCount, values);
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
if (!generationMode.IsPreview())
|
||||
return;
|
||||
|
||||
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)));
|
||||
|
||||
AbstractShaderProperty property;
|
||||
switch (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 Vector1ShaderProperty();
|
||||
break;
|
||||
case ConcreteSlotValueType.Matrix4:
|
||||
property = new Matrix4ShaderProperty();
|
||||
break;
|
||||
case ConcreteSlotValueType.Matrix3:
|
||||
property = new Matrix3ShaderProperty();
|
||||
break;
|
||||
case ConcreteSlotValueType.Matrix2:
|
||||
property = new Matrix2ShaderProperty();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
property.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
|
||||
property.generatePropertyBlock = false;
|
||||
properties.AddShaderProperty(property);
|
||||
}
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{
|
||||
var slot = foundSlot as DynamicValueMaterialSlot;
|
||||
if (slot != null)
|
||||
value = slot.value;
|
||||
}
|
||||
|
||||
public override void CopyDefaultValue(MaterialSlot other)
|
||||
{
|
||||
base.CopyDefaultValue(other);
|
||||
if (other is IMaterialSlotHasValue<Matrix4x4> ms)
|
||||
{
|
||||
m_DefaultValue = ms.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 38b2d4645340d4274a793e2e12ec097c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,145 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class DynamicVectorMaterialSlot : MaterialSlot, IMaterialSlotHasValue<Vector4>
|
||||
{
|
||||
[SerializeField]
|
||||
private Vector4 m_Value;
|
||||
|
||||
[SerializeField]
|
||||
private Vector4 m_DefaultValue = Vector4.zero;
|
||||
|
||||
static readonly string[] k_Labels = { "X", "Y", "Z", "W" };
|
||||
|
||||
private ConcreteSlotValueType m_ConcreteValueType = ConcreteSlotValueType.Vector1;
|
||||
|
||||
public DynamicVectorMaterialSlot()
|
||||
{
|
||||
}
|
||||
|
||||
public DynamicVectorMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
Vector4 value,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
|
||||
{
|
||||
m_Value = value;
|
||||
}
|
||||
|
||||
public Vector4 defaultValue { get { return m_DefaultValue; } }
|
||||
|
||||
public Vector4 value
|
||||
{
|
||||
get { return m_Value; }
|
||||
set { m_Value = value; }
|
||||
}
|
||||
|
||||
public override bool isDefaultValue => value.Equals(defaultValue);
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
var labels = k_Labels.Take(concreteValueType.GetChannelCount()).ToArray();
|
||||
return new MultiFloatSlotControlView(owner, labels, () => value, (newValue) => value = newValue);
|
||||
}
|
||||
|
||||
public override SlotValueType valueType { get { return SlotValueType.DynamicVector; } }
|
||||
|
||||
public override ConcreteSlotValueType concreteValueType
|
||||
{
|
||||
get { return m_ConcreteValueType; }
|
||||
}
|
||||
|
||||
public void SetConcreteType(ConcreteSlotValueType valueType)
|
||||
{
|
||||
m_ConcreteValueType = valueType;
|
||||
}
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
var propType = concreteValueType.ToPropertyType();
|
||||
var pp = new PreviewProperty(propType) { name = name };
|
||||
if (propType == PropertyType.Float)
|
||||
pp.floatValue = value.x;
|
||||
else
|
||||
pp.vector4Value = new Vector4(value.x, value.y, value.z, value.w);
|
||||
properties.Add(pp);
|
||||
}
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
var channelCount = SlotValueHelper.GetChannelCount(concreteValueType);
|
||||
string values = NodeUtils.FloatToShaderValue(value.x);
|
||||
if (channelCount == 1)
|
||||
return values;
|
||||
for (var i = 1; i < channelCount; i++)
|
||||
values += ", " + NodeUtils.FloatToShaderValue(value[i]);
|
||||
return string.Format("$precision{0}({1})", channelCount, values);
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
if (!generationMode.IsPreview())
|
||||
return;
|
||||
|
||||
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)));
|
||||
|
||||
AbstractShaderProperty property;
|
||||
switch (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 Vector1ShaderProperty();
|
||||
break;
|
||||
default:
|
||||
// This shouldn't happen due to edge validation. The generated shader will
|
||||
// have errors.
|
||||
Debug.LogError($"Invalid value type {concreteValueType} passed to Vector Slot {displayName}. Value will be ignored, please plug in an edge with a vector type.");
|
||||
return;
|
||||
}
|
||||
|
||||
property.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
|
||||
property.generatePropertyBlock = false;
|
||||
properties.AddShaderProperty(property);
|
||||
}
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{
|
||||
var slot = foundSlot as DynamicVectorMaterialSlot;
|
||||
if (slot != null)
|
||||
value = slot.value;
|
||||
}
|
||||
|
||||
public override void CopyDefaultValue(MaterialSlot other)
|
||||
{
|
||||
base.CopyDefaultValue(other);
|
||||
if (other is IMaterialSlotHasValue<Vector4> ms)
|
||||
{
|
||||
m_DefaultValue = ms.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a5dfe8ebe34ab064fb2769846adaa6a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class GradientInputMaterialSlot : GradientMaterialSlot, IMaterialSlotHasValue<Gradient>
|
||||
{
|
||||
[SerializeField]
|
||||
Gradient m_Value = new Gradient();
|
||||
|
||||
[SerializeField]
|
||||
Gradient m_DefaultValue = new Gradient();
|
||||
|
||||
public GradientInputMaterialSlot()
|
||||
{
|
||||
}
|
||||
|
||||
public GradientInputMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, SlotType.Input, stageCapability, hidden)
|
||||
{
|
||||
}
|
||||
|
||||
public Gradient value
|
||||
{
|
||||
get { return m_Value; }
|
||||
set { m_Value = value; }
|
||||
}
|
||||
|
||||
public Gradient defaultValue { get { return m_DefaultValue; } }
|
||||
|
||||
public override bool isDefaultValue => value.Equals(defaultValue);
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new GradientSlotControlView(this);
|
||||
}
|
||||
|
||||
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)));
|
||||
|
||||
if (generationMode.IsPreview())
|
||||
return GradientUtil.GetGradientForPreview(matOwner.GetVariableNameForSlot(id));
|
||||
|
||||
return ConcreteSlotValueAsVariable();
|
||||
}
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
return GradientUtil.GetGradientValue(value, "");
|
||||
}
|
||||
|
||||
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)));
|
||||
|
||||
if (generationMode != GenerationMode.Preview)
|
||||
return;
|
||||
|
||||
GradientUtil.GetGradientPropertiesForPreview(properties, matOwner.GetVariableNameForSlot(id), value);
|
||||
}
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
properties.Add(new PreviewProperty(PropertyType.Gradient)
|
||||
{
|
||||
name = name,
|
||||
gradientValue = value
|
||||
});
|
||||
}
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{
|
||||
var slot = foundSlot as GradientInputMaterialSlot;
|
||||
if (slot != null)
|
||||
value = slot.value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b1acbb0046e714669a0792cec877146c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using UnityEditor.Graphing;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class GradientMaterialSlot : MaterialSlot
|
||||
{
|
||||
public GradientMaterialSlot()
|
||||
{ }
|
||||
|
||||
public GradientMaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
|
||||
{ }
|
||||
|
||||
public override SlotValueType valueType { get { return SlotValueType.Gradient; } }
|
||||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Gradient; } }
|
||||
public override bool isDefaultValue => true;
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{ }
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{ }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7e0de094fe34c4c099697bd8e8e6ee07
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,112 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.ShaderGraph.Drawing.Controls;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
[BlackboardInputInfo(30)]
|
||||
class GradientShaderProperty : AbstractShaderProperty<Gradient>
|
||||
{
|
||||
public GradientShaderProperty()
|
||||
{
|
||||
displayName = "Gradient";
|
||||
value = new Gradient();
|
||||
}
|
||||
|
||||
public override PropertyType propertyType => PropertyType.Gradient;
|
||||
|
||||
internal override bool isExposable => false;
|
||||
internal override bool isRenamable => true;
|
||||
|
||||
internal override bool AllowHLSLDeclaration(HLSLDeclaration decl) => false; // disable UI, nothing to choose
|
||||
|
||||
internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
|
||||
{
|
||||
Action<ShaderStringBuilder> customDecl = (builder) =>
|
||||
{
|
||||
builder.AppendLine("Gradient {0}_Definition()", referenceName);
|
||||
using (builder.BlockScope())
|
||||
{
|
||||
string[] colors = new string[8];
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
colors[i] = string.Format("g.colors[{0}] = {1}4(0, 0, 0, 0);", i, concretePrecision.ToShaderString());
|
||||
for (int i = 0; i < value.colorKeys.Length; i++)
|
||||
colors[i] = string.Format("g.colors[{0}] = {1}4({2}, {3}, {4}, {5});"
|
||||
, i
|
||||
, concretePrecision.ToShaderString()
|
||||
, NodeUtils.FloatToShaderValue(value.colorKeys[i].color.r)
|
||||
, NodeUtils.FloatToShaderValue(value.colorKeys[i].color.g)
|
||||
, NodeUtils.FloatToShaderValue(value.colorKeys[i].color.b)
|
||||
, NodeUtils.FloatToShaderValue(value.colorKeys[i].time));
|
||||
|
||||
string[] alphas = new string[8];
|
||||
for (int i = 0; i < alphas.Length; i++)
|
||||
alphas[i] = string.Format("g.alphas[{0}] = {1}2(0, 0);", i, concretePrecision.ToShaderString());
|
||||
for (int i = 0; i < value.alphaKeys.Length; i++)
|
||||
alphas[i] = string.Format("g.alphas[{0}] = {1}2({2}, {3});"
|
||||
, i
|
||||
, concretePrecision.ToShaderString()
|
||||
, NodeUtils.FloatToShaderValue(value.alphaKeys[i].alpha)
|
||||
, NodeUtils.FloatToShaderValue(value.alphaKeys[i].time));
|
||||
|
||||
builder.AppendLine("Gradient g;");
|
||||
builder.AppendLine("g.type = {0};",
|
||||
(int)value.mode);
|
||||
builder.AppendLine("g.colorsLength = {0};",
|
||||
value.colorKeys.Length);
|
||||
builder.AppendLine("g.alphasLength = {0};",
|
||||
value.alphaKeys.Length);
|
||||
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
builder.AppendLine(colors[i]);
|
||||
|
||||
for (int i = 0; i < alphas.Length; i++)
|
||||
builder.AppendLine(alphas[i]);
|
||||
builder.AppendLine("return g;", true);
|
||||
}
|
||||
builder.TryAppendIndentation();
|
||||
builder.Append("#define {0} {0}_Definition()", referenceName);
|
||||
};
|
||||
|
||||
action(
|
||||
new HLSLProperty(HLSLType._CUSTOM, referenceName, HLSLDeclaration.Global, concretePrecision)
|
||||
{
|
||||
customDeclaration = customDecl
|
||||
});
|
||||
}
|
||||
|
||||
internal override string GetPropertyAsArgumentString(string precisionString)
|
||||
{
|
||||
return "Gradient " + referenceName;
|
||||
}
|
||||
|
||||
internal override AbstractMaterialNode ToConcreteNode()
|
||||
{
|
||||
return new GradientNode { gradient = value };
|
||||
}
|
||||
|
||||
internal override PreviewProperty GetPreviewMaterialProperty()
|
||||
{
|
||||
return new PreviewProperty(propertyType)
|
||||
{
|
||||
name = referenceName,
|
||||
gradientValue = value
|
||||
};
|
||||
}
|
||||
|
||||
internal override ShaderInput Copy()
|
||||
{
|
||||
return new GradientShaderProperty
|
||||
{
|
||||
displayName = displayName,
|
||||
value = value,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 544078fab8a6b410f907cc3ae58d977f
|
||||
timeCreated: 1505346949
|
|
@ -0,0 +1,29 @@
|
|||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
sealed partial class GraphData : ISerializationCallbackReceiver
|
||||
{
|
||||
public static class GraphConcretization
|
||||
{
|
||||
public static void ConcretizeNode(AbstractMaterialNode node)
|
||||
{
|
||||
node.Concretize();
|
||||
}
|
||||
|
||||
public static void ConcretizeProperties(GraphData graph)
|
||||
{
|
||||
var propertyNodes = graph.GetNodes<PropertyNode>().Where(n => !graph.m_Properties.Any(p => p == n.property)).ToArray();
|
||||
foreach (var pNode in propertyNodes)
|
||||
graph.ReplacePropertyNodeWithConcreteNodeNoValidate(pNode);
|
||||
}
|
||||
|
||||
public static void ConcretizeGraph(GraphData graph)
|
||||
{
|
||||
ConcretizeProperties(graph);
|
||||
GraphDataUtils.ApplyActionLeafFirst(graph, ConcretizeNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 54e6f853237cbe244b9d890b2a1eba6e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a2fb414d26e54be1a6cc2b4d6aa4b1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,26 @@
|
|||
using System.Linq;
|
||||
using UnityEditor.Graphing;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
readonly struct GraphDataReadOnly
|
||||
{
|
||||
private readonly GraphData m_Graph;
|
||||
|
||||
public GraphDataReadOnly(GraphData graph)
|
||||
{
|
||||
m_Graph = graph;
|
||||
}
|
||||
|
||||
private bool AnyConnectedControl<T>() where T : IControl
|
||||
{
|
||||
var matchingNodes = m_Graph.GetNodes<BlockNode>().Where(o => o.descriptor.control is T);
|
||||
return matchingNodes.SelectMany(o => o.GetInputSlots<MaterialSlot>()).Any(o => o.isConnected);
|
||||
}
|
||||
|
||||
public bool AnyVertexAnimationActive()
|
||||
{
|
||||
return AnyConnectedControl<PositionControl>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ca28a7e4d7fc7644a99f49e5a48574dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEngine.Pool;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
sealed partial class GraphData : ISerializationCallbackReceiver
|
||||
{
|
||||
public static class GraphDataUtils
|
||||
{
|
||||
public static void ApplyActionLeafFirst(GraphData graph, Action<AbstractMaterialNode> action)
|
||||
{
|
||||
var temporaryMarks = PooledHashSet<string>.Get();
|
||||
var permanentMarks = PooledHashSet<string>.Get();
|
||||
var slots = ListPool<MaterialSlot>.Get();
|
||||
|
||||
// Make sure we process a node's children before the node itself.
|
||||
var stack = StackPool<AbstractMaterialNode>.Get();
|
||||
foreach (var node in graph.GetNodes<AbstractMaterialNode>())
|
||||
{
|
||||
stack.Push(node);
|
||||
}
|
||||
while (stack.Count > 0)
|
||||
{
|
||||
var node = stack.Pop();
|
||||
if (permanentMarks.Contains(node.objectId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (temporaryMarks.Contains(node.objectId))
|
||||
{
|
||||
action.Invoke(node);
|
||||
permanentMarks.Add(node.objectId);
|
||||
}
|
||||
else
|
||||
{
|
||||
temporaryMarks.Add(node.objectId);
|
||||
stack.Push(node);
|
||||
node.GetInputSlots(slots);
|
||||
foreach (var inputSlot in slots)
|
||||
{
|
||||
var nodeEdges = graph.GetEdges(inputSlot.slotReference);
|
||||
foreach (var edge in nodeEdges)
|
||||
{
|
||||
var fromSocketRef = edge.outputSlot;
|
||||
var childNode = fromSocketRef.node;
|
||||
if (childNode != null)
|
||||
{
|
||||
stack.Push(childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
slots.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
StackPool<AbstractMaterialNode>.Release(stack);
|
||||
ListPool<MaterialSlot>.Release(slots);
|
||||
temporaryMarks.Dispose();
|
||||
permanentMarks.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e0a5780bf979b06409897f2eb2c23c13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
sealed partial class GraphData : ISerializationCallbackReceiver
|
||||
{
|
||||
public static class GraphSetup
|
||||
{
|
||||
public static void SetupNode(AbstractMaterialNode node)
|
||||
{
|
||||
node.Setup();
|
||||
}
|
||||
|
||||
public static void SetupGraph(GraphData graph)
|
||||
{
|
||||
GraphDataUtils.ApplyActionLeafFirst(graph, SetupNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b4148bd86961c24c8ccbdb3462dfd80
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
sealed partial class GraphData : ISerializationCallbackReceiver
|
||||
{
|
||||
public static class GraphValidation
|
||||
{
|
||||
public static void ValidateNode(AbstractMaterialNode node)
|
||||
{
|
||||
Type t = node.GetType();
|
||||
node.ValidateNode();
|
||||
if (!(node is BlockNode))
|
||||
{
|
||||
bool disallowedByAnyTargets = false;
|
||||
bool disallowedByAllTargets = true;
|
||||
IEnumerable<Target> targets = node.owner.activeTargets;
|
||||
if (node.owner.isSubGraph)
|
||||
{
|
||||
targets = node.owner.allPotentialTargets;
|
||||
}
|
||||
foreach (var target in targets)
|
||||
{
|
||||
//if at least one target doesn't allow a node, it is considered invalid
|
||||
if (!target.IsNodeAllowedByTarget(t))
|
||||
{
|
||||
disallowedByAnyTargets = true;
|
||||
node.isValid = false;
|
||||
node.owner.AddValidationError(node.objectId, $"{node.name} Node is not allowed by {target.displayName} implementation", Rendering.ShaderCompilerMessageSeverity.Warning);
|
||||
node.owner.m_UnsupportedTargets.Add(target);
|
||||
}
|
||||
//at least one target does allow node, not going to be explicitly set inactive
|
||||
else
|
||||
{
|
||||
disallowedByAllTargets = false;
|
||||
}
|
||||
}
|
||||
if (!disallowedByAnyTargets)
|
||||
{
|
||||
node.isValid = true;
|
||||
}
|
||||
|
||||
//Set ActiveState based on if all targets disallow this node
|
||||
if (disallowedByAllTargets)
|
||||
{
|
||||
node.SetOverrideActiveState(AbstractMaterialNode.ActiveState.ExplicitInactive);
|
||||
node.owner.AddValidationError(node.objectId, $"{node.name} Node is not allowed by any active targets, and will not be used in generation", Rendering.ShaderCompilerMessageSeverity.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
node.SetOverrideActiveState(AbstractMaterialNode.ActiveState.Implicit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ValidateGraph(GraphData graph)
|
||||
{
|
||||
graph.m_UnsupportedTargets.Clear();
|
||||
GraphDataUtils.ApplyActionLeafFirst(graph, ValidateNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e06ae0cdd5cae6d48a9e8ea6519840f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using UnityEditor.ShaderGraph.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
public class GroupData : JsonObject
|
||||
{
|
||||
[SerializeField]
|
||||
string m_Title;
|
||||
|
||||
public string title
|
||||
{
|
||||
get { return m_Title; }
|
||||
set { m_Title = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
Vector2 m_Position;
|
||||
|
||||
public Vector2 position
|
||||
{
|
||||
get { return m_Position; }
|
||||
set { m_Position = value; }
|
||||
}
|
||||
|
||||
public GroupData() : base() { }
|
||||
|
||||
public GroupData(string title, Vector2 position)
|
||||
{
|
||||
m_Title = title;
|
||||
m_Position = position;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dd9ae74f463480e49a2f6f1ed7f7fb2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,3 @@
|
|||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3e00256415a816419b39d61b3bf8451
|
||||
timeCreated: 1465559572
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
interface IMaterialSlotHasValue<T>
|
||||
{
|
||||
T defaultValue { get; }
|
||||
T value { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 94492244ef44a2e48b3e7790d7ac681d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.ShaderGraph.Internal
|
||||
{
|
||||
internal static class LightmappingShaderProperties
|
||||
{
|
||||
public class LightmapTextureArrayProperty : Texture2DArrayShaderProperty
|
||||
{
|
||||
internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
|
||||
{
|
||||
// no declaration from ShaderGraph side -- declared by SRP internal include files
|
||||
}
|
||||
|
||||
internal override string GetPropertyAsArgumentString(string precisionString)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly LightmapTextureArrayProperty kLightmapsArray = new LightmapTextureArrayProperty()
|
||||
{
|
||||
displayName = "unity_Lightmaps",
|
||||
generatePropertyBlock = true,
|
||||
overrideHLSLDeclaration = false,
|
||||
hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
|
||||
hidden = true,
|
||||
modifiable = true,
|
||||
overrideReferenceName = "unity_Lightmaps",
|
||||
precision = Precision.Single
|
||||
};
|
||||
|
||||
public static readonly LightmapTextureArrayProperty kLightmapsIndirectionArray = new LightmapTextureArrayProperty()
|
||||
{
|
||||
displayName = "unity_LightmapsInd",
|
||||
generatePropertyBlock = true,
|
||||
overrideHLSLDeclaration = false,
|
||||
hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
|
||||
hidden = true,
|
||||
modifiable = true,
|
||||
overrideReferenceName = "unity_LightmapsInd",
|
||||
precision = Precision.Single
|
||||
};
|
||||
|
||||
public static readonly LightmapTextureArrayProperty kShadowMasksArray = new LightmapTextureArrayProperty()
|
||||
{
|
||||
displayName = "unity_ShadowMasks",
|
||||
generatePropertyBlock = true,
|
||||
overrideHLSLDeclaration = false,
|
||||
hlslDeclarationOverride = HLSLDeclaration.DoNotDeclare,
|
||||
hidden = true,
|
||||
modifiable = true,
|
||||
overrideReferenceName = "unity_ShadowMasks",
|
||||
precision = Precision.Single
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c8591c94b6db465586cce42a9bd2a399
|
||||
timeCreated: 1601468048
|
|
@ -0,0 +1,375 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEditor.ShaderGraph.Serialization;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
abstract class MaterialSlot : JsonObject
|
||||
{
|
||||
const string k_NotInit = "Not Initialized";
|
||||
|
||||
[SerializeField]
|
||||
int m_Id;
|
||||
|
||||
[SerializeField]
|
||||
string m_DisplayName = k_NotInit;
|
||||
|
||||
[SerializeField]
|
||||
SlotType m_SlotType = SlotType.Input;
|
||||
|
||||
[SerializeField]
|
||||
bool m_Hidden;
|
||||
|
||||
[SerializeField]
|
||||
string m_ShaderOutputName;
|
||||
|
||||
[SerializeField]
|
||||
ShaderStageCapability m_StageCapability;
|
||||
|
||||
bool m_HasError;
|
||||
|
||||
protected MaterialSlot() { }
|
||||
|
||||
protected MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
|
||||
{
|
||||
m_Id = slotId;
|
||||
m_DisplayName = displayName;
|
||||
m_SlotType = slotType;
|
||||
m_Hidden = hidden;
|
||||
m_ShaderOutputName = shaderOutputName;
|
||||
this.stageCapability = stageCapability;
|
||||
}
|
||||
|
||||
internal void SetInternalData(SlotType slotType, string shaderOutputName)
|
||||
{
|
||||
this.m_SlotType = slotType;
|
||||
this.shaderOutputName = shaderOutputName;
|
||||
}
|
||||
|
||||
public bool IsConnectionTestable()
|
||||
{
|
||||
if (owner is SubGraphNode sgNode)
|
||||
{
|
||||
var property = sgNode.GetShaderProperty(id);
|
||||
if (property != null)
|
||||
{
|
||||
return property.isConnectionTestable;
|
||||
}
|
||||
}
|
||||
else if (owner is PropertyNode propertyNode)
|
||||
{
|
||||
return propertyNode.property.isConnectionTestable;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public VisualElement InstantiateCustomControl()
|
||||
{
|
||||
if (!isConnected && IsConnectionTestable())
|
||||
{
|
||||
var sgNode = owner as SubGraphNode;
|
||||
var property = sgNode.GetShaderProperty(id);
|
||||
return new LabelSlotControlView(property.customSlotLabel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual VisualElement InstantiateControl()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
static string ConcreteSlotValueTypeAsString(ConcreteSlotValueType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ConcreteSlotValueType.Vector1:
|
||||
return "(1)";
|
||||
case ConcreteSlotValueType.Vector2:
|
||||
return "(2)";
|
||||
case ConcreteSlotValueType.Vector3:
|
||||
return "(3)";
|
||||
case ConcreteSlotValueType.Vector4:
|
||||
return "(4)";
|
||||
case ConcreteSlotValueType.Boolean:
|
||||
return "(B)";
|
||||
case ConcreteSlotValueType.Matrix2:
|
||||
return "(2x2)";
|
||||
case ConcreteSlotValueType.Matrix3:
|
||||
return "(3x3)";
|
||||
case ConcreteSlotValueType.Matrix4:
|
||||
return "(4x4)";
|
||||
case ConcreteSlotValueType.SamplerState:
|
||||
return "(SS)";
|
||||
case ConcreteSlotValueType.Texture2D:
|
||||
return "(T2)";
|
||||
case ConcreteSlotValueType.Texture2DArray:
|
||||
return "(T2A)";
|
||||
case ConcreteSlotValueType.Texture3D:
|
||||
return "(T3)";
|
||||
case ConcreteSlotValueType.Cubemap:
|
||||
return "(C)";
|
||||
case ConcreteSlotValueType.Gradient:
|
||||
return "(G)";
|
||||
case ConcreteSlotValueType.VirtualTexture:
|
||||
return "(VT)";
|
||||
case ConcreteSlotValueType.PropertyConnectionState:
|
||||
return "(P)";
|
||||
default:
|
||||
return "(E)";
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string displayName
|
||||
{
|
||||
get { return m_DisplayName + ConcreteSlotValueTypeAsString(concreteValueType); }
|
||||
set { m_DisplayName = value; }
|
||||
}
|
||||
|
||||
public string RawDisplayName()
|
||||
{
|
||||
return m_DisplayName;
|
||||
}
|
||||
|
||||
public static MaterialSlot CreateMaterialSlot(SlotValueType type, int slotId, string displayName, string shaderOutputName, SlotType slotType, Vector4 defaultValue, ShaderStageCapability shaderStageCapability = ShaderStageCapability.All, bool hidden = false)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SlotValueType.SamplerState:
|
||||
return new SamplerStateMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.DynamicMatrix:
|
||||
return new DynamicMatrixMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.Matrix4:
|
||||
return new Matrix4MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.Matrix3:
|
||||
return new Matrix3MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.Matrix2:
|
||||
return new Matrix2MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.Texture2D:
|
||||
return slotType == SlotType.Input
|
||||
? new Texture2DInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
|
||||
: new Texture2DMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.Texture2DArray:
|
||||
return slotType == SlotType.Input
|
||||
? new Texture2DArrayInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
|
||||
: new Texture2DArrayMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.Texture3D:
|
||||
return slotType == SlotType.Input
|
||||
? new Texture3DInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
|
||||
: new Texture3DMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.Cubemap:
|
||||
return slotType == SlotType.Input
|
||||
? new CubemapInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
|
||||
: new CubemapMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.VirtualTexture:
|
||||
return slotType == SlotType.Input
|
||||
? new VirtualTextureInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
|
||||
: new VirtualTextureMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.Gradient:
|
||||
return slotType == SlotType.Input
|
||||
? new GradientInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
|
||||
: new GradientMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
case SlotValueType.DynamicVector:
|
||||
return new DynamicVectorMaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden);
|
||||
case SlotValueType.Vector4:
|
||||
return new Vector4MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden);
|
||||
case SlotValueType.Vector3:
|
||||
return new Vector3MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden);
|
||||
case SlotValueType.Vector2:
|
||||
return new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden);
|
||||
case SlotValueType.Vector1:
|
||||
return new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStageCapability, hidden: hidden);
|
||||
case SlotValueType.Dynamic:
|
||||
return new DynamicValueMaterialSlot(slotId, displayName, shaderOutputName, slotType, new Matrix4x4(defaultValue, Vector4.zero, Vector4.zero, Vector4.zero), shaderStageCapability, hidden);
|
||||
case SlotValueType.Boolean:
|
||||
return new BooleanMaterialSlot(slotId, displayName, shaderOutputName, slotType, false, shaderStageCapability, hidden);
|
||||
case SlotValueType.PropertyConnectionState:
|
||||
return new PropertyConnectionStateMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException("type", type, null);
|
||||
}
|
||||
|
||||
public SlotReference slotReference
|
||||
{
|
||||
get { return new SlotReference(owner, m_Id); }
|
||||
}
|
||||
|
||||
public AbstractMaterialNode owner { get; set; }
|
||||
|
||||
// if hidden, the slot does not create a port in the UI
|
||||
public bool hidden
|
||||
{
|
||||
get { return m_Hidden; }
|
||||
set { m_Hidden = value; }
|
||||
}
|
||||
|
||||
public int id
|
||||
{
|
||||
get { return m_Id; }
|
||||
}
|
||||
|
||||
public bool isInputSlot
|
||||
{
|
||||
get { return m_SlotType == SlotType.Input; }
|
||||
}
|
||||
|
||||
public bool isOutputSlot
|
||||
{
|
||||
get { return m_SlotType == SlotType.Output; }
|
||||
}
|
||||
|
||||
public SlotType slotType
|
||||
{
|
||||
get { return m_SlotType; }
|
||||
}
|
||||
|
||||
public bool isConnected
|
||||
{
|
||||
get
|
||||
{
|
||||
// node and graph respectivly
|
||||
if (owner == null || owner.owner == null)
|
||||
return false;
|
||||
|
||||
var graph = owner.owner;
|
||||
var edges = graph.GetEdges(slotReference);
|
||||
return edges.Any();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract bool isDefaultValue { get; }
|
||||
|
||||
public abstract SlotValueType valueType { get; }
|
||||
|
||||
public abstract ConcreteSlotValueType concreteValueType { get; }
|
||||
|
||||
public string shaderOutputName
|
||||
{
|
||||
get { return m_ShaderOutputName; }
|
||||
private set { m_ShaderOutputName = value; }
|
||||
}
|
||||
|
||||
public ShaderStageCapability stageCapability
|
||||
{
|
||||
get { return m_StageCapability; }
|
||||
set { m_StageCapability = value; }
|
||||
}
|
||||
|
||||
public bool hasError
|
||||
{
|
||||
get { return m_HasError; }
|
||||
set { m_HasError = value; }
|
||||
}
|
||||
|
||||
public bool IsUsingDefaultValue()
|
||||
{
|
||||
if (!isConnected && isDefaultValue)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsCompatibleWith(MaterialSlot otherSlot)
|
||||
{
|
||||
return otherSlot != null
|
||||
&& otherSlot.owner != owner
|
||||
&& otherSlot.isInputSlot != isInputSlot
|
||||
&& !hidden
|
||||
&& !otherSlot.hidden
|
||||
&& ((isInputSlot
|
||||
? SlotValueHelper.AreCompatible(valueType, otherSlot.concreteValueType, otherSlot.IsConnectionTestable())
|
||||
: SlotValueHelper.AreCompatible(otherSlot.valueType, concreteValueType, IsConnectionTestable())));
|
||||
}
|
||||
|
||||
public bool IsCompatibleStageWith(MaterialSlot otherSlot)
|
||||
{
|
||||
var startStage = otherSlot.stageCapability;
|
||||
if (startStage == ShaderStageCapability.All || otherSlot.owner is SubGraphNode)
|
||||
startStage = NodeUtils.GetEffectiveShaderStageCapability(otherSlot, true)
|
||||
& NodeUtils.GetEffectiveShaderStageCapability(otherSlot, false);
|
||||
return startStage == ShaderStageCapability.All || stageCapability == ShaderStageCapability.All || stageCapability == startStage;
|
||||
}
|
||||
|
||||
public string GetDefaultValue(GenerationMode generationMode, ConcretePrecision concretePrecision)
|
||||
{
|
||||
string defaultValue = GetDefaultValue(generationMode);
|
||||
return defaultValue.Replace(PrecisionUtil.Token, concretePrecision.ToShaderString());
|
||||
}
|
||||
|
||||
public virtual 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)));
|
||||
|
||||
if (generationMode.IsPreview() && matOwner.isActive)
|
||||
return matOwner.GetVariableNameForSlot(id);
|
||||
|
||||
return ConcreteSlotValueAsVariable();
|
||||
}
|
||||
|
||||
protected virtual string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
return "error";
|
||||
}
|
||||
|
||||
public abstract void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode);
|
||||
|
||||
public virtual void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
properties.Add(default(PreviewProperty));
|
||||
}
|
||||
|
||||
public virtual void AppendHLSLParameterDeclaration(ShaderStringBuilder sb, string paramName)
|
||||
{
|
||||
sb.Append(concreteValueType.ToShaderString());
|
||||
sb.Append(" ");
|
||||
sb.Append(paramName);
|
||||
}
|
||||
|
||||
public abstract void CopyValuesFrom(MaterialSlot foundSlot);
|
||||
|
||||
public bool Equals(MaterialSlot other)
|
||||
{
|
||||
return m_Id == other.m_Id && owner == other.owner;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != this.GetType()) return false;
|
||||
return Equals((MaterialSlot)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (m_Id * 397) ^ (owner != null ? owner.GetHashCode() : 0);
|
||||
}
|
||||
}
|
||||
|
||||
// this tracks old CustomFunctionNode slots that are expecting the old bare resource inputs
|
||||
// rather than the new structure-based inputs
|
||||
internal virtual bool bareResource { get { return false; } set { } }
|
||||
|
||||
public virtual void CopyDefaultValue(MaterialSlot other)
|
||||
{
|
||||
m_Id = other.m_Id;
|
||||
m_DisplayName = other.m_DisplayName;
|
||||
m_SlotType = other.m_SlotType;
|
||||
m_Hidden = other.m_Hidden;
|
||||
m_ShaderOutputName = other.m_ShaderOutputName;
|
||||
m_StageCapability = other.m_StageCapability;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d998d7fbd75b97459f63fb4931d14b5
|
||||
timeCreated: 1463560120
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class Matrix2MaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4>
|
||||
{
|
||||
[SerializeField]
|
||||
private Matrix4x4 m_Value = Matrix4x4.identity;
|
||||
|
||||
[SerializeField]
|
||||
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
|
||||
|
||||
public Matrix2MaterialSlot()
|
||||
{
|
||||
}
|
||||
|
||||
public Matrix2MaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
|
||||
{
|
||||
}
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new LabelSlotControlView("Identity");
|
||||
}
|
||||
|
||||
public Matrix4x4 defaultValue { get { return m_DefaultValue; } }
|
||||
|
||||
public Matrix4x4 value
|
||||
{
|
||||
get { return m_Value; }
|
||||
set { m_Value = value; }
|
||||
}
|
||||
|
||||
public override bool isDefaultValue => value.Equals(defaultValue);
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
return "$precision2x2 (1,0,0,1)";
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
if (!generationMode.IsPreview())
|
||||
return;
|
||||
|
||||
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 property = new Matrix2ShaderProperty()
|
||||
{
|
||||
overrideReferenceName = matOwner.GetVariableNameForSlot(id),
|
||||
generatePropertyBlock = false,
|
||||
value = value
|
||||
};
|
||||
properties.AddShaderProperty(property);
|
||||
}
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
var pp = new PreviewProperty(PropertyType.Matrix2)
|
||||
{
|
||||
name = name,
|
||||
matrixValue = value
|
||||
};
|
||||
properties.Add(pp);
|
||||
}
|
||||
|
||||
public override SlotValueType valueType { get { return SlotValueType.Matrix2; } }
|
||||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix2; } }
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{
|
||||
var slot = foundSlot as Matrix2MaterialSlot;
|
||||
if (slot != null)
|
||||
value = slot.value;
|
||||
}
|
||||
|
||||
public override void CopyDefaultValue(MaterialSlot other)
|
||||
{
|
||||
base.CopyDefaultValue(other);
|
||||
if (other is IMaterialSlotHasValue<Matrix4x4> ms)
|
||||
{
|
||||
m_DefaultValue = ms.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4cba4fbdefbdfa04cb2f6f84376a1353
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
[BlackboardInputInfo(70)]
|
||||
class Matrix2ShaderProperty : MatrixShaderProperty
|
||||
{
|
||||
public Matrix2ShaderProperty()
|
||||
{
|
||||
displayName = "Matrix2x2";
|
||||
value = Matrix4x4.identity;
|
||||
}
|
||||
|
||||
public override PropertyType propertyType => PropertyType.Matrix2;
|
||||
|
||||
internal override string GetPropertyAsArgumentString(string precisionString)
|
||||
{
|
||||
return $"{precisionString}2x2 {referenceName}";
|
||||
}
|
||||
|
||||
internal override AbstractMaterialNode ToConcreteNode()
|
||||
{
|
||||
return new Matrix2Node
|
||||
{
|
||||
row0 = new Vector2(value.m00, value.m01),
|
||||
row1 = new Vector2(value.m10, value.m11)
|
||||
};
|
||||
}
|
||||
|
||||
internal override PreviewProperty GetPreviewMaterialProperty()
|
||||
{
|
||||
return new PreviewProperty(propertyType)
|
||||
{
|
||||
name = referenceName,
|
||||
matrixValue = value
|
||||
};
|
||||
}
|
||||
|
||||
internal override ShaderInput Copy()
|
||||
{
|
||||
return new Matrix2ShaderProperty()
|
||||
{
|
||||
displayName = displayName,
|
||||
value = value,
|
||||
};
|
||||
}
|
||||
|
||||
public override int latestVersion => 1;
|
||||
public override void OnAfterDeserialize(string json)
|
||||
{
|
||||
if (sgVersion == 0)
|
||||
{
|
||||
// all old matrices were declared global; yes even if flagged hybrid!
|
||||
// maintain old behavior on versioning, users can always change the override if they wish
|
||||
overrideHLSLDeclaration = true;
|
||||
hlslDeclarationOverride = HLSLDeclaration.Global;
|
||||
ChangeVersion(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0755d7f7a7e11cb4294563bbd0d434cc
|
||||
timeCreated: 1505346935
|
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Graphing;
|
||||
using UnityEditor.ShaderGraph.Drawing.Slots;
|
||||
using UnityEditor.ShaderGraph.Internal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEditor.ShaderGraph
|
||||
{
|
||||
[Serializable]
|
||||
class Matrix3MaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4>
|
||||
{
|
||||
[SerializeField]
|
||||
private Matrix4x4 m_Value = Matrix4x4.identity;
|
||||
|
||||
[SerializeField]
|
||||
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
|
||||
|
||||
public Matrix3MaterialSlot()
|
||||
{
|
||||
}
|
||||
|
||||
public Matrix3MaterialSlot(
|
||||
int slotId,
|
||||
string displayName,
|
||||
string shaderOutputName,
|
||||
SlotType slotType,
|
||||
ShaderStageCapability stageCapability = ShaderStageCapability.All,
|
||||
bool hidden = false)
|
||||
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
|
||||
{
|
||||
}
|
||||
|
||||
public override VisualElement InstantiateControl()
|
||||
{
|
||||
return new LabelSlotControlView("Identity");
|
||||
}
|
||||
|
||||
public Matrix4x4 defaultValue { get { return m_DefaultValue; } }
|
||||
|
||||
public Matrix4x4 value
|
||||
{
|
||||
get { return m_Value; }
|
||||
set { m_Value = value; }
|
||||
}
|
||||
|
||||
public override bool isDefaultValue => value.Equals(defaultValue);
|
||||
|
||||
protected override string ConcreteSlotValueAsVariable()
|
||||
{
|
||||
return "$precision3x3 (1,0,0,0,1,0,0,0,1)";
|
||||
}
|
||||
|
||||
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
|
||||
{
|
||||
if (!generationMode.IsPreview())
|
||||
return;
|
||||
|
||||
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 property = new Matrix3ShaderProperty()
|
||||
{
|
||||
overrideReferenceName = matOwner.GetVariableNameForSlot(id),
|
||||
generatePropertyBlock = false,
|
||||
value = value
|
||||
};
|
||||
properties.AddShaderProperty(property);
|
||||
}
|
||||
|
||||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
|
||||
{
|
||||
var pp = new PreviewProperty(PropertyType.Matrix3)
|
||||
{
|
||||
name = name,
|
||||
matrixValue = value
|
||||
};
|
||||
properties.Add(pp);
|
||||
}
|
||||
|
||||
public override SlotValueType valueType { get { return SlotValueType.Matrix3; } }
|
||||
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix3; } }
|
||||
|
||||
public override void CopyValuesFrom(MaterialSlot foundSlot)
|
||||
{
|
||||
var slot = foundSlot as Matrix3MaterialSlot;
|
||||
if (slot != null)
|
||||
value = slot.value;
|
||||
}
|
||||
|
||||
public override void CopyDefaultValue(MaterialSlot other)
|
||||
{
|
||||
base.CopyDefaultValue(other);
|
||||
if (other is IMaterialSlotHasValue<Matrix4x4> ms)
|
||||
{
|
||||
m_DefaultValue = ms.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5afbdbfda75b8c24ab4c07b8b3deddbe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue