initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,3 @@
namespace UnityEditor.ShaderGraph
{
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f69ae4bd132ba4c4990a5f2ec28e5932
timeCreated: 1482920380
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b1411039ed1342fa8efff6fa8a4c179d
timeCreated: 1505346915

View file

@ -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();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 67f66fefcaac3e04388ec470163bf127
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: efad93f5b8245a54fb4fee128fc0f3f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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,
};
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8891f9466e6b01c498c3f4b2c6abc0eb
timeCreated: 1505346922

View file

@ -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);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 332fa5bbacd1429da13c8290552956d3
timeCreated: 1614033426

View file

@ -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);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 89d670f0d46a47d08be1209a78765617
timeCreated: 1510659340

View file

@ -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);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a29c1f6321a430d439c5623e2a44f397
timeCreated: 1510659340

View file

@ -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);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 47cf9e64b21b48b09320f42eb82ac3c3
timeCreated: 1505346940

View file

@ -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);
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b961f6f7e2617446afb6a8e329d84d4
timeCreated: 1509276977

View file

@ -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)
{ }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ada5a840e90db5e4d901c686dca382ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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,
};
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ca5ddce766d5ae24f8be282b4f7a21bd
timeCreated: 1505346949

View file

@ -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);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94728d99bee7bc94fbcf158448fc21a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9e985385869ccee4ca3c6fd2fd15174c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 38b2d4645340d4274a793e2e12ec097c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a5dfe8ebe34ab064fb2769846adaa6a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1acbb0046e714669a0792cec877146c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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)
{ }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e0de094fe34c4c099697bd8e8e6ee07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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,
};
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 544078fab8a6b410f907cc3ae58d977f
timeCreated: 1505346949

View file

