浏览代码

Merge pull request #1377 from Unity-Technologies/sg/texture-types

Texture2D Array and Texture 3D
/main
GitHub 6 年前
当前提交
f8e5ff57
共有 58 个文件被更改,包括 1315 次插入29 次删除
  1. 24
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs
  2. 12
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/PreviewProperty.cs
  3. 2
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs
  4. 6
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/TextureShaderProperty.cs
  5. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs
  6. 14
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/CodeFunctionNode.cs
  7. 15
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/PropertyNode.cs
  8. 2
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture2DAssetNode.cs
  9. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/PropertyType.cs
  10. 6
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/SlotValue.cs
  11. 30
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Utility/SubGraphNode.cs
  12. 1
      ShaderGraph/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs
  13. 28
      ShaderGraph/com.unity.shadergraph/Editor/Data/Util/PropertyCollector.cs
  14. 22
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardFieldPropertyView.cs
  15. 4
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs
  16. 4
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/DefaultControl.cs
  17. 6
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs
  18. 34
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs
  19. 6
      ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/PortInputView.uss
  20. 10
      ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/ShaderPort.uss
  21. 53
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/SerializableTextureArray.cs
  22. 3
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/SerializableTextureArray.cs.meta
  23. 79
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayInputMaterialSlot.cs
  24. 3
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayInputMaterialSlot.cs.meta
  25. 31
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayMaterialSlot.cs
  26. 11
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayMaterialSlot.cs.meta
  27. 84
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayShaderProperty.cs
  28. 3
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayShaderProperty.cs.meta
  29. 79
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DInputMaterialSlot.cs
  30. 3
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DInputMaterialSlot.cs.meta
  31. 31
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DMaterialSlot.cs
  32. 11
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DMaterialSlot.cs.meta
  33. 84
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DShaderProperty.cs
  34. 3
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DShaderProperty.cs.meta
  35. 97
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture2DArrayNode.cs
  36. 12
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture2DArrayNode.cs.meta
  37. 63
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture3DNode.cs
  38. 12
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture3DNode.cs.meta
  39. 78
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture2DArrayAssetNode.cs
  40. 11
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture2DArrayAssetNode.cs.meta
  41. 78
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture3DAssetNode.cs
  42. 11
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture3DAssetNode.cs.meta
  43. 53
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/Texture3DControl.cs
  44. 11
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/Texture3DControl.cs.meta
  45. 53
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/TextureArrayControl.cs
  46. 11
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/TextureArrayControl.cs.meta
  47. 34
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/Slots/Texture3DSlotControlView.cs
  48. 3
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/Slots/Texture3DSlotControlView.cs.meta
  49. 34
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/Slots/TextureArraySlotControlView.cs
  50. 3
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/Slots/TextureArraySlotControlView.cs.meta
  51. 12
      ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/Controls/Texture3DSlotControlView.uss
  52. 10
      ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/Controls/Texture3DSlotControlView.uss.meta
  53. 12
      ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/Controls/TextureArraySlotControlView.uss
  54. 10
      ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/Controls/TextureArraySlotControlView.uss.meta
  55. 8
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes.meta
  56. 8
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting.meta
  57. 8
      Tests/Scripts/GraphicTests/HDRenderPipeline.meta

24
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs


case ConcreteSlotValueType.SamplerState:
return "(SS)";
case ConcreteSlotValueType.Texture2D:
return "(T)";
return "(T2)";
case ConcreteSlotValueType.Texture2DArray:
return "(T2A)";
case ConcreteSlotValueType.Texture3D:
return "(T3)";
case ConcreteSlotValueType.Cubemap:
return "(C)";
case ConcreteSlotValueType.Gradient:

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)

|| inputType == SlotValueType.Dynamic;
case SlotValueType.Texture2D:
return inputType == SlotValueType.Texture2D;
case SlotValueType.Texture2DArray:
return inputType == SlotValueType.Texture2DArray;
case SlotValueType.Texture3D:
return inputType == SlotValueType.Texture3D;
case SlotValueType.Cubemap:
return inputType == SlotValueType.Cubemap;
case SlotValueType.Gradient:

