initial commit

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

View file

@ -0,0 +1,45 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Blackbody")]
class BlackbodyNode : CodeFunctionNode
{
public BlackbodyNode()
{
name = "Blackbody";
}
public override bool hasPreview
{
get { return true; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Blackbody", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Blackbody(
[Slot(0, Binding.None, 512.0f, 512.0f, 512.0f, 512.0f)] Vector1 Temperature,
[Slot(1, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return
@"
{
//based on data by Mitchell Charity http://www.vendian.org/mncharity/dir3/blackbody/
$precision3 color = $precision3(255.0, 255.0, 255.0);
color.x = 56100000. * pow(Temperature,(-3.0 / 2.0)) + 148.0;
color.y = 100.04 * log(Temperature) - 623.6;
if (Temperature > 6500.0) color.y = 35200000.0 * pow(Temperature,(-3.0 / 2.0)) + 184.0;
color.z = 194.18 * log(Temperature) - 1448.6;
color = clamp(color, 0.0, 255.0)/255.0;
if (Temperature < 1000.0) color *= Temperature/1000.0;
Out = color;
}
";
}
}
}

View file

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

View file

@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Gradient")]
class GradientNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private float m_Value;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public GradientNode()
{
name = "Gradient";
synonyms = new string[] { "ramp" };
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
{
if (m_SerializableAlphaKeys != null && m_SerializableColorKeys != null)
{
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;
}
return m_Gradient;
}
set
{
var scope = ModificationScope.Nothing;
if (!GradientUtil.CheckEquivalency(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 OnBeforeSerialize()
{
base.OnBeforeSerialize();
if (m_Gradient != null)
{
m_SerializableColorKeys = m_Gradient.colorKeys.Select(k => new Vector4(k.color.r, k.color.g, k.color.b, k.time)).ToArray();
m_SerializableAlphaKeys = m_Gradient.alphaKeys.Select(k => new Vector2(k.alpha, k.time)).ToArray();
m_SerializableMode = (int)m_Gradient.mode;
}
}
public override bool hasPreview { get { return false; } }
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new GradientMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (generationMode.IsPreview())
{
sb.AppendLine("Gradient {0} = {1};", GetVariableNameForSlot(outputSlotId), GradientUtil.GetGradientForPreview(GetVariableNameForNode()));
}
else
{
sb.AppendLine("Gradient {0} = {1}", GetVariableNameForSlot(outputSlotId), GradientUtil.GetGradientValue(gradient, ";"));
}
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
properties.Add(new PreviewProperty(PropertyType.Gradient)
{
name = GetVariableNameForNode(),
gradientValue = gradient
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
base.CollectShaderProperties(properties, generationMode);
GradientUtil.GetGradientPropertiesForPreview(properties, GetVariableNameForNode(), gradient);
}
public AbstractShaderProperty AsShaderProperty()
{
return new GradientShaderProperty { value = gradient };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

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

View file

@ -0,0 +1,94 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Sample Gradient")]
class SampleGradient : CodeFunctionNode
{
public override int latestVersion => 1;
public SampleGradient()
{
name = "Sample Gradient";
}
public override bool hasPreview
{
get { return true; }
}
protected override MethodInfo GetFunctionToConvert()
{
switch (sgVersion)
{
case 0:
return GetType().GetMethod("Unity_SampleGradientV0", BindingFlags.Static | BindingFlags.NonPublic);
case 1:
default:
return GetType().GetMethod("Unity_SampleGradientV1", BindingFlags.Static | BindingFlags.NonPublic);
}
}
static string Unity_SampleGradientV0(
[Slot(0, Binding.None)] Gradient Gradient,
[Slot(1, Binding.None)] Vector1 Time,
[Slot(2, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
$precision3 color = Gradient.colors[0].rgb;
[unroll]
for (int c = 1; c < Gradient.colorsLength; 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 < Gradient.alphasLength; 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 = $precision4(color, alpha);
}
";
}
static string Unity_SampleGradientV1(
[Slot(0, Binding.None)] Gradient Gradient,
[Slot(1, Binding.None)] Vector1 Time,
[Slot(2, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
$precision3 color = Gradient.colors[0].rgb;
[unroll]
for (int c = 1; c < Gradient.colorsLength; 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));
}
#ifdef UNITY_COLORSPACE_GAMMA
color = LinearToSRGB(color);
#endif
$precision alpha = Gradient.alphas[0].x;
[unroll]
for (int a = 1; a < Gradient.alphasLength; 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 = $precision4(color, alpha);
}
";
}
}
}

View file

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