浏览代码

Remove Gradient nodes and asset type :(

/main
Matt Dean 7 年前
当前提交
bbb186d6
共有 18 个文件被更改,包括 1 次插入290 次删除
  1. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs
  4. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs
  5. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyType.cs
  6. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs
  7. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs
  8. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/DefaultControl.cs
  9. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientMaterialSlot.cs
  10. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientMaterialSlot.cs.meta
  11. 58
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientShaderProperty.cs
  12. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientShaderProperty.cs.meta
  13. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient.meta
  14. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs.meta
  15. 91
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs
  16. 34
      MaterialGraphProject/Assets/UnityShaderEditor/ShaderGraph.cginc
  17. 9
      MaterialGraphProject/Assets/UnityShaderEditor/ShaderGraph.cginc.meta

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


finalShader.AddShaderChunk("CGINCLUDE", false);
finalShader.AddShaderChunk("#include \"UnityCG.cginc\"", false);
finalShader.AddShaderChunk("#include \"//Assets/UnityShaderEditor/ShaderGraph.cginc\"", false);
finalShader.AddShaderChunk(shaderFunctionVisitor.GetShaderString(2), false);
finalShader.AddShaderChunk(graphVertexInput, false);
finalShader.AddShaderChunk(surfaceInputs.GetShaderString(2), false);

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/MaterialSlot.cs


return "(SS)";
case ConcreteSlotValueType.Texture2D:
return "(T)";
case ConcreteSlotValueType.Gradient:
return "(G)";
default:
return "(E)";
}