switch (slotValue)
{
case ConcreteSlotValueType.Texture2D:
return PropertyType.Texture;
return PropertyType.Texture2D;
case ConcreteSlotValueType.Texture2DArray:
return PropertyType.Texture2DArray;
case ConcreteSlotValueType.Texture3D:
return PropertyType.Texture3D;
case ConcreteSlotValueType.Cubemap:
return PropertyType.Cubemap;
case ConcreteSlotValueType.Gradient:

12
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/PreviewProperty.cs


{
get
{
if (propType != PropertyType.Texture)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Texture, propType));
if (propType != PropertyType.Texture2D && propType != PropertyType.Texture2DArray && propType != PropertyType.Texture3D)
throw new ArgumentException(string.Format(k_GetErrorMessage, PropertyType.Texture2D, propType));
if (propType != PropertyType.Texture)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Texture, propType));
if (propType != PropertyType.Texture2D && propType != PropertyType.Texture2DArray && propType != PropertyType.Texture3D)
throw new ArgumentException(string.Format(k_SetErrorMessage, PropertyType.Texture2D, propType));
m_Data.textureValue = value;
}
}

}
set
{
if (propType != PropertyType.Vector2 && propType != PropertyType.Vector3 && propType != PropertyType.Vector4
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_Data.vector4Value = value;

public void SetMaterialPropertyBlockValue(MaterialPropertyBlock block)
{
if (propType == PropertyType.Texture && textureValue != null)
if ((propType == PropertyType.Texture2D || propType == PropertyType.Texture2DArray || propType == PropertyType.Texture3D) && textureValue != null)
block.SetTexture(name, m_Data.textureValue);
else if (propType == PropertyType.Cubemap && cubemapValue != null)
block.SetTexture(name, m_Data.cubemapValue);

2
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs


public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
{
var pp = new PreviewProperty(PropertyType.Texture)
var pp = new PreviewProperty(PropertyType.Texture2D)
{
name = name,
textureValue = texture,

6
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/TextureShaderProperty.cs


public TextureShaderProperty()
{
value = new SerializableTexture();
displayName = "Texture";
displayName = "Texture2D";
get { return PropertyType.Texture; }
get { return PropertyType.Texture2D; }
}
public bool modifiable

public override PreviewProperty GetPreviewMaterialProperty()
{
return new PreviewProperty(PropertyType.Texture)
return new PreviewProperty(PropertyType.Texture2D)
{
name = referenceName,
textureValue = value.texture

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs


return p + "4";
case ConcreteSlotValueType.Texture2D:
return "Texture2D";
case ConcreteSlotValueType.Texture2DArray:
return "Texture2DArray";
case ConcreteSlotValueType.Texture3D:
return "Texture3D";
case ConcreteSlotValueType.Cubemap:
return "Cubemap";
case ConcreteSlotValueType.Gradient:

14
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/CodeFunctionNode.cs


protected struct Texture2D
{}
protected struct Texture2DArray
{}
protected struct Texture3D
{}
protected struct SamplerState
{}

if (t == typeof(Texture2D))
{
return SlotValueType.Texture2D;
}
if (t == typeof(Texture2DArray))
{
return SlotValueType.Texture2DArray;
}
if (t == typeof(Texture3D))
{
return SlotValueType.Texture3D;
}
if (t == typeof(Cubemap))
{

15
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/PropertyNode.cs


AddSlot(new Texture2DMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] {OutputSlotId});
}
else if (property is Texture2DArrayShaderProperty)
{
AddSlot(new Texture2DArrayMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] {OutputSlotId});
}
else if (property is Texture3DShaderProperty)
{
AddSlot(new Texture3DMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] {OutputSlotId});
}
else if (property is CubemapShaderProperty)
{
AddSlot(new CubemapMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));

var graph = owner as AbstractMaterialGraph;
var property = graph.properties.FirstOrDefault(x => x.guid == propertyGuid);
if (!(property is TextureShaderProperty) && !(property is CubemapShaderProperty))
if (!(property is TextureShaderProperty) &&
!(property is Texture2DArrayShaderProperty) &&
!(property is Texture3DShaderProperty) &&
!(property is CubemapShaderProperty))
return base.GetVariableNameForSlot(slotId);
return property.referenceName;

2
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture2DAssetNode.cs


public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Texture)
properties.Add(new PreviewProperty(PropertyType.Texture2D)
{
name = GetVariableNameForSlot(OutputSlotId),
textureValue = texture

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/PropertyType.cs


public enum PropertyType
{
Color,
Texture,
Texture2D,
Texture2DArray,
Texture3D,
Cubemap,
Gradient,
Boolean,

6
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/SlotValue.cs


Matrix3,
Matrix2,
Texture2D,
Texture2DArray,
Texture3D,
Cubemap,
Gradient,
DynamicVector,

Matrix3,
Matrix2,
Texture2D,
Texture2DArray,
Texture3D,
Cubemap,
Gradient,
Vector4,

"typeMatrix",
"typeMatrix",
"typeTexture2D",
"typeTexture2DArray",
"typeTexture3D",
"typeCubemap",
"typeGradient",
"typeFloat4",

30
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Utility/SubGraphNode.cs


if (prop is TextureShaderProperty)
arguments.Add(string.Format("TEXTURE2D_PARAM({0}, sampler{0})", GetSlotValue(inSlotId, generationMode)));
if (prop is Texture2DArrayShaderProperty)
arguments.Add(string.Format("TEXTURE2D_PARAM({0}, sampler{0})", GetSlotValue(inSlotId, generationMode)));
if (prop is Texture3DShaderProperty)
arguments.Add(string.Format("TEXTURE3D_PARAM({0}, sampler{0})", GetSlotValue(inSlotId, generationMode)));
else if (prop is CubemapShaderProperty)
arguments.Add(string.Format("TEXTURECUBE_PARAM({0}, sampler{0})", GetSlotValue(inSlotId, generationMode)));
else

case PropertyType.Color:
slotType = SlotValueType.Vector4;
break;
case PropertyType.Texture:
case PropertyType.Texture2D:
case PropertyType.Texture2DArray:
slotType = SlotValueType.Texture2DArray;
break;
case PropertyType.Texture3D:
slotType = SlotValueType.Texture3D;
break;
case PropertyType.Cubemap:
slotType = SlotValueType.Cubemap;
break;

var id = prop.guid.GetHashCode();
MaterialSlot slot = MaterialSlot.CreateMaterialSlot(slotType, id, prop.displayName, prop.referenceName, SlotType.Input, prop.defaultValue, ShaderStageCapability.Fragment);
// copy default for texture for niceness
if (slotType == SlotValueType.Texture2D && propType == PropertyType.Texture)
if (slotType == SlotValueType.Texture2D && propType == PropertyType.Texture2D)
if (tSlot != null && tProp != null)
tSlot.texture = tProp.value.texture;
}
// copy default for texture array for niceness
else if (slotType == SlotValueType.Texture2DArray && propType == PropertyType.Texture2DArray)
{
var tSlot = slot as Texture2DArrayInputMaterialSlot;
var tProp = prop as Texture2DArrayShaderProperty;
if (tSlot != null && tProp != null)
tSlot.textureArray = tProp.value.textureArray;
}
// copy default for texture 3d for niceness
else if (slotType == SlotValueType.Texture3D && propType == PropertyType.Texture3D)
{
var tSlot = slot as Texture3DInputMaterialSlot;
var tProp = prop as Texture3DShaderProperty;
if (tSlot != null && tProp != null)
tSlot.texture = tProp.value.texture;
}

1
ShaderGraph/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs


using UnityEditor.Graphing.Util;
using UnityEngine;
using System.Reflection;
using System.Text.RegularExpressions;
namespace UnityEditor.ShaderGraph
{

28
ShaderGraph/com.unity.shadergraph/Editor/Data/Util/PropertyCollector.cs


}
}
foreach (var prop in m_Properties.OfType<Texture2DArrayShaderProperty>())
{
if (prop.referenceName != null)
{
var textureInfo = new TextureInfo
{
name = prop.referenceName,
textureId = prop.value.textureArray != null ? prop.value.textureArray.GetInstanceID() : 0,
modifiable = prop.modifiable
};
result.Add(textureInfo);
}
}
foreach (var prop in m_Properties.OfType<Texture3DShaderProperty>())
{
if (prop.referenceName != null)
{
var textureInfo = new TextureInfo
{
name = prop.referenceName,
textureId = prop.value.texture != null ? prop.value.texture.GetInstanceID() : 0,
modifiable = prop.modifiable
};
result.Add(textureInfo);
}
}
foreach (var prop in m_Properties.OfType<CubemapShaderProperty>())
{
if (prop.referenceName != null)

22
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardFieldPropertyView.cs


});
AddRow("Default", field);
}
else if (property is Texture2DArrayShaderProperty)
{
var textureProperty = (Texture2DArrayShaderProperty)property;
var field = new ObjectField { value = textureProperty.value.textureArray, objectType = typeof(Texture2DArray) };
field.OnValueChanged(evt =>
{
textureProperty.value.textureArray = (Texture2DArray)evt.newValue;
DirtyNodes();
});
AddRow("Default", field);
}
else if (property is Texture3DShaderProperty)
{
var textureProperty = (Texture3DShaderProperty)property;
var field = new ObjectField { value = textureProperty.value.texture, objectType = typeof(Texture3D) };
field.OnValueChanged(evt =>
{
textureProperty.value.texture = (Texture3D)evt.newValue;
DirtyNodes();
});
AddRow("Default", field);
}
else if (property is CubemapShaderProperty)
{
var cubemapProperty = (CubemapShaderProperty)property;

4
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardProvider.cs


gm.AddItem(new GUIContent("Vector3"), false, () => AddProperty(new Vector3ShaderProperty(), true));
gm.AddItem(new GUIContent("Vector4"), false, () => AddProperty(new Vector4ShaderProperty(), true));
gm.AddItem(new GUIContent("Color"), false, () => AddProperty(new ColorShaderProperty(), true));
gm.AddItem(new GUIContent("Texture"), false, () => AddProperty(new TextureShaderProperty(), true));
gm.AddItem(new GUIContent("Texture2D"), false, () => AddProperty(new TextureShaderProperty(), true));
gm.AddItem(new GUIContent("Texture2D Array"), false, () => AddProperty(new Texture2DArrayShaderProperty(), true));
gm.AddItem(new GUIContent("Texture3D"), false, () => AddProperty(new Texture3DShaderProperty(), true));
gm.AddItem(new GUIContent("Cubemap"), false, () => AddProperty(new CubemapShaderProperty(), true));
gm.AddItem(new GUIContent("Boolean"), false, () => AddProperty(new BooleanShaderProperty(), true));
gm.ShowAsContext();

4
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/DefaultControl.cs


return new EnumControlView(null, node, propertyInfo);
if (propertyInfo.PropertyType == typeof(Texture2D))
return new TextureControlView(null, node, propertyInfo);
if (propertyInfo.PropertyType == typeof(Texture2DArray))
return new TextureArrayControlView(null, node, propertyInfo);
if (propertyInfo.PropertyType == typeof(Texture3D))
return new Texture3DControlView(null, node, propertyInfo);
if (MultiFloatControlView.validTypes.Contains(propertyInfo.PropertyType))
return new MultiFloatControlView(null, "X", "Y", "Z", "W", node, propertyInfo);
if (typeof(Object).IsAssignableFrom(propertyInfo.PropertyType))

6
ShaderGraph/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs


case ConcreteSlotValueType.Texture2D:
prop = new TextureShaderProperty();
break;
case ConcreteSlotValueType.Texture2DArray:
prop = new Texture2DArrayShaderProperty();
break;
case ConcreteSlotValueType.Texture3D:
prop = new Texture3DShaderProperty();
break;
case ConcreteSlotValueType.Cubemap:
prop = new CubemapShaderProperty();
break;

34
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs


static bool ValidateObjectForDrop(Object obj)
{
return EditorUtility.IsPersistent(obj) && (obj is Texture2D || obj is Cubemap || obj is MaterialSubGraphAsset);
return EditorUtility.IsPersistent(obj) && (obj is Texture2D || obj is Cubemap || obj is MaterialSubGraphAsset || obj is Texture2DArray || obj is Texture3D);
}
static void OnDragUpdatedEvent(DragUpdatedEvent e)

if (inputslot != null)
inputslot.texture = texture2D;
}
var textureArray = obj as Texture2DArray;
if (textureArray != null)
{
graph.owner.RegisterCompleteObjectUndo("Drag Texture Array");
var property = new Texture2DArrayShaderProperty { displayName = textureArray.name, value = { textureArray = textureArray } };
graph.AddShaderProperty(property);
var node = new SampleTexture2DArrayNode();
var drawState = node.drawState;
drawState.position = new Rect(nodePosition, drawState.position.size);
node.drawState = drawState;
graph.AddNode(node);
var inputslot = node.FindSlot<Texture2DArrayInputMaterialSlot>(SampleTexture2DArrayNode.TextureInputId);
if (inputslot != null)
inputslot.textureArray = textureArray;
}
var texture3D = obj as Texture3D;
if (texture3D != null)
{
graph.owner.RegisterCompleteObjectUndo("Drag Texture 3D");
var property = new Texture3DShaderProperty { displayName = texture3D.name, value = { texture = texture3D } };
graph.AddShaderProperty(property);
var node = new SampleTexture3DNode();
var drawState = node.drawState;
drawState.position = new Rect(nodePosition, drawState.position.size);
node.drawState = drawState;
graph.AddNode(node);
var inputslot = node.FindSlot<Texture3DInputMaterialSlot>(SampleTexture3DNode.TextureInputId);
if (inputslot != null)
inputslot.texture = texture3D;
}
var cubemap = obj as Cubemap;

6
ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/PortInputView.uss


edge-color: #8FC1DF;
}
PortInputView.typeTexture2D > #container > #slot > #dot,
PortInputView.typeTexture2D > #container > #slot > #dot,
PortInputView.typeTexture2DArray > #container > #slot > #dot,
PortInputView.typeTexture3D > #container > #slot > #dot,
PortInputView.typeTexture2DArray,
PortInputView.typeTexture3D,
PortInputView.typeCubemap {
edge-color: #FF8B8B;
}

10
ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/ShaderPort.uss


port-color:#FF8B8B;
}
ShaderPort.typeTexture2DArray {
/* Same as typeTexture */
port-color:#FF8B8B;
}
ShaderPort.typeTexture3D {
/* Same as typeTexture */
port-color:#FF8B8B;
}
ShaderPort.typeCubemap {
/* Same as typeTexture */
port-color:#FF8B8B;

53
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/SerializableTextureArray.cs


using System;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class SerializableTextureArray
{
[SerializeField]
string m_SerializedTexture;
[SerializeField]
string m_Guid;
[NonSerialized]
Texture2DArray m_TextureArray;
[Serializable]
class TextureHelper
{
#pragma warning disable 649
public Texture2DArray textureArray;
#pragma warning restore 649
}
public Texture2DArray textureArray
{
get
{
if (!string.IsNullOrEmpty(m_SerializedTexture))
{
var textureHelper = new TextureHelper();
EditorJsonUtility.FromJsonOverwrite(m_SerializedTexture, textureHelper);
m_SerializedTexture = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(textureHelper.textureArray));
m_TextureArray = textureHelper.textureArray;
}
else if (!string.IsNullOrEmpty(m_Guid) && m_TextureArray == null)
{
m_TextureArray = AssetDatabase.LoadAssetAtPath<Texture2DArray>(AssetDatabase.GUIDToAssetPath(m_Guid));
}
return m_TextureArray;
}
set
{
m_SerializedTexture = null;
m_Guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value));
m_TextureArray = value;
}
}
}
}

