Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from Unity-Technologies/gradient-nodes
Gradient Nodes
- Loading branch information
Showing
42 changed files
with
1,042 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
com.unity.shadergraph/Editor/Data/Graphs/GradientInputMaterialSlot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
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 GradientInputMaterialSlot : GradientMaterialSlot, IMaterialSlotHasValue<Gradient> | ||
{ | ||
[SerializeField] | ||
Gradient m_Value = new Gradient(); | ||
|
||
[SerializeField] | ||
Gradient m_DefaultValue; | ||
|
||
public GradientInputMaterialSlot() | ||
{ | ||
} | ||
|
||
public GradientInputMaterialSlot( | ||
int slotId, | ||
string displayName, | ||
string shaderOutputName, | ||
ShaderStage shaderStage = ShaderStage.Dynamic, | ||
bool hidden = false) | ||
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStage, hidden) | ||
{ | ||
} | ||
|
||
public Gradient value | ||
{ | ||
get { return m_Value; } | ||
set { m_Value = value; } | ||
} | ||
|
||
public Gradient defaultValue { get { return m_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))); | ||
|
||
return string.Format("Unity{0}()", 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))); | ||
|
||
if(generationMode == GenerationMode.Preview) | ||
{ | ||
properties.AddShaderProperty(new Vector1ShaderProperty() | ||
{ | ||
overrideReferenceName = string.Format("{0}_Type", matOwner.GetVariableNameForSlot(id)), | ||
value = (int)value.mode, | ||
generatePropertyBlock = false | ||
}); | ||
|
||
properties.AddShaderProperty(new Vector1ShaderProperty() | ||
{ | ||
overrideReferenceName = string.Format("{0}_ColorsLength", matOwner.GetVariableNameForSlot(id)), | ||
value = value.colorKeys.Length, | ||
generatePropertyBlock = false | ||
}); | ||
|
||
properties.AddShaderProperty(new Vector1ShaderProperty() | ||
{ | ||
overrideReferenceName = string.Format("{0}_AlphasLength", matOwner.GetVariableNameForSlot(id)), | ||
value = value.alphaKeys.Length, | ||
generatePropertyBlock = false | ||
}); | ||
|
||
for(int i = 0; i < 8; i++) | ||
{ | ||
properties.AddShaderProperty(new Vector4ShaderProperty() | ||
{ | ||
overrideReferenceName = string.Format("{0}_ColorKey{1}", matOwner.GetVariableNameForSlot(id), i), | ||
value = i < value.colorKeys.Length ? GradientUtils.ColorKeyToVector(value.colorKeys[i]) : Vector4.zero, | ||
generatePropertyBlock = false | ||
}); | ||
} | ||
|
||
for(int i = 0; i < 8; i++) | ||
{ | ||
properties.AddShaderProperty(new Vector4ShaderProperty() | ||
{ | ||
overrideReferenceName = string.Format("{0}_AlphaKey{1}", matOwner.GetVariableNameForSlot(id), i), | ||
value = i < value.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(value.alphaKeys[i]) : Vector2.zero, | ||
generatePropertyBlock = false | ||
}); | ||
} | ||
} | ||
|
||
var prop = new GradientShaderProperty(); | ||
prop.overrideReferenceName = matOwner.GetVariableNameForSlot(id); | ||
prop.generatePropertyBlock = false; | ||
prop.value = value; | ||
|
||
if(generationMode == GenerationMode.Preview) | ||
prop.OverrideMembers(matOwner.GetVariableNameForSlot(id)); | ||
|
||
properties.AddShaderProperty(prop); | ||
} | ||
|
||
public override void GetPreviewProperties(List<PreviewProperty> properties, string name) | ||
{ | ||
properties.Add(new PreviewProperty(PropertyType.Vector1) | ||
{ | ||
name = string.Format("{0}_Type", name), | ||
floatValue = (int)value.mode | ||
}); | ||
|
||
properties.Add(new PreviewProperty(PropertyType.Vector1) | ||
{ | ||
name = string.Format("{0}_ColorsLength", name), | ||
floatValue = value.colorKeys.Length | ||
}); | ||
|
||
properties.Add(new PreviewProperty(PropertyType.Vector1) | ||
{ | ||
name = string.Format("{0}_AlphasLength", name), | ||
floatValue = value.alphaKeys.Length | ||
}); | ||
|
||
for(int i = 0; i < 8; i++) | ||
{ | ||
properties.Add(new PreviewProperty(PropertyType.Vector4) | ||
{ | ||
name = string.Format("{0}_ColorKey{1}", name, i), | ||
vector4Value = i < value.colorKeys.Length ? GradientUtils.ColorKeyToVector(value.colorKeys[i]) : Vector4.zero | ||
}); | ||
} | ||
|
||
for(int i = 0; i < 8; i++) | ||
{ | ||
properties.Add(new PreviewProperty(PropertyType.Vector2) | ||
{ | ||
name = string.Format("{0}_AlphaKey{1}", name, i), | ||
vector4Value = i < value.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(value.alphaKeys[i]) : Vector2.zero | ||
}); | ||
} | ||
} | ||
|
||
public override void CopyValuesFrom(MaterialSlot foundSlot) | ||
{ | ||
var slot = foundSlot as GradientInputMaterialSlot; | ||
if (slot != null) | ||
value = slot.value; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.shadergraph/Editor/Data/Graphs/GradientInputMaterialSlot.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
com.unity.shadergraph/Editor/Data/Graphs/GradientMaterialSlot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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 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) | ||
{ | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.shadergraph/Editor/Data/Graphs/GradientMaterialSlot.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.