{
switch (type)
{
case SlotValueType.Gradient:
return new GradientMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
case SlotValueType.SamplerState:
return new SamplerStateMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
case SlotValueType.Matrix4:

{
switch (concreteValueType)
{
case ConcreteSlotValueType.Gradient:
return inputType == ConcreteSlotValueType.Gradient;
case ConcreteSlotValueType.SamplerState:
return inputType == ConcreteSlotValueType.SamplerState;
case ConcreteSlotValueType.Matrix4:

return PropertyType.Matrix4;
case ConcreteSlotValueType.SamplerState:
return PropertyType.SamplerState;
case ConcreteSlotValueType.Gradient:
return PropertyType.Gradient;
default:
return PropertyType.Vector4;
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/AbstractMaterialNode.cs


return "Matrix4x4";
case ConcreteSlotValueType.SamplerState:
return "SamplerState";
case ConcreteSlotValueType.Gradient:
return "Gradient";
default:
return "Error";
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/CodeFunctionNode.cs


protected struct DynamicDimensionVector
{}
protected struct Gradient
{}
protected enum Binding
{
None,

if (t == typeof(SamplerState))
{
return SlotValueType.SamplerState;
}
if (t == typeof(Gradient))
{
return SlotValueType.Gradient;
}
if (t == typeof(DynamicDimensionVector))
{

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyType.cs


Matrix2,
Matrix3,
Matrix4,
SamplerState,
Gradient
SamplerState
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/SlotValue.cs


[Serializable]
public enum SlotValueType
{
Gradient,
SamplerState,
Matrix4,
Matrix3,

public enum ConcreteSlotValueType
{
Gradient,
SamplerState,
Matrix4,
Matrix3,

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/AbstractSubGraphNode.cs


case PropertyType.Matrix4:
slotType = SlotValueType.Matrix4;
break;
case PropertyType.Gradient:
slotType = SlotValueType.Gradient;
break;
default:
throw new ArgumentOutOfRangeException();
}

2
MaterialGraphProject/Assets/UnityShaderEditor/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(Gradient))
return new GradientControlView(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))

46
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientMaterialSlot.cs


using System;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class GradientMaterialSlot : MaterialSlot
{
public GradientMaterialSlot()
{
}
public GradientMaterialSlot(
int slotId,
string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
bool hidden = false)
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
{
}
public static readonly string DefaultGradientName = "ShaderGraph_DefaultGradient()";
public override SlotValueType valueType { get { return SlotValueType.Gradient; } }
public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Gradient; } }
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
{
}
public override void CopyValuesFrom(MaterialSlot foundSlot)
{
}
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 DefaultGradientName;
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientMaterialSlot.cs.meta


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

58
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientShaderProperty.cs


using System;
using System.Text;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Serializable]
public class GradientShaderProperty : AbstractShaderProperty<Gradient>
{
[SerializeField]
private bool m_Modifiable = true;
public GradientShaderProperty()
{
value = new Gradient();
}
public override PropertyType propertyType
{
get { return PropertyType.Gradient; }
}
public bool modifiable
{
get { return m_Modifiable; }
set { m_Modifiable = value; }
}
public override Vector4 defaultValue
{
get { return new Vector4(); }
}
public override string GetPropertyBlockString()
{
return "";
}
public override string GetPropertyDeclarationString()
{
return "";
}
public override string GetInlinePropertyDeclarationString()
{
return "Gradient ShaderGraph_DefaultGradient;";
}
public override PreviewProperty GetPreviewMaterialProperty()
{
return new PreviewProperty()
{
m_Name = referenceName,
m_PropType = PropertyType.Gradient
};
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/GradientShaderProperty.cs.meta


fileFormatVersion: 2
guid: 186ecc17664ca614d9663a3fa18dede9
timeCreated: 1505346949

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Gradient.meta


fileFormatVersion: 2
guid: 4655415e388e6914ebefaaf9e2148ff1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs.meta


fileFormatVersion: 2
guid: 41930fdac13e47db8faedb82e6411a4f
timeCreated: 1507882043

91
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/GradientControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEditor.ShaderGraph;
namespace UnityEditor.ShaderGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class GradientControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public GradientControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new GradientControlView(m_Label, node, propertyInfo);
}
}
[Serializable]
public class GradientObject : ScriptableObject
{
public Gradient gradient = new Gradient();
}
public class GradientControlView : VisualElement
{
GUIContent m_Label;
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
string m_PrevWindow = "";
[SerializeField]
GradientObject m_GradientObject;
[SerializeField]
SerializedObject m_SerializedObject;
[SerializeField]
SerializedProperty m_SerializedProperty;
public GradientControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
m_Label = new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));
m_Node = node;
m_PropertyInfo = propertyInfo;
if (propertyInfo.PropertyType != typeof(Gradient))
throw new ArgumentException("Property must be of type Gradient.", "propertyInfo");
m_GradientObject = ScriptableObject.CreateInstance<GradientObject>();
m_GradientObject.gradient = new Gradient();
m_SerializedObject = new SerializedObject(m_GradientObject);
m_SerializedProperty = m_SerializedObject.FindProperty("gradient");
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
m_SerializedObject.Update();
var gradient = (Gradient)m_PropertyInfo.GetValue(m_Node, null);
m_GradientObject.gradient.SetKeys(gradient.colorKeys, gradient.alphaKeys);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
EditorGUILayout.PropertyField(m_SerializedProperty, m_Label, true, null);
m_SerializedObject.ApplyModifiedProperties();
if (changeCheckScope.changed)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, m_GradientObject.gradient, null);
}
}
var e = Event.current;
if (EditorWindow.focusedWindow != null && m_PrevWindow != EditorWindow.focusedWindow.ToString() && EditorWindow.focusedWindow.ToString() != "(UnityEditor.GradientPicker)")
{
m_PropertyInfo.SetValue(m_Node, m_GradientObject.gradient, null);
m_PrevWindow = EditorWindow.focusedWindow.ToString();
}
}
}
}

34
MaterialGraphProject/Assets/UnityShaderEditor/ShaderGraph.cginc


// Gradient Type
struct Gradient
{
int type;
int colorsLength;
int alphasLength;
float4 colors[8];
float2 alphas[8];
};
Gradient ShaderGraph_DefaultGradient()
{
Gradient g;
g.type = 0;
g.colorsLength = 2;
g.alphasLength = 2;
g.colors[0] = float4(0, 0, 0, 0);
g.colors[1] = float4(1, 1, 1, 1);
g.colors[2] = float4(0, 0, 0, 0);
g.colors[3] = float4(0, 0, 0, 0);
g.colors[4] = float4(0, 0, 0, 0);
g.colors[5] = float4(0, 0, 0, 0);
g.colors[6] = float4(0, 0, 0, 0);
g.colors[7] = float4(0, 0, 0, 0);
g.alphas[0] = float2(1, 0);
g.alphas[1] = float2(1, 1);
g.alphas[2] = float2(0, 0);
g.alphas[3] = float2(0, 0);
g.alphas[4] = float2(0, 0);
g.alphas[5] = float2(0, 0);
g.alphas[6] = float2(0, 0);
g.alphas[7] = float2(0, 0);
return g;
}

9
MaterialGraphProject/Assets/UnityShaderEditor/ShaderGraph.cginc.meta


fileFormatVersion: 2
guid: 2a7388374397c47f1a598ae9ea3f2069
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存