@ -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);
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 54e6f853237cbe244b9d890b2a1eba6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6a2fb414d26e54be1a6cc2b4d6aa4b1f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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>();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ca28a7e4d7fc7644a99f49e5a48574dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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();
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e0a5780bf979b06409897f2eb2c23c13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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);
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6b4148bd86961c24c8ccbdb3462dfd80
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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);
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e06ae0cdd5cae6d48a9e8ea6519840f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dd9ae74f463480e49a2f6f1ed7f7fb2e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,3 @@
namespace UnityEditor.ShaderGraph
{
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c3e00256415a816419b39d61b3bf8451
timeCreated: 1465559572
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
namespace UnityEditor.ShaderGraph
{
interface IMaterialSlotHasValue<T>
{
T defaultValue { get; }
T value { get; }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94492244ef44a2e48b3e7790d7ac681d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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
};
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c8591c94b6db465586cce42a9bd2a399
timeCreated: 1601468048

View file

@ -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;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7d998d7fbd75b97459f63fb4931d14b5
timeCreated: 1463560120
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4cba4fbdefbdfa04cb2f6f84376a1353
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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);
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0755d7f7a7e11cb4294563bbd0d434cc
timeCreated: 1505346935

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5afbdbfda75b8c24ab4c07b8b3deddbe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,66 @@
using System;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Serializable]
[BlackboardInputInfo(71)]
class Matrix3ShaderProperty : MatrixShaderProperty
{
public Matrix3ShaderProperty()
{
displayName = "Matrix3x3";
value = Matrix4x4.identity;
}
public override PropertyType propertyType => PropertyType.Matrix3;
internal override string GetPropertyAsArgumentString(string precisionString)
{
return $"{precisionString}3x3 {referenceName}";
}
internal override AbstractMaterialNode ToConcreteNode()
{
return new Matrix3Node
{
row0 = new Vector3(value.m00, value.m01, value.m02),
row1 = new Vector3(value.m10, value.m11, value.m12),
row2 = new Vector3(value.m20, value.m21, value.m22)
};
}
internal override PreviewProperty GetPreviewMaterialProperty()
{
return new PreviewProperty(propertyType)
{
name = referenceName,
matrixValue = value
};
}
internal override ShaderInput Copy()
{
return new Matrix3ShaderProperty()
{
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);
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 95c9c50f50c70c8479180b855a3bd255
timeCreated: 1505346935

View file

@ -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 Matrix4MaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4>
{
[SerializeField]
private Matrix4x4 m_Value = Matrix4x4.identity;
[SerializeField]
private Matrix4x4 m_DefaultValue = Matrix4x4.identity;
public Matrix4MaterialSlot()
{
}
public Matrix4MaterialSlot(
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 "$precision4x4 (1,0,0,0,0,1,0,0,0,0,1,0,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 Matrix4ShaderProperty()
{
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.Matrix4)
{
name = name,
matrixValue = value
};
properties.Add(pp);
}
public override SlotValueType valueType { get { return SlotValueType.Matrix4; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix4; } }
public override void CopyValuesFrom(MaterialSlot foundSlot)
{
var slot = foundSlot as Matrix4MaterialSlot;
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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 69e137d338a024949b0a96921f86ee50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,67 @@
using System;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Serializable]
[BlackboardInputInfo(72)]
class Matrix4ShaderProperty : MatrixShaderProperty
{
public Matrix4ShaderProperty()
{
displayName = "Matrix4x4";
value = Matrix4x4.identity;
}
public override PropertyType propertyType => PropertyType.Matrix4;
internal override string GetPropertyAsArgumentString(string precisionString)
{
return $"{precisionString}4x4 {referenceName}";
}
internal override AbstractMaterialNode ToConcreteNode()
{
return new Matrix4Node
{
row0 = new Vector4(value.m00, value.m01, value.m02, value.m03),
row1 = new Vector4(value.m10, value.m11, value.m12, value.m13),
row2 = new Vector4(value.m20, value.m21, value.m22, value.m23),
row3 = new Vector4(value.m30, value.m31, value.m32, value.m33)
};
}
internal override PreviewProperty GetPreviewMaterialProperty()
{
return new PreviewProperty(propertyType)
{
name = referenceName,
matrixValue = value
};
}
internal override ShaderInput Copy()
{
return new Matrix4ShaderProperty()
{
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);
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6379ce3fb15957343ba875d18f87efbc
timeCreated: 1505346935

View file

@ -0,0 +1,42 @@
using System;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
abstract class MatrixShaderProperty : AbstractShaderProperty<Matrix4x4>
{
internal override bool isExposable => false;
internal override bool isRenamable => true;
internal override string GetHLSLVariableName(bool isSubgraphProperty, GenerationMode mode)
{
HLSLDeclaration decl = GetDefaultHLSLDeclaration();
if (decl == HLSLDeclaration.HybridPerInstance)
return $"UNITY_ACCESS_HYBRID_INSTANCED_PROP({referenceName}, {concretePrecision.ToShaderString()}4x4)";
else
return base.GetHLSLVariableName(isSubgraphProperty, mode);
}
internal override HLSLDeclaration GetDefaultHLSLDeclaration()
{
if (overrideHLSLDeclaration)
return hlslDeclarationOverride;
// Since Matrices cannot be exposed, the default declaration rules would set them to Global.
// However, this means new Matrix properties would be different from all other float-based property types
// (all others use UnityPerMaterial by default, because they are exposed).
// So instead, we override the default rules so that Matrices always default to UnityPerMaterial
return HLSLDeclaration.UnityPerMaterial;
}
internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
{
HLSLDeclaration decl = GetDefaultHLSLDeclaration();
// HLSL decl is always 4x4 even if matrix smaller
action(new HLSLProperty(HLSLType._matrix4x4, referenceName, decl, concretePrecision));
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 79075442664faac49b00b4c93d28e08b
timeCreated: 1505408377

View file

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Legacy;
using UnityEditor.ShaderGraph.Serialization;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
/// <summary>
/// Minimal version of <see cref="GraphData"/> used for gathering dependencies. This allows us to not deserialize
/// all the nodes, ports, edges, groups etc., which is important as we cannot share data between
/// <see cref="ShaderSubGraphImporter.GatherDependenciesFromSourceFile"/> and
/// <see cref="ShaderSubGraphImporter.OnImportAsset"/>. The latter must always import fully, but for the former we
/// want to avoid the extra GC pressure.
/// </summary>
[Serializable]
class MinimalGraphData
{
static Dictionary<string, Type> s_MinimalTypeMap = CreateMinimalTypeMap();
static Dictionary<string, Type> CreateMinimalTypeMap()
{
var types = new Dictionary<string, Type>();
foreach (var type in TypeCache.GetTypesWithAttribute<HasDependenciesAttribute>())
{
var dependencyAttribute = (HasDependenciesAttribute)type.GetCustomAttributes(typeof(HasDependenciesAttribute), false)[0];
if (!typeof(IHasDependencies).IsAssignableFrom(dependencyAttribute.minimalType))
{
Debug.LogError($"{type} must implement {typeof(IHasDependencies)} to be used in {typeof(HasDependenciesAttribute)}");
continue;
}
types.Add(type.FullName, dependencyAttribute.minimalType);
var formerNameAttributes = (FormerNameAttribute[])type.GetCustomAttributes(typeof(FormerNameAttribute), false);
foreach (var formerNameAttribute in formerNameAttributes)
{
types.Add(formerNameAttribute.fullName, dependencyAttribute.minimalType);
}
}
return types;
}
[SerializeField]
List<SerializationHelper.JSONSerializedElement> m_SerializableNodes = new List<SerializationHelper.JSONSerializedElement>();
// gather all asset dependencies declared by nodes in the given (shadergraph or shadersubgraph) asset
// by reading the source file from disk, and doing a minimal parse
// returns true if it successfully gathered the dependencies, false if there was an error
public static bool GatherMinimalDependenciesFromFile(string assetPath, AssetCollection assetCollection)
{
var textGraph = FileUtilities.SafeReadAllText(assetPath);
// if we can't read the file, no dependencies can be gathered
if (string.IsNullOrEmpty(textGraph))
return false;
var entries = MultiJsonInternal.Parse(textGraph);
if (string.IsNullOrWhiteSpace(entries[0].type))
{
var minimalGraphData = JsonUtility.FromJson<MinimalGraphData>(textGraph);
entries.Clear();
foreach (var node in minimalGraphData.m_SerializableNodes)
{
entries.Add(new MultiJsonEntry(node.typeInfo.fullName, null, node.JSONnodeData));
AbstractMaterialNode0 amn = new AbstractMaterialNode0();
JsonUtility.FromJsonOverwrite(node.JSONnodeData, amn);
foreach (var slot in amn.m_SerializableSlots)
{
entries.Add(new MultiJsonEntry(slot.typeInfo.fullName, null, slot.JSONnodeData));
}
}
}
foreach (var entry in entries)
{
if (s_MinimalTypeMap.TryGetValue(entry.type, out var minimalType))
{
var instance = (IHasDependencies)Activator.CreateInstance(minimalType);
JsonUtility.FromJsonOverwrite(entry.json, instance);
instance.GetSourceAssetDependencies(assetCollection);
}
}
return true;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d42a0735e4fa4df40bb0c0dcdbfeaf5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,36 @@
using System;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph
{
[Serializable]
class NormalMaterialSlot : SpaceMaterialSlot, IMayRequireNormal
{
public NormalMaterialSlot()
{ }
public NormalMaterialSlot(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.Normal));
}
public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability)
{
if (isConnected)
return NeededCoordinateSpace.None;
return space.ToNeededCoordinateSpace();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 08969711a3defe445a6803416d676b5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,12 @@
using System;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
struct ParentGroupChange
{
public IGroupItem groupItem;
public GroupData oldGroup;
public GroupData newGroup;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58e407e9c8cef1b4d9d68b73a421984c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,36 @@
using System;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph
{
[Serializable]
class PositionMaterialSlot : SpaceMaterialSlot, IMayRequirePosition
{
public PositionMaterialSlot()
{ }
public PositionMaterialSlot(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.Position));
}
public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability)
{
if (isConnected)
return NeededCoordinateSpace.None;
return space.ToNeededCoordinateSpace();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0612806deec2f154587fad5a1f7b060a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
namespace UnityEditor.ShaderGraph
{
enum PreviewMode
{
Inherit, // this usually means: 2D, unless a connected input node is 3D, in which case it is 3D
Preview2D,
Preview3D
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 084b4ac1c80bf4746bb42f8d424c058f
timeCreated: 1463576280
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,289 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
struct PreviewProperty
{
public string name { get; set; }
public PropertyType propType { get; private set; }
public PreviewProperty(PropertyType type) : this()
{
propType = type;
}
[StructLayout(LayoutKind.Explicit)]
struct ClassData
{
[FieldOffset(0)]
public Texture textureValue;
[FieldOffset(0)]
public Cubemap cubemapValue;
[FieldOffset(0)]
public Gradient gradientValue;
[FieldOffset(0)]
public VirtualTextureShaderProperty vtProperty;
}
[StructLayout(LayoutKind.Explicit)]
struct StructData
{
[FieldOffset(0)]
public Color colorValue;
[FieldOffset(0)]
public Vector4 vector4Value;
[FieldOffset(0)]
public float floatValue;
[FieldOffset(0)]
public bool booleanValue;
[FieldOffset(0)]
public Matrix4x4 matrixValue;
}
ClassData m_ClassData;
StructData m_StructData;
Texture2DShaderProperty.DefaultType m_texture2dDefaultType;
public Color colorValue
{
get
{
if (propType != PropertyType.Color)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Color, propType));
return m_StructData.colorValue;
}
set
{
if (propType != PropertyType.Color)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Color, propType));
m_StructData.colorValue = value;
}
}
public Texture textureValue
{
get
{
if (propType != PropertyType.Texture2D && propType != PropertyType.Texture2DArray && propType != PropertyType.Texture3D)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Texture2D, propType));
return m_ClassData.textureValue;
}
set
{
if (propType != PropertyType.Texture2D && propType != PropertyType.Texture2DArray && propType != PropertyType.Texture3D)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Texture2D, propType));
m_ClassData.textureValue = value;
}
}
public Texture2DShaderProperty.DefaultType texture2DDefaultType
{
get
{
if (propType != PropertyType.Texture2D)
throw new ArgumentException(string.Format(k_GetErrorMessage, "Texture2DShaderProperty.DefaultType", propType));
return m_texture2dDefaultType;
}
set
{
if (propType != PropertyType.Texture2D)
throw new ArgumentException(string.Format(k_GetErrorMessage, "Texture2DShaderProperty.DefaultType", propType));
m_texture2dDefaultType = value;
}
}
public Cubemap cubemapValue
{
get
{
if (propType != PropertyType.Cubemap)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Cubemap, propType));
return m_ClassData.cubemapValue;
}
set
{
if (propType != PropertyType.Cubemap)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Cubemap, propType));
m_ClassData.cubemapValue = value;
}
}
public Gradient gradientValue
{
get
{
if (propType != PropertyType.Gradient)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Gradient, propType));
return m_ClassData.gradientValue;
}
set
{
if (propType != PropertyType.Gradient)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Gradient, propType));
m_ClassData.gradientValue = value;
}
}
public VirtualTextureShaderProperty vtProperty
{
get
{
if (propType != PropertyType.VirtualTexture)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Gradient, propType));
return m_ClassData.vtProperty;
}
set
{
if (propType != PropertyType.VirtualTexture)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Gradient, propType));
m_ClassData.vtProperty = value;
}
}
public Vector4 vector4Value
{
get
{
if (propType != PropertyType.Vector2 && propType != PropertyType.Vector3 && propType != PropertyType.Vector4)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Vector4, propType));
return m_StructData.vector4Value;
}
set
{
if (propType != PropertyType.Vector2 && propType != PropertyType.Vector3 && propType != PropertyType.Vector4
&& propType != PropertyType.Matrix2 && propType != PropertyType.Matrix3 && propType != PropertyType.Matrix4)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Vector4, propType));
m_StructData.vector4Value = value;
}
}
public float floatValue
{
get
{
if (propType != PropertyType.Float)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Float, propType));
return m_StructData.floatValue;
}
set
{
if (propType != PropertyType.Float)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Float, propType));
m_StructData.floatValue = value;
}
}
public bool booleanValue
{
get
{
if (propType != PropertyType.Boolean)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Boolean, propType));
return m_StructData.booleanValue;
}
set
{
if (propType != PropertyType.Boolean)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Boolean, propType));
m_StructData.booleanValue = value;
}
}
public Matrix4x4 matrixValue
{
get
{
if (propType != PropertyType.Matrix2 && propType != PropertyType.Matrix3 && propType != PropertyType.Matrix4)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Boolean, propType));
return m_StructData.matrixValue;
}
set
{
if (propType != PropertyType.Matrix2 && propType != PropertyType.Matrix3 && propType != PropertyType.Matrix4)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Boolean, propType));
m_StructData.matrixValue = value;
}
}
const string k_SetErrorMessage = "Cannot set a {0} property on a PreviewProperty with type {1}.";
const string k_GetErrorMessage = "Cannot get a {0} property on a PreviewProperty with type {1}.";
public void SetValueOnMaterialPropertyBlock(MaterialPropertyBlock mat)
{
if ((propType == PropertyType.Texture2D || propType == PropertyType.Texture2DArray || propType == PropertyType.Texture3D))
{
if (m_ClassData.textureValue == null)
{
// there's no way to set the texture back to NULL
// and no way to delete the property either
// so instead we set the value to what we know the default will be
// (all textures in ShaderGraph default to white)
switch (m_texture2dDefaultType)
{
case Texture2DShaderProperty.DefaultType.White:
mat.SetTexture(name, Texture2D.whiteTexture);
break;
case Texture2DShaderProperty.DefaultType.Black:
mat.SetTexture(name, Texture2D.blackTexture);
break;
case Texture2DShaderProperty.DefaultType.Grey:
mat.SetTexture(name, Texture2D.grayTexture);
break;
case Texture2DShaderProperty.DefaultType.NormalMap:
mat.SetTexture(name, Texture2D.normalTexture);
break;
case Texture2DShaderProperty.DefaultType.LinearGrey:
mat.SetTexture(name, Texture2D.linearGrayTexture);
break;
case Texture2DShaderProperty.DefaultType.Red:
mat.SetTexture(name, Texture2D.redTexture);
break;
}
}
else
mat.SetTexture(name, m_ClassData.textureValue);
}
else if (propType == PropertyType.Cubemap)
{
if (m_ClassData.cubemapValue == null)
{
// there's no way to set the texture back to NULL
// and no way to delete the property either
// so instead we set the value to what we know the default will be
// (all textures in ShaderGraph default to white)
// there's no Cubemap.whiteTexture, but this seems to work
mat.SetTexture(name, Texture2D.whiteTexture);
}
else
mat.SetTexture(name, m_ClassData.cubemapValue);
}
else if (propType == PropertyType.Color)
mat.SetColor(name, m_StructData.colorValue);
else if (propType == PropertyType.Vector2 || propType == PropertyType.Vector3 || propType == PropertyType.Vector4)
mat.SetVector(name, m_StructData.vector4Value);
else if (propType == PropertyType.Float)
mat.SetFloat(name, m_StructData.floatValue);
else if (propType == PropertyType.Boolean)
mat.SetFloat(name, m_StructData.booleanValue ? 1 : 0);
else if (propType == PropertyType.Matrix2 || propType == PropertyType.Matrix3 || propType == PropertyType.Matrix4)
mat.SetMatrix(name, m_StructData.matrixValue);
else if (propType == PropertyType.Gradient)
{
mat.SetFloat(string.Format("{0}_Type", name), (int)m_ClassData.gradientValue.mode);
mat.SetFloat(string.Format("{0}_ColorsLength", name), m_ClassData.gradientValue.colorKeys.Length);
mat.SetFloat(string.Format("{0}_AlphasLength", name), m_ClassData.gradientValue.alphaKeys.Length);
for (int i = 0; i < 8; i++)
mat.SetVector(string.Format("{0}_ColorKey{1}", name, i), i < m_ClassData.gradientValue.colorKeys.Length ? GradientUtil.ColorKeyToVector(m_ClassData.gradientValue.colorKeys[i]) : Vector4.zero);
for (int i = 0; i < 8; i++)
mat.SetVector(string.Format("{0}_AlphaKey{1}", name, i), i < m_ClassData.gradientValue.alphaKeys.Length ? GradientUtil.AlphaKeyToVector(m_ClassData.gradientValue.alphaKeys[i]) : Vector2.zero);
}
else if (propType == PropertyType.VirtualTexture)
{
// virtual texture assignments are not supported via the material property block, we must assign them to the materials
}
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b61922288469cb5438e9b4118b11a4d9
timeCreated: 1463576280
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,76 @@
using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph
{
[Serializable]
class PropertyConnectionStateMaterialSlot : MaterialSlot, IMaterialSlotHasValue<bool>
{
public PropertyConnectionStateMaterialSlot()
{ }
public PropertyConnectionStateMaterialSlot(
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 PropertyConnectionStateSlotControlView(this);
}
protected override string ConcreteSlotValueAsVariable()
{
// This is a funky slot, that doesn't directly hold a value.
return "false";
}
public bool defaultValue
{
// This is a funky slot, that doesn't directly hold a value.
get { return false; }
}
public bool value
{
// This is a funky slot, that doesn't directly hold a value.
get { return false; }
}
public override bool isDefaultValue => true;
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
if (owner == 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 = owner.GetVariableNameForSlot(id),
generatePropertyBlock = false,
value = isConnected
};
properties.AddShaderProperty(property);
}
public override SlotValueType valueType { get { return SlotValueType.PropertyConnectionState; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.PropertyConnectionState; } }
public override void CopyValuesFrom(MaterialSlot foundSlot)
{
// This is a funky slot, that doesn't directly hold a value.
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aca882b159c67ee488d0f3ce6b7f9494
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,94 @@
using System;
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
class SamplerStateMaterialSlot : MaterialSlot
{
public SamplerStateMaterialSlot()
{
}
public SamplerStateMaterialSlot(
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; }
}
// NOT serialized -- this is always set by the parent node if they care about it
public TextureSamplerState defaultSamplerState { get; set; }
public string defaultSamplerStateName => defaultSamplerState?.defaultPropertyName ?? "SamplerState_Linear_Repeat";
public override void AppendHLSLParameterDeclaration(ShaderStringBuilder sb, string paramName)
{
if (m_BareResource)
{
// we have to use our modified macro declaration here, to ensure that something is declared for GLES2 platforms
// (the standard SAMPLER macro doesn't declare anything, so the commas will be messed up in the parameter list)
sb.Append("UNITY_BARE_SAMPLER(");
sb.Append(paramName);
sb.Append(")");
}
else
base.AppendHLSLParameterDeclaration(sb, paramName);
}
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 $"UnityBuildSamplerStateStruct({defaultSamplerStateName})";
}
public override SlotValueType valueType { get { return SlotValueType.SamplerState; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.SamplerState; } }
public override bool isDefaultValue => true;
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)));
properties.AddShaderProperty(new SamplerStateShaderProperty()
{
value = defaultSamplerState ?? new TextureSamplerState()
{
filter = TextureSamplerState.FilterMode.Linear,
wrap = TextureSamplerState.WrapMode.Repeat
},
overrideReferenceName = defaultSamplerStateName,
generatePropertyBlock = false,
});
}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{ }
public override void CopyDefaultValue(MaterialSlot other)
{
base.CopyDefaultValue(other);
if (other is SamplerStateMaterialSlot ms)
{
defaultSamplerState = ms.defaultSamplerState;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 095dad16f79a37b4d9aba1e9c31691f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,91 @@
using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[BlackboardInputInfo(80)]
class SamplerStateShaderProperty : AbstractShaderProperty<TextureSamplerState>
{
public SamplerStateShaderProperty()
{
displayName = "SamplerState";
value = new TextureSamplerState();
}
public override PropertyType propertyType => PropertyType.SamplerState;
// Sampler States cannot be exposed on a Material
internal override bool isExposable => false;
// subgraph Sampler States can be renamed
// just the actual properties they create will always have fixed names
internal override bool isRenamable => true;
internal override bool isReferenceRenamable => false;
// this is the fixed naming scheme for actual samplerstates properties
string propertyReferenceName => value.defaultPropertyName;
public override string referenceNameForEditing => propertyReferenceName;
internal override bool AllowHLSLDeclaration(HLSLDeclaration decl) => false; // disable UI, nothing to choose
internal override void ForeachHLSLProperty(Action<HLSLProperty> action)
{
action(new HLSLProperty(HLSLType._SamplerState, propertyReferenceName, HLSLDeclaration.Global));
}
internal override string GetPropertyAsArgumentString(string precisionString)
{
return $"UnitySamplerState {referenceName}";
}
internal override string GetHLSLVariableName(bool isSubgraphProperty, GenerationMode mode)
{
if (isSubgraphProperty)
return referenceName;
else
return $"UnityBuildSamplerStateStruct({propertyReferenceName})";
}
internal override AbstractMaterialNode ToConcreteNode()
{
return new SamplerStateNode()
{
filter = value.filter,
wrap = value.wrap
};
}
internal override PreviewProperty GetPreviewMaterialProperty()
{
return default(PreviewProperty);
}
internal override ShaderInput Copy()
{
return new SamplerStateShaderProperty()
{
displayName = displayName,
value = value,
};
}
public override int latestVersion => 1;
public override void OnAfterDeserialize(string json)
{
if (sgVersion == 0)
{
// we no longer require forced reference names on sampler state properties
// as we enforce custom property naming by simply not using the reference name
// this allows us to use the real reference name for subgraph parameters
// however we must clear out the old reference name first (as it was always hard-coded)
// this will fallback to the default ref name
overrideReferenceName = null;
var unused = referenceName;
ChangeVersion(1);
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b48a2e97e3e24303833a0062f90f4f13
timeCreated: 1505436387

View file

@ -0,0 +1,55 @@
using System;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.ShaderGraph
{
[Serializable]
class ScreenPositionMaterialSlot : Vector4MaterialSlot, IMayRequireScreenPosition
{
[SerializeField]
ScreenSpaceType m_ScreenSpaceType;
public ScreenSpaceType screenSpaceType
{
get { return m_ScreenSpaceType; }
set { m_ScreenSpaceType = value; }
}
public override bool isDefaultValue => screenSpaceType == ScreenSpaceType.Default;
public ScreenPositionMaterialSlot()
{ }
public ScreenPositionMaterialSlot(int slotId, string displayName, string shaderOutputName, ScreenSpaceType screenSpaceType,
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, stageCapability, hidden: hidden)
{
this.screenSpaceType = screenSpaceType;
}
public override VisualElement InstantiateControl()
{
return new ScreenPositionSlotControlView(this);
}
public override string GetDefaultValue(GenerationMode generationMode)
{
return m_ScreenSpaceType.ToValueAsVariable();
}
public bool RequiresScreenPosition(ShaderStageCapability stageCapability)
{
return !isConnected;
}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{
var slot = foundSlot as ScreenPositionMaterialSlot;
if (slot != null)
screenSpaceType = slot.screenSpaceType;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20a329ed82797b8459cd7b6e22787f2e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,102 @@
using System;
using UnityEngine;
namespace UnityEditor.ShaderGraph.Internal
{
[Serializable]
public sealed class SerializableCubemap : ISerializationCallbackReceiver
{
[SerializeField]
string m_SerializedCubemap;
[SerializeField]
string m_Guid;
[NonSerialized]
Cubemap m_Cubemap;
[Serializable]
class CubemapHelper
{
#pragma warning disable 649
public Cubemap cubemap;
#pragma warning restore 649
}
// used to get a Cubemap ref guid without loading the cubemap asset itself into memory
[Serializable]
class MinimalCubemapHelper
{
// these variables are only ever populated by serialization, disable the C# warning that checks if they are ever assigned
#pragma warning disable 0649
[Serializable]
public struct MinimalTextureRef
{
public string guid;
}
public MinimalTextureRef cubemap;
#pragma warning restore 0649
}
internal string guid
{
get
{
if (!string.IsNullOrEmpty(m_SerializedCubemap))
{
var textureHelper = new MinimalCubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, textureHelper);
if (!string.IsNullOrEmpty(textureHelper.cubemap.guid))
return textureHelper.cubemap.guid;
}
if (!string.IsNullOrEmpty(m_Guid))
{
return m_Guid;
}
if (m_Cubemap != null)
{
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(m_Cubemap, out string guid, out long localId))
return guid;
}
return null;
}
}
public Cubemap cubemap
{
get
{
if (!string.IsNullOrEmpty(m_SerializedCubemap))
{
var textureHelper = new CubemapHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedCubemap, textureHelper);
m_SerializedCubemap = null;
m_Guid = null;
m_Cubemap = textureHelper.cubemap;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_Cubemap == null)
{
m_Cubemap = AssetDatabase.LoadAssetAtPath<Cubemap>(AssetDatabase.GUIDToAssetPath(m_Guid));
m_Guid = null;
}
return m_Cubemap;
}
set
{
m_Cubemap = value;
m_Guid = null;
m_SerializedCubemap = null;
}
}
public void OnBeforeSerialize()
{
m_SerializedCubemap = EditorJsonUtility.ToJson(new CubemapHelper { cubemap = cubemap }, false);
}
public void OnAfterDeserialize()
{
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 01e80e004e94f5e48ad1cb83d5701300
timeCreated: 1505346945

View file

@ -0,0 +1,44 @@
using System;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
class SerializableGuid : ISerializationCallbackReceiver
{
public SerializableGuid()
{
m_Guid = Guid.NewGuid();
}
public SerializableGuid(Guid guid)
{
m_Guid = guid;
}
[NonSerialized]
private Guid m_Guid;
[SerializeField]
private string m_GuidSerialized;
public Guid guid
{
get { return m_Guid; }
internal set { m_Guid = value; } // allow id to be overwritten when necessary
}
public virtual void OnBeforeSerialize()
{
m_GuidSerialized = m_Guid.ToString();
}
public virtual void OnAfterDeserialize()
{
if (!string.IsNullOrEmpty(m_GuidSerialized))
m_Guid = new Guid(m_GuidSerialized);
else
m_Guid = Guid.NewGuid();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fb9a23efd2bc46e9a5e34bf5ff0c9768
timeCreated: 1507479217

View file

@ -0,0 +1,63 @@
using System;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
class SerializableMesh : ISerializationCallbackReceiver
{
[SerializeField]
string m_SerializedMesh;
[SerializeField]
string m_Guid;
[NonSerialized]
Mesh m_Mesh;
[Serializable]
class MeshHelper
{
#pragma warning disable 649
public Mesh mesh;
#pragma warning restore 649
}
public Mesh mesh
{
get
{
if (!string.IsNullOrEmpty(m_SerializedMesh))
{
var textureHelper = new MeshHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedMesh, textureHelper);
m_SerializedMesh = null;
m_Guid = null;
m_Mesh = textureHelper.mesh;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_Mesh == null)
{
m_Mesh = AssetDatabase.LoadAssetAtPath<Mesh>(AssetDatabase.GUIDToAssetPath(m_Guid));
m_Guid = null;
}
return m_Mesh;
}
set
{
m_Mesh = value;
m_Guid = null;
m_SerializedMesh = null;
}
}
public void OnBeforeSerialize()
{
m_SerializedMesh = EditorJsonUtility.ToJson(new MeshHelper { mesh = mesh }, false);
}
public void OnAfterDeserialize()
{
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 944c4fc9d004e7845adb3f86843ab742
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