3
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/SerializableTextureArray.cs.meta


fileFormatVersion: 2
guid: d9807a630579843d5a2e956e776b0d3d
timeCreated: 1505346945

79
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayInputMaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class Texture2DArrayInputMaterialSlot : Texture2DArrayMaterialSlot
{
[SerializeField]
private SerializableTextureArray m_TextureArray = new SerializableTextureArray();
public Texture2DArray textureArray
{
get { return m_TextureArray.textureArray; }
set { m_TextureArray.textureArray = value; }
}
public Texture2DArrayInputMaterialSlot()
{}
public Texture2DArrayInputMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
ShaderStageCapability shaderStageCapability = ShaderStageCapability.All,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStageCapability, hidden)
{}
public override VisualElement InstantiateControl()
{
return new TextureArraySlotControlView(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)));
return matOwner.GetVariableNameForSlot(id);
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{
var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
var prop = new Texture2DArrayShaderProperty();
prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
prop.modifiable = false;
prop.generatePropertyBlock = true;
prop.value.textureArray = textureArray;
properties.AddShaderProperty(prop);
}
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
{
var pp = new PreviewProperty(PropertyType.Texture2DArray)
{
name = name,
textureValue = textureArray,
};
properties.Add(pp);
}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{
var slot = foundSlot as Texture2DArrayInputMaterialSlot;
if (slot != null)
m_TextureArray = slot.m_TextureArray;
}
}
}

