浏览代码

Move to 'ShaderGraph' folder

/main
Peter Bay Bastian 7 年前
当前提交
54aaeaae
共有 28 个文件被更改,包括 313 次插入281 次删除
  1. 4
      .gitattributes
  2. 24
      ShaderGraph/build.py
  3. 450
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Gradient/GradientNode.cs
  4. 108
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Gradient/SampleGradientNode.cs
  5. 8
      ShaderGraph.meta
  6. 0
      /ShaderGraph/README.md
  7. 0
      /ShaderGraph/.editorconfig
  8. 0
      /ShaderGraph/README.md.meta
  9. 0
      /ShaderGraph/Testing.meta
  10. 0
      /ShaderGraph/Testing
  11. 0
      /ShaderGraph/build.py.meta
  12. 0
      /ShaderGraph/com.unity.shadergraph.meta
  13. 0
      /ShaderGraph/TestbedAssets
  14. 0
      /ShaderGraph/TestbedAssets.meta
  15. 0
      /ShaderGraph/build.py
  16. 0
      /ShaderGraph/Unity.ShaderGraph.Unreleased.Editor.asmdef
  17. 0
      /ShaderGraph/Unity.ShaderGraph.Unreleased.Editor.asmdef.meta
  18. 0
      /ShaderGraph/HDPipeline
  19. 0
      /ShaderGraph/HDPipeline.meta
  20. 0
      /ShaderGraph/CONTRIBUTIONS.md
  21. 0
      /ShaderGraph/CONTRIBUTIONS.md.meta
  22. 0
      /ShaderGraph/LICENSE.md.meta
  23. 0
      /ShaderGraph/LICENSE.md
  24. 0
      /ShaderGraph/.data
  25. 0
      /ShaderGraph/CHANGELOG.md
  26. 0
      /ShaderGraph/CHANGELOG.md.meta
  27. 0
      /ShaderGraph/com.unity.shadergraph

4
.gitattributes


*.png filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
ShaderGraph/**/*.png filter=lfs diff=lfs merge=lfs -text
ShaderGraph/**/*.gif filter=lfs diff=lfs merge=lfs -text

24
ShaderGraph/build.py


#!/usr/bin/python -B
import os
import logging
def packages_list():
return [
("com.unity.shadergraph", "com.unity.shadergraph")
]
# Prepare an empty project for editor tests
def prepare_editor_test_project(repo_path, project_path, logger):
import unity_package_build
unity_package_build.copy_path_to_project("TestbedAssets", repo_path, project_path, logger)
unity_package_build.copy_path_to_project("Testing", repo_path, project_path, logger)
if __name__ == "__main__":
import sys
sys.path.insert(0, os.path.abspath(os.path.join("..", "automation-tools")))
try:
import unity_package_build
build_log = unity_package_build.setup()
except ImportError:
print "No Automation Tools found."