3
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayInputMaterialSlot.cs.meta


fileFormatVersion: 2
guid: 56d6d3c32403e4aa1af1fc8b307c0133
timeCreated: 1509276977

31
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayMaterialSlot.cs


using System;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class Texture2DArrayMaterialSlot : MaterialSlot
{
public Texture2DArrayMaterialSlot()
{}
public Texture2DArrayMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStageCapability shaderStageCapability = ShaderStageCapability.All,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden)
{}
public override SlotValueType valueType { get { return SlotValueType.Texture2DArray; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Texture2DArray; } }
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{}
}
}

11
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayMaterialSlot.cs.meta


fileFormatVersion: 2
guid: b87c46f06c359416e8bf44a90c7737d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

84
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayShaderProperty.cs


using System;
using System.Text;
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class Texture2DArrayShaderProperty : AbstractShaderProperty<SerializableTextureArray>
{
[SerializeField]
private bool m_Modifiable = true;
public Texture2DArrayShaderProperty()
{
value = new SerializableTextureArray();
displayName = "Texture2D Array";
}
public override PropertyType propertyType
{
get { return PropertyType.Texture2DArray; }
}
public bool modifiable
{
get { return m_Modifiable; }
set { m_Modifiable = value; }
}
public override Vector4 defaultValue
{
get { return new Vector4(); }
}
public override string GetPropertyBlockString()
{
var result = new StringBuilder();
if (!m_Modifiable)
{
result.Append("[NonModifiableTextureData] ");
}
result.Append("[NoScaleOffset] ");
result.Append(referenceName);
result.Append("(\"");
result.Append(displayName);
result.Append("\", 2DArray) = \"white\" {}");
return result.ToString();
}
public override string GetPropertyDeclarationString(string delimiter = ";")
{
return string.Format("TEXTURE2D_ARRAY({0}){1} SAMPLER(sampler{0}){1}", referenceName, delimiter);
}
public override string GetPropertyAsArgumentString()
{
return string.Format("TEXTURE2D_ARRAY_ARGS({0}, sampler{0})", referenceName);
}
public override PreviewProperty GetPreviewMaterialProperty()
{
return new PreviewProperty(PropertyType.Texture2D)
{
name = referenceName,
textureValue = value.textureArray
};
}
public override INode ToConcreteNode()
{
return new Texture2DAssetNode { texture = value.textureArray };
}
public override IShaderProperty Copy()
{
var copied = new Texture2DArrayShaderProperty();
copied.displayName = displayName;
copied.value = value;
return copied;
}
}
}

3
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DArrayShaderProperty.cs.meta


fileFormatVersion: 2
guid: 3e63504c5144748fd844c188e96e941b
timeCreated: 1505346949

79
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DInputMaterialSlot.cs


using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Slots;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class Texture3DInputMaterialSlot : Texture3DMaterialSlot
{
[SerializeField]
private SerializableTexture m_Texture = new SerializableTexture();
public Texture texture
{
get { return m_Texture.texture; }
set { m_Texture.texture = value; }
}
public Texture3DInputMaterialSlot()
{}
public Texture3DInputMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
ShaderStageCapability shaderStageCapability = ShaderStageCapability.All,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStageCapability, hidden)
{}
public override VisualElement InstantiateControl()
{
return new Texture3DSlotControlView(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)));
return matOwner.GetVariableNameForSlot(id);
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{
var matOwner = owner as AbstractMaterialNode;
if (matOwner == null)
throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
var prop = new Texture3DShaderProperty();
prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id);
prop.modifiable = false;
prop.generatePropertyBlock = true;
prop.value.texture = texture;
properties.AddShaderProperty(prop);
}
public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
{
var pp = new PreviewProperty(PropertyType.Texture3D)
{
name = name,
textureValue = texture,
};
properties.Add(pp);
}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{
var slot = foundSlot as Texture3DInputMaterialSlot;
if (slot != null)
m_Texture = slot.m_Texture;
}
}
}

3
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DInputMaterialSlot.cs.meta


fileFormatVersion: 2
guid: fa82e95b6172d4aafaed3656eb9d0a03
timeCreated: 1509276977

31
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DMaterialSlot.cs


using System;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class Texture3DMaterialSlot : MaterialSlot
{
public Texture3DMaterialSlot()
{}
public Texture3DMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStageCapability shaderStageCapability = ShaderStageCapability.All,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden)
{}
public override SlotValueType valueType { get { return SlotValueType.Texture3D; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Texture3D; } }
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{}
}
}

11
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DMaterialSlot.cs.meta


fileFormatVersion: 2
guid: d14087d6634274aee91ead8607c2e32d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