450
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Gradient/GradientNode.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Gradient")]
public class GradientNode : AbstractMaterialNode, IGeneratesFunction
{
[SerializeField]
private float m_Value;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public GradientNode()
{
name = "Gradient";
UpdateNodeAfterDeserialization();
}
string GetFunctionName()
{
return string.Format("Unity_{0}", GetVariableNameForNode());
}
Gradient m_Gradient = new Gradient();
[SerializeField]
Vector4[] m_SerializableColorKeys = { new Vector4(1f, 1f, 1f, 0f), new Vector4(0f, 0f, 0f, 1f), };
[SerializeField]
Vector2[] m_SerializableAlphaKeys = { new Vector2(1f, 0f), new Vector2(1f, 1f) };
[SerializeField]
int m_SerializableMode = 0;
[GradientControl("")]
public Gradient gradient
{
get
{
return m_Gradient;
}
set
{
var scope = ModificationScope.Nothing;
if(!GradientUtils.CheckEquivalency(m_Gradient, value))
scope = scope < ModificationScope.Graph ? ModificationScope.Graph : scope;
if (scope > ModificationScope.Nothing)
{
var newColorKeys = value.colorKeys;
var newAlphaKeys = value.alphaKeys;
m_Gradient.SetKeys(newColorKeys, newAlphaKeys);
m_Gradient.mode = value.mode;
Dirty(ModificationScope.Node);
}
}
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
m_Gradient = new Gradient();
var colorKeys = m_SerializableColorKeys.Select(k => new GradientColorKey(new Color(k.x, k.y, k.z, 1f), k.w)).ToArray();
var alphaKeys = m_SerializableAlphaKeys.Select(k => new GradientAlphaKey(k.x, k.y)).ToArray();
m_SerializableAlphaKeys = null;
m_SerializableColorKeys = null;
m_Gradient.SetKeys(colorKeys, alphaKeys);
m_Gradient.mode = (GradientMode)m_SerializableMode;
}
public override void OnBeforeSerialize()
{
base.OnBeforeSerialize();
m_SerializableColorKeys = gradient.colorKeys.Select(k => new Vector4(k.color.r, k.color.g, k.color.b, k.time)).ToArray();
m_SerializableAlphaKeys = gradient.alphaKeys.Select(k => new Vector2(k.alpha, k.time)).ToArray();
m_SerializableMode = (int)gradient.mode;
}
public override bool hasPreview { get { return false; } }
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new GradientMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output,0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
if(generationMode == GenerationMode.Preview)
{
registry.ProvideFunction(GetFunctionName(), s =>
{
s.AppendLine("Gradient {0} ()",
GetFunctionName());
using (s.BlockScope())
{
s.AppendLine("Gradient g;");
s.AppendLine("g.type = _{0}_Type;", GetVariableNameForNode());
s.AppendLine("g.colorsLength = _{0}_ColorsLength;", GetVariableNameForNode());
s.AppendLine("g.alphasLength = _{0}_AlphasLength;", GetVariableNameForNode());
for(int i = 0; i < 8; i++)
{
s.AppendLine("g.colors[{0}] = _{1}_ColorKey{0};", i, GetVariableNameForNode());
}
for(int i = 0; i < 8; i++)
{
s.AppendLine("g.alphas[{0}] = _{1}_AlphaKey{0};", i, GetVariableNameForNode());
}
s.AppendLine("return g;", true);
}
});
}
else
{
registry.ProvideFunction(GetFunctionName(), s =>
{
s.AppendLine("Gradient {0} ()",
GetFunctionName());
using (s.BlockScope())
{
GradientUtils.GetGradientDeclaration(m_Gradient, ref s);
s.AppendLine("return g;", true);
}
});
}
}
public override string GetVariableNameForSlot(int slotId)
{
return string.Format("{0}()", GetFunctionName());
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
properties.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("_{0}_Type", GetVariableNameForNode()),
floatValue = (int)m_Gradient.mode
});
properties.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("_{0}_ColorsLength", GetVariableNameForNode()),
floatValue = m_Gradient.colorKeys.Length
});
properties.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("_{0}_AlphasLength", GetVariableNameForNode()),
floatValue = m_Gradient.alphaKeys.Length
});
for(int i = 0; i < 8; i++)
{
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_ColorKey{1}", GetVariableNameForNode(), i),
vector4Value = i < m_Gradient.colorKeys.Length ? GradientUtils.ColorKeyToVector(m_Gradient.colorKeys[i]) : Vector4.zero
});
}
for(int i = 0; i < 8; i++)
{
properties.Add(new PreviewProperty(PropertyType.Vector2)
{
name = string.Format("_{0}_AlphaKey{1}", GetVariableNameForNode(), i),
vector4Value = i < m_Gradient.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(m_Gradient.alphaKeys[i]) : Vector2.zero
});
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
base.CollectShaderProperties(properties, generationMode);
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_Type", GetVariableNameForNode()),
generatePropertyBlock = false
});
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_ColorsLength", GetVariableNameForNode()),
generatePropertyBlock = false
});
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_AlphasLength", GetVariableNameForNode()),
generatePropertyBlock = false
});
for(int i = 0; i < 8; i++)
{
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_ColorKey{1}", GetVariableNameForNode(), i),
generatePropertyBlock = false
});
}
for(int i = 0; i < 8; i++)
{
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_AlphaKey{1}", GetVariableNameForNode(), i),
generatePropertyBlock = false
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Gradient")]
public class GradientNode : AbstractMaterialNode, IGeneratesFunction
{
[SerializeField]
private float m_Value;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public GradientNode()
{
name = "Gradient";
UpdateNodeAfterDeserialization();
}
string GetFunctionName()
{
return string.Format("Unity_{0}", GetVariableNameForNode());
}
Gradient m_Gradient = new Gradient();
[SerializeField]
Vector4[] m_SerializableColorKeys = { new Vector4(1f, 1f, 1f, 0f), new Vector4(0f, 0f, 0f, 1f), };
[SerializeField]
Vector2[] m_SerializableAlphaKeys = { new Vector2(1f, 0f), new Vector2(1f, 1f) };
[SerializeField]
int m_SerializableMode = 0;
[GradientControl("")]
public Gradient gradient
{
get
{
return m_Gradient;
}
set
{
var scope = ModificationScope.Nothing;
if(!GradientUtils.CheckEquivalency(m_Gradient, value))
scope = scope < ModificationScope.Graph ? ModificationScope.Graph : scope;
if (scope > ModificationScope.Nothing)
{
var newColorKeys = value.colorKeys;
var newAlphaKeys = value.alphaKeys;
m_Gradient.SetKeys(newColorKeys, newAlphaKeys);
m_Gradient.mode = value.mode;
Dirty(ModificationScope.Node);
}
}
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
m_Gradient = new Gradient();
var colorKeys = m_SerializableColorKeys.Select(k => new GradientColorKey(new Color(k.x, k.y, k.z, 1f), k.w)).ToArray();
var alphaKeys = m_SerializableAlphaKeys.Select(k => new GradientAlphaKey(k.x, k.y)).ToArray();
m_SerializableAlphaKeys = null;
m_SerializableColorKeys = null;
m_Gradient.SetKeys(colorKeys, alphaKeys);
m_Gradient.mode = (GradientMode)m_SerializableMode;
}
public override void OnBeforeSerialize()
{
base.OnBeforeSerialize();
m_SerializableColorKeys = gradient.colorKeys.Select(k => new Vector4(k.color.r, k.color.g, k.color.b, k.time)).ToArray();
m_SerializableAlphaKeys = gradient.alphaKeys.Select(k => new Vector2(k.alpha, k.time)).ToArray();
m_SerializableMode = (int)gradient.mode;
}
public override bool hasPreview { get { return false; } }
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new GradientMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output,0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
if(generationMode == GenerationMode.Preview)
{
registry.ProvideFunction(GetFunctionName(), s =>
{
s.AppendLine("Gradient {0} ()",
GetFunctionName());
using (s.BlockScope())
{
s.AppendLine("Gradient g;");
s.AppendLine("g.type = _{0}_Type;", GetVariableNameForNode());
s.AppendLine("g.colorsLength = _{0}_ColorsLength;", GetVariableNameForNode());
s.AppendLine("g.alphasLength = _{0}_AlphasLength;", GetVariableNameForNode());
for(int i = 0; i < 8; i++)
{
s.AppendLine("g.colors[{0}] = _{1}_ColorKey{0};", i, GetVariableNameForNode());
}
for(int i = 0; i < 8; i++)
{
s.AppendLine("g.alphas[{0}] = _{1}_AlphaKey{0};", i, GetVariableNameForNode());
}
s.AppendLine("return g;", true);
}
});
}
else
{
registry.ProvideFunction(GetFunctionName(), s =>
{
s.AppendLine("Gradient {0} ()",
GetFunctionName());
using (s.BlockScope())
{
GradientUtils.GetGradientDeclaration(m_Gradient, ref s);
s.AppendLine("return g;", true);
}
});
}
}
public override string GetVariableNameForSlot(int slotId)
{
return string.Format("{0}()", GetFunctionName());
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
properties.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("_{0}_Type", GetVariableNameForNode()),
floatValue = (int)m_Gradient.mode
});
properties.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("_{0}_ColorsLength", GetVariableNameForNode()),
floatValue = m_Gradient.colorKeys.Length
});
properties.Add(new PreviewProperty(PropertyType.Vector1)
{
name = string.Format("_{0}_AlphasLength", GetVariableNameForNode()),
floatValue = m_Gradient.alphaKeys.Length
});
for(int i = 0; i < 8; i++)
{
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_ColorKey{1}", GetVariableNameForNode(), i),
vector4Value = i < m_Gradient.colorKeys.Length ? GradientUtils.ColorKeyToVector(m_Gradient.colorKeys[i]) : Vector4.zero
});
}
for(int i = 0; i < 8; i++)
{
properties.Add(new PreviewProperty(PropertyType.Vector2)
{
name = string.Format("_{0}_AlphaKey{1}", GetVariableNameForNode(), i),
vector4Value = i < m_Gradient.alphaKeys.Length ? GradientUtils.AlphaKeyToVector(m_Gradient.alphaKeys[i]) : Vector2.zero
});
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
base.CollectShaderProperties(properties, generationMode);
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_Type", GetVariableNameForNode()),
generatePropertyBlock = false
});
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_ColorsLength", GetVariableNameForNode()),
generatePropertyBlock = false
});
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_AlphasLength", GetVariableNameForNode()),
generatePropertyBlock = false
});
for(int i = 0; i < 8; i++)
{
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_ColorKey{1}", GetVariableNameForNode(), i),
generatePropertyBlock = false
});
}
for(int i = 0; i < 8; i++)
{
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_AlphaKey{1}", GetVariableNameForNode(), i),
generatePropertyBlock = false
});
}
}
}
}