84
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DShaderProperty.cs


using System;
using System.Text;
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class Texture3DShaderProperty : AbstractShaderProperty<SerializableTexture>
{
[SerializeField]
private bool m_Modifiable = true;
public Texture3DShaderProperty()
{
value = new SerializableTexture();
displayName = "Texture3D";
}
public override PropertyType propertyType
{
get { return PropertyType.Texture3D; }
}
public bool modifiable
{
get { return m_Modifiable; }
set { m_Modifiable = value; }
}
public override Vector4 defaultValue
{
get { return new Vector4(); }
}
public override string GetPropertyBlockString()
{
var result = new StringBuilder();
if (!m_Modifiable)
{
result.Append("[NonModifiableTextureData] ");
}
result.Append("[NoScaleOffset] ");
result.Append(referenceName);
result.Append("(\"");
result.Append(displayName);
result.Append("\", 3D) = \"white\" {}");
return result.ToString();
}
public override string GetPropertyDeclarationString(string delimiter = ";")
{
return string.Format("TEXTURE3D({0}){1} SAMPLER(sampler{0}){1}", referenceName, delimiter);
}
public override string GetPropertyAsArgumentString()
{
return string.Format("TEXTURE3D_ARGS({0}, sampler{0})", referenceName);
}
public override PreviewProperty GetPreviewMaterialProperty()
{
return new PreviewProperty(PropertyType.Texture3D)
{
name = referenceName,
textureValue = value.texture
};
}
public override INode ToConcreteNode()
{
return new Texture3DAssetNode { texture = (Texture3D)value.texture };
}
public override IShaderProperty Copy()
{
var copied = new Texture3DShaderProperty();
copied.displayName = displayName;
copied.value = value;
return copied;
}
}
}

3
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture3DShaderProperty.cs.meta


fileFormatVersion: 2
guid: fa05c5d2d4d374703b6c59248a30fca3
timeCreated: 1505346949

97
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture2DArrayNode.cs


using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Sample Texture 2D Array")]
public class SampleTexture2DArrayNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
{
public const int OutputSlotRGBAId = 0;
public const int OutputSlotRId = 4;
public const int OutputSlotGId = 5;
public const int OutputSlotBId = 6;
public const int OutputSlotAId = 7;
public const int TextureInputId = 1;
public const int UVInput = 2;
public const int SamplerInput = 3;
public const int IndexInputId = 8;
const string kOutputSlotRGBAName = "RGBA";
const string kOutputSlotRName = "R";
const string kOutputSlotGName = "G";
const string kOutputSlotBName = "B";
const string kOutputSlotAName = "A";
const string kTextureInputName = "Texture Array";
const string kUVInputName = "UV";
const string kSamplerInputName = "Sampler";
const string kIndexInputName = "Index";
public override bool hasPreview { get { return true; } }
public SampleTexture2DArrayNode()
{
name = "Sample Texture 2D Array";
UpdateNodeAfterDeserialization();
}
public override string documentationURL
{
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Sample-Texture-2D-Array-Node"; }
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, 0));
AddSlot(new Texture2DArrayInputMaterialSlot(TextureInputId, kTextureInputName, kTextureInputName));
AddSlot(new Vector1MaterialSlot(IndexInputId, kIndexInputName, kIndexInputName, SlotType.Input, 0));
AddSlot(new UVMaterialSlot(UVInput, kUVInputName, kUVInputName, UVChannel.UV0));
AddSlot(new SamplerStateMaterialSlot(SamplerInput, kSamplerInputName, kSamplerInputName, SlotType.Input));
RemoveSlotsNameNotMatching(new[] { OutputSlotRGBAId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, TextureInputId, IndexInputId, UVInput, SamplerInput });
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvName = GetSlotValue(UVInput, generationMode);
var indexName = GetSlotValue(IndexInputId, generationMode);
//Sampler input slot
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerInput);
var edgesSampler = owner.GetEdges(samplerSlot.slotReference);
var id = GetSlotValue(TextureInputId, generationMode);
var result = string.Format("{0}4 {1} = SAMPLE_TEXTURE2D_ARRAY({2}, {3}, {4}, {5});"
, precision
, GetVariableNameForSlot(OutputSlotRGBAId)
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : "sampler" + id
, uvName
, indexName);
visitor.AddShaderChunk(result, true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.r;", precision, GetVariableNameForSlot(OutputSlotRId), GetVariableNameForSlot(OutputSlotRGBAId)), true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.g;", precision, GetVariableNameForSlot(OutputSlotGId), GetVariableNameForSlot(OutputSlotRGBAId)), true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.b;", precision, GetVariableNameForSlot(OutputSlotBId), GetVariableNameForSlot(OutputSlotRGBAId)), true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.a;", precision, GetVariableNameForSlot(OutputSlotAId), GetVariableNameForSlot(OutputSlotRGBAId)), true);
}
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
{
s_TempSlots.Clear();
GetInputSlots(s_TempSlots);
foreach (var slot in s_TempSlots)
{
if (slot.RequiresMeshUV(channel))
return true;
}
return false;
}
}
}

12
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture2DArrayNode.cs.meta


fileFormatVersion: 2
guid: 0789ef77e28f0406dbb0970c5a8e7a2c
timeCreated: 1495637741
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

63
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture3DNode.cs


using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Sample Texture 3D")]
public class SampleTexture3DNode : AbstractMaterialNode, IGeneratesBodyCode
{
public const int OutputSlotId = 0;
public const int TextureInputId = 1;
public const int UVInput = 2;
public const int SamplerInput = 3;
const string kOutputSlotName = "Out";
const string kTextureInputName = "Texture";
const string kUVInputName = "UV";
const string kSamplerInputName = "Sampler";
public override bool hasPreview { get { return true; } }
public SampleTexture3DNode()
{
name = "Sample Texture 3D";
UpdateNodeAfterDeserialization();
}
public override string documentationURL
{
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Sample-Texture-3D-Node"; }
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
AddSlot(new Texture3DInputMaterialSlot(TextureInputId, kTextureInputName, kTextureInputName));
AddSlot(new Vector3MaterialSlot(UVInput, kUVInputName, kUVInputName, SlotType.Input, Vector3.zero));
AddSlot(new SamplerStateMaterialSlot(SamplerInput, kSamplerInputName, kSamplerInputName, SlotType.Input));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, TextureInputId, UVInput, SamplerInput });
}
// Node generations
public virtual void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
var uvName = GetSlotValue(UVInput, generationMode);
//Sampler input slot
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerInput);
var edgesSampler = owner.GetEdges(samplerSlot.slotReference);
var id = GetSlotValue(TextureInputId, generationMode);
var result = string.Format("{0}4 {1} = SAMPLE_TEXTURE3D({2}, {3}, {4});"
, precision
, GetVariableNameForSlot(OutputSlotId)
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : "sampler" + id
, uvName);
visitor.AddShaderChunk(result, true);
}
}
}

12
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/SampleTexture3DNode.cs.meta


fileFormatVersion: 2
guid: 0c9bd58ae163e49acb187db417dbfd95
timeCreated: 1495637741
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

78
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture2DArrayAssetNode.cs


using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Texture 2D Array Asset")]
public class Texture2DArrayAssetNode : AbstractMaterialNode, IPropertyFromNode
{
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
public Texture2DArrayAssetNode()
{
name = "Texture 2D Array Asset";
UpdateNodeAfterDeserialization();
}
public override string documentationURL
{
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Texture-2D-Array-Asset-Node"; }
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Texture2DArrayMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[SerializeField]
private SerializableTextureArray m_Texture = new SerializableTextureArray();
[TextureArrayControl("")]
public Texture2DArray texture
{
get { return m_Texture.textureArray; }
set
{
if (m_Texture.textureArray == value)
return;
m_Texture.textureArray = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new Texture2DArrayShaderProperty()
{
overrideReferenceName = GetVariableNameForSlot(OutputSlotId),
generatePropertyBlock = true,
value = m_Texture,
modifiable = false
});
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Texture2DArray)
{
name = GetVariableNameForSlot(OutputSlotId),
textureValue = texture
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new Texture2DArrayShaderProperty { value = m_Texture };
if (texture != null)
prop.displayName = texture.name;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

11
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture2DArrayAssetNode.cs.meta


fileFormatVersion: 2
guid: 34c0298d9fb6e4bc9aedbeeeeb8b8054
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

78
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture3DAssetNode.cs


using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Texture 3D Asset")]
public class Texture3DAssetNode : AbstractMaterialNode, IPropertyFromNode
{
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
public Texture3DAssetNode()
{
name = "Texture 3D Asset";
UpdateNodeAfterDeserialization();
}
public override string documentationURL
{
get { return "https://github.com/Unity-Technologies/ShaderGraph/wiki/Texture-3D-Asset-Node"; }
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Texture3DMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[SerializeField]
private SerializableTexture m_Texture = new SerializableTexture();
[Texture3DControl("")]
public Texture3D texture
{
get { return (Texture3D)m_Texture.texture; }
set
{
if (m_Texture.texture == value)
return;
m_Texture.texture = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new Texture3DShaderProperty()
{
overrideReferenceName = GetVariableNameForSlot(OutputSlotId),
generatePropertyBlock = true,
value = m_Texture,
modifiable = false
});
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Texture3D)
{
name = GetVariableNameForSlot(OutputSlotId),
textureValue = texture
});
}
public IShaderProperty AsShaderProperty()
{
var prop = new Texture3DShaderProperty { value = m_Texture };
if (texture != null)
prop.displayName = texture.name;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

11
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Texture/Texture3DAssetNode.cs.meta


fileFormatVersion: 2
guid: 0b009ba9b523742a0ad6530e14a063a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

53
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/Texture3DControl.cs


using System;
using System.Reflection;
using UnityEditor.Experimental.UIElements;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class Texture3DControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public Texture3DControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new Texture3DControlView(m_Label, node, propertyInfo);
}
}
public class Texture3DControlView : VisualElement
{
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
public Texture3DControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;
m_PropertyInfo = propertyInfo;
if (propertyInfo.PropertyType != typeof(Texture3D))
throw new ArgumentException("Property must be of type Texture 3D.", "propertyInfo");
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
if (!string.IsNullOrEmpty(label))
Add(new Label(label));
var textureField = new ObjectField { value = (Texture3D)m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Texture3D) };
textureField.OnValueChanged(OnChange);
Add(textureField);
}
void OnChange(ChangeEvent<UnityEngine.Object> evt)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Texture Change");
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
this.MarkDirtyRepaint();
}
}
}