108
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/Input/Gradient/SampleGradientNode.cs


using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Sample Gradient")]
public class SampleGradient : CodeFunctionNode, IGeneratesBodyCode
{
public SampleGradient()
{
name = "Sample Gradient";
}
public override bool hasPreview
{
get { return true; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_SampleGradient", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_SampleGradient(
[Slot(0, Binding.None)] Gradient Gradient,
[Slot(1, Binding.None)] Vector1 Time,
[Slot(2, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
{precision}3 color = Gradient.colors[0].rgb;
[unroll]
for (int c = 1; c < 8; c++)
{
{precision} colorPos = saturate((Time - Gradient.colors[c-1].w) / (Gradient.colors[c].w - Gradient.colors[c-1].w)) * step(c, Gradient.colorsLength-1);
color = lerp(color, Gradient.colors[c].rgb, lerp(colorPos, step(0.01, colorPos), Gradient.type));
}
#ifndef UNITY_COLORSPACE_GAMMA
color = SRGBToLinear(color);
#endif
{precision} alpha = Gradient.alphas[0].x;
[unroll]
for (int a = 1; a < 8; a++)
{
{precision} alphaPos = saturate((Time - Gradient.alphas[a-1].y) / (Gradient.alphas[a].y - Gradient.alphas[a-1].y)) * step(a, Gradient.alphasLength-1);
alpha = lerp(alpha, Gradient.alphas[a].x, lerp(alphaPos, step(0.01, alphaPos), Gradient.type));
}
Out = {precision}4(color, alpha);
}
";
}
}
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Sample Gradient")]
public class SampleGradient : CodeFunctionNode, IGeneratesBodyCode
{
public SampleGradient()
{
name = "Sample Gradient";
}
public override bool hasPreview
{
get { return true; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_SampleGradient", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_SampleGradient(
[Slot(0, Binding.None)] Gradient Gradient,
[Slot(1, Binding.None)] Vector1 Time,
[Slot(2, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
{precision}3 color = Gradient.colors[0].rgb;
[unroll]
for (int c = 1; c < 8; c++)
{
{precision} colorPos = saturate((Time - Gradient.colors[c-1].w) / (Gradient.colors[c].w - Gradient.colors[c-1].w)) * step(c, Gradient.colorsLength-1);
color = lerp(color, Gradient.colors[c].rgb, lerp(colorPos, step(0.01, colorPos), Gradient.type));
}
#ifndef UNITY_COLORSPACE_GAMMA
color = SRGBToLinear(color);
#endif
{precision} alpha = Gradient.alphas[0].x;
[unroll]
for (int a = 1; a < 8; a++)
{
{precision} alphaPos = saturate((Time - Gradient.alphas[a-1].y) / (Gradient.alphas[a].y - Gradient.alphas[a-1].y)) * step(a, Gradient.alphasLength-1);
alpha = lerp(alpha, Gradient.alphas[a].x, lerp(alphaPos, step(0.01, alphaPos), Gradient.type));
}
Out = {precision}4(color, alpha);
}
";
}
}
}

8
ShaderGraph.meta


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

/README.md → /ShaderGraph/README.md

/.editorconfig → /ShaderGraph/.editorconfig

/README.md.meta → /ShaderGraph/README.md.meta

/Testing.meta → /ShaderGraph/Testing.meta

/Testing → /ShaderGraph/Testing

/build.py.meta → /ShaderGraph/build.py.meta

/com.unity.shadergraph.meta → /ShaderGraph/com.unity.shadergraph.meta

/TestbedAssets → /ShaderGraph/TestbedAssets

/TestbedAssets.meta → /ShaderGraph/TestbedAssets.meta

/build.py → /ShaderGraph/build.py

/Unity.ShaderGraph.Unreleased.Editor.asmdef → /ShaderGraph/Unity.ShaderGraph.Unreleased.Editor.asmdef

/Unity.ShaderGraph.Unreleased.Editor.asmdef.meta → /ShaderGraph/Unity.ShaderGraph.Unreleased.Editor.asmdef.meta

/HDPipeline → /ShaderGraph/HDPipeline

/HDPipeline.meta → /ShaderGraph/HDPipeline.meta

/CONTRIBUTIONS.md → /ShaderGraph/CONTRIBUTIONS.md

/CONTRIBUTIONS.md.meta → /ShaderGraph/CONTRIBUTIONS.md.meta

/LICENSE.md.meta → /ShaderGraph/LICENSE.md.meta

/LICENSE.md → /ShaderGraph/LICENSE.md

/.data → /ShaderGraph/.data

/CHANGELOG.md → /ShaderGraph/CHANGELOG.md

/CHANGELOG.md.meta → /ShaderGraph/CHANGELOG.md.meta

/com.unity.shadergraph → /ShaderGraph/com.unity.shadergraph

正在加载...
取消
保存