11
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/Texture3DControl.cs.meta


fileFormatVersion: 2
guid: 841bd408b769d48caa3011ed9219df24
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

53
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/TextureArrayControl.cs


using System;
using System.Reflection;
using UnityEditor.Experimental.UIElements;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class TextureArrayControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public TextureArrayControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new TextureArrayControlView(m_Label, node, propertyInfo);
}
}
public class TextureArrayControlView : VisualElement
{
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
public TextureArrayControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Node = node;
m_PropertyInfo = propertyInfo;
if (propertyInfo.PropertyType != typeof(Texture2DArray))
throw new ArgumentException("Property must be of type Texture 2D Array.", "propertyInfo");
label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
if (!string.IsNullOrEmpty(label))
Add(new Label(label));
var textureField = new ObjectField { value = (Texture2DArray)m_PropertyInfo.GetValue(m_Node, null), objectType = typeof(Texture2DArray) };
textureField.OnValueChanged(OnChange);
Add(textureField);
}
void OnChange(ChangeEvent<UnityEngine.Object> evt)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Texture Change");
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
Dirty(ChangeType.Repaint);
}
}
}

11
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Controls/TextureArrayControl.cs.meta


fileFormatVersion: 2
guid: 0e3e309a7d3ff4d2e81a55970ef9b026
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

34
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/Slots/Texture3DSlotControlView.cs


using System;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Object = UnityEngine.Object;
namespace UnityEditor.ShaderGraph.Drawing.Slots
{
public class Texture3DSlotControlView : VisualElement
{
Texture3DInputMaterialSlot m_Slot;
public Texture3DSlotControlView(Texture3DInputMaterialSlot slot)
{
m_Slot = slot;
AddStyleSheetPath("Styles/Controls/Texture3DSlotControlView");
var objectField = new ObjectField { objectType = typeof(Texture3D), value = m_Slot.texture };
objectField.OnValueChanged(OnValueChanged);
Add(objectField);
}
void OnValueChanged(ChangeEvent<Object> evt)
{
var texture = evt.newValue as Texture3D;
if (texture != m_Slot.texture)
{
m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change Texture");
m_Slot.texture = texture;
m_Slot.owner.Dirty(ModificationScope.Node);
}
}
}
}

3
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/Slots/Texture3DSlotControlView.cs.meta


fileFormatVersion: 2
guid: 843052fb41ee94a92b93c2070c1bf577
timeCreated: 1509718979

34
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/Slots/TextureArraySlotControlView.cs


using System;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Object = UnityEngine.Object;
namespace UnityEditor.ShaderGraph.Drawing.Slots
{
public class TextureArraySlotControlView : VisualElement
{
Texture2DArrayInputMaterialSlot m_Slot;
public TextureArraySlotControlView(Texture2DArrayInputMaterialSlot slot)
{
m_Slot = slot;
AddStyleSheetPath("Styles/Controls/TextureArraySlotControlView");
var objectField = new ObjectField { objectType = typeof(Texture2DArray), value = m_Slot.textureArray };
objectField.OnValueChanged(OnValueChanged);
Add(objectField);
}
void OnValueChanged(ChangeEvent<Object> evt)
{
var textureArray = evt.newValue as Texture2DArray;
if (textureArray != m_Slot.textureArray)
{
m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change Texture Array");
m_Slot.textureArray = textureArray;
m_Slot.owner.Dirty(ModificationScope.Node);
}
}
}
}

3
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/Slots/TextureArraySlotControlView.cs.meta


fileFormatVersion: 2
guid: b65e883d3170e4edca841ea6a8fca626
timeCreated: 1509718979

12
ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/Controls/Texture3DSlotControlView.uss


Texture3DSlotControlView {
flex-direction: row;
align-items: center;
}
Texture3DSlotControlView > ObjectField {
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
width: 100;
}

10
ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/Controls/Texture3DSlotControlView.uss.meta


fileFormatVersion: 2
guid: 8d40f6518d8654aa4bf083cc5897f8ee
ScriptedImporter:
fileIDToRecycleName:
11400000: stylesheet
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}

12
ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/Controls/TextureArraySlotControlView.uss


TextureArraySlotControlView {
flex-direction: row;
align-items: center;
}
TextureArraySlotControlView > ObjectField {
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
width: 100;
}

10
ShaderGraph/com.unity.shadergraph/Editor/Resources/Styles/Controls/TextureArraySlotControlView.uss.meta


fileFormatVersion: 2
guid: 223e574ec2e9a40e690b2d94380057cf
ScriptedImporter:
fileIDToRecycleName:
11400000: stylesheet
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}

8
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes.meta


fileFormatVersion: 2
guid: 85fe5b01e71324be0ac9733087ddfb3d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/Scenes/2xxx_Lighting.meta


fileFormatVersion: 2
guid: 18a2c5ab8a1294651aa8c1dd0dc9b579
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Tests/Scripts/GraphicTests/HDRenderPipeline.meta


fileFormatVersion: 2
guid: 7cd8aa1b9665ad0408015b8700c38b36
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存