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,152 @@
using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Artistic", "Adjustment", "Channel Mixer")]
class ChannelMixerNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
{
public ChannelMixerNode()
{
name = "Channel Mixer";
UpdateNodeAfterDeserialization();
}
const int InputSlotId = 0;
const int OutputSlotId = 1;
const string kInputSlotName = "In";
const string kOutputSlotName = "Out";
public override bool hasPreview
{
get { return true; }
}
string GetFunctionName()
{
return "Unity_ChannelMixer_$precision";
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector3.zero));
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId });
}
[SerializeField]
ChannelMixer m_ChannelMixer = new ChannelMixer(new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1));
[Serializable]
public struct ChannelMixer
{
public Vector3 outRed;
public Vector3 outGreen;
public Vector3 outBlue;
public ChannelMixer(Vector3 red, Vector3 green, Vector3 blue)
{
outRed = red;
outGreen = green;
outBlue = blue;
}
}
[ChannelMixerControl("")]
public ChannelMixer channelMixer
{
get { return m_ChannelMixer; }
set
{
if ((value.outRed == m_ChannelMixer.outRed) && (value.outGreen == m_ChannelMixer.outGreen) && (value.outBlue == m_ChannelMixer.outBlue))
return;
m_ChannelMixer = value;
Dirty(ModificationScope.Node);
}
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var inputValue = GetSlotValue(InputSlotId, generationMode);
var outputValue = GetSlotValue(OutputSlotId, generationMode);
sb.AppendLine("{0} {1};", FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString(), GetVariableNameForSlot(OutputSlotId));
if (!generationMode.IsPreview())
{
sb.AppendLine("$precision3 _{0}_Red = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(), channelMixer.outRed[0], channelMixer.outRed[1], channelMixer.outRed[2]);
sb.AppendLine("$precision3 _{0}_Green = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(), channelMixer.outGreen[0], channelMixer.outGreen[1], channelMixer.outGreen[2]);
sb.AppendLine("$precision3 _{0}_Blue = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(), channelMixer.outBlue[0], channelMixer.outBlue[1], channelMixer.outBlue[2]);
}
sb.AppendLine("{0}({1}, _{2}_Red, _{2}_Green, _{2}_Blue, {3});", GetFunctionName(), inputValue, GetVariableNameForNode(), outputValue);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_Red", GetVariableNameForNode()),
vector4Value = channelMixer.outRed
});
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_Green", GetVariableNameForNode()),
vector4Value = channelMixer.outGreen
});
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_Blue", GetVariableNameForNode()),
vector4Value = channelMixer.outBlue
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
base.CollectShaderProperties(properties, generationMode);
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_Red", GetVariableNameForNode()),
generatePropertyBlock = false
});
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_Green", GetVariableNameForNode()),
generatePropertyBlock = false
});
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_Blue", GetVariableNameForNode()),
generatePropertyBlock = false
});
}
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
registry.ProvideFunction(GetFunctionName(), s =>
{
s.AppendLine("void {0} ({1} In, $precision3 Red, $precision3 Green, $precision3 Blue, out {2} Out)",
GetFunctionName(),
FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString(),
FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString());
using (s.BlockScope())
{
s.AppendLine("Out = {0}(dot(In, Red), dot(In, Green), dot(In, Blue));",
FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString());
}
});
}
}
}

View file

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

View file

@ -0,0 +1,33 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Artistic", "Adjustment", "Contrast")]
class ContrastNode : CodeFunctionNode
{
public ContrastNode()
{
name = "Contrast";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Contrast", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Contrast(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None, 1, 1, 1, 1)] Vector1 Contrast,
[Slot(2, Binding.None)] out Vector3 Out)
{
Out = Vector2.zero;
return
@"
{
$precision midpoint = pow(0.5, 2.2);
Out = (In - midpoint) * Contrast + midpoint;
}";
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 94965bffe51535041a4f0a618263bf7d
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,114 @@
using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
enum HueMode
{
Degrees,
Normalized
};
[Title("Artistic", "Adjustment", "Hue")]
class HueNode : CodeFunctionNode
{
public HueNode()
{
name = "Hue";
}
[SerializeField]
private HueMode m_HueMode = HueMode.Degrees;
[EnumControl("Range")]
public HueMode hueMode
{
get { return m_HueMode; }
set
{
if (m_HueMode == value)
return;
m_HueMode = value;
Dirty(ModificationScope.Graph);
}
}
protected override MethodInfo GetFunctionToConvert()
{
switch (m_HueMode)
{
case HueMode.Normalized:
return GetType().GetMethod("Unity_Hue_Normalized", BindingFlags.Static | BindingFlags.NonPublic);
default:
return GetType().GetMethod("Unity_Hue_Degrees", BindingFlags.Static | BindingFlags.NonPublic);
}
}
static string Unity_Hue_Degrees(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None)] Vector1 Offset,
[Slot(2, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return
@"
{
// RGB to HSV
$precision4 K = $precision4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
$precision4 P = lerp($precision4(In.bg, K.wz), $precision4(In.gb, K.xy), step(In.b, In.g));
$precision4 Q = lerp($precision4(P.xyw, In.r), $precision4(In.r, P.yzx), step(P.x, In.r));
$precision D = Q.x - min(Q.w, Q.y);
$precision E = 1e-10;
$precision V = (D == 0) ? Q.x : (Q.x + E);
$precision3 hsv = $precision3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), V);
$precision hue = hsv.x + Offset / 360;
hsv.x = (hue < 0)
? hue + 1
: (hue > 1)
? hue - 1
: hue;
// HSV to RGB
$precision4 K2 = $precision4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
$precision3 P2 = abs(frac(hsv.xxx + K2.xyz) * 6.0 - K2.www);
Out = hsv.z * lerp(K2.xxx, saturate(P2 - K2.xxx), hsv.y);
}";
}
static string Unity_Hue_Normalized(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector1 Offset,
[Slot(2, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return
@"
{
// RGB to HSV
$precision4 K = $precision4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
$precision4 P = lerp($precision4(In.bg, K.wz), $precision4(In.gb, K.xy), step(In.b, In.g));
$precision4 Q = lerp($precision4(P.xyw, In.r), $precision4(In.r, P.yzx), step(P.x, In.r));
$precision D = Q.x - min(Q.w, Q.y);
$precision E = 1e-10;
$precision V = (D == 0) ? Q.x : (Q.x + E);
$precision3 hsv = $precision3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), V);
$precision hue = hsv.x + Offset;
hsv.x = (hue < 0)
? hue + 1
: (hue > 1)
? hue - 1
: hue;
// HSV to RGB
$precision4 K2 = $precision4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
$precision3 P2 = abs(frac(hsv.xxx + K2.xyz) * 6.0 - K2.www);
Out = hsv.z * lerp(K2.xxx, saturate(P2 - K2.xxx), hsv.y);
}";
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 083caf0fe7ff62f438e121e934355461
timeCreated: 1490973460
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,174 @@
using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Artistic", "Adjustment", "Invert Colors")]
class InvertColorsNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction
{
public InvertColorsNode()
{
name = "Invert Colors";
UpdateNodeAfterDeserialization();
}
const int InputSlotId = 0;
const int OutputSlotId = 1;
const string kInputSlotName = "In";
const string kOutputSlotName = "Out";
public override bool hasPreview
{
get { return true; }
}
string GetFunctionName()
{
return $"Unity_InvertColors_{FindSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString()}";
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new DynamicVectorMaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector4.zero));
AddSlot(new DynamicVectorMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId });
}
int channelCount { get { return SlotValueHelper.GetChannelCount(FindSlot<MaterialSlot>(InputSlotId).concreteValueType); } }
[SerializeField]
private bool m_RedChannel;
[ToggleControl("Red")]
public ToggleData redChannel
{
get { return new ToggleData(m_RedChannel, channelCount > 0); }
set
{
if (m_RedChannel == value.isOn)
return;
m_RedChannel = value.isOn;
Dirty(ModificationScope.Node);
}
}
[SerializeField]
private bool m_GreenChannel;
[ToggleControl("Green")]
public ToggleData greenChannel
{
get { return new ToggleData(m_GreenChannel, channelCount > 1); }
set
{
if (m_GreenChannel == value.isOn)
return;
m_GreenChannel = value.isOn;
Dirty(ModificationScope.Node);
}
}
[SerializeField]
private bool m_BlueChannel;
[ToggleControl("Blue")]
public ToggleData blueChannel
{
get { return new ToggleData(m_BlueChannel, channelCount > 2); }
set
{
if (m_BlueChannel == value.isOn)
return;
m_BlueChannel = value.isOn;
Dirty(ModificationScope.Node);
}
}
private bool m_AlphaChannel;
[ToggleControl("Alpha")]
public ToggleData alphaChannel
{
get { return new ToggleData(m_AlphaChannel, channelCount > 3); }
set
{
if (m_AlphaChannel == value.isOn)
return;
m_AlphaChannel = value.isOn;
Dirty(ModificationScope.Node);
}
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var inputValue = GetSlotValue(InputSlotId, generationMode);
var outputValue = GetSlotValue(OutputSlotId, generationMode);
sb.AppendLine("{0} {1};", FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString(), GetVariableNameForSlot(OutputSlotId));
if (!generationMode.IsPreview())
{
sb.TryAppendIndentation();
sb.Append("{0} _{1}_InvertColors = {0} ({2}",
FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString(),
GetVariableNameForNode(),
Convert.ToInt32(m_RedChannel));
if (channelCount > 1)
sb.Append(", {0}", Convert.ToInt32(m_GreenChannel));
if (channelCount > 2)
sb.Append(", {0}", Convert.ToInt32(m_BlueChannel));
if (channelCount > 3)
sb.Append(", {0}", Convert.ToInt32(m_AlphaChannel));
sb.Append(");");
sb.AppendNewLine();
}
sb.AppendLine("{0}({1}, _{2}_InvertColors, {3});", GetFunctionName(), inputValue, GetVariableNameForNode(), outputValue);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_InvertColors", GetVariableNameForNode()),
vector4Value = new Vector4(Convert.ToInt32(m_RedChannel), Convert.ToInt32(m_GreenChannel), Convert.ToInt32(m_BlueChannel), Convert.ToInt32(m_AlphaChannel)),
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
base.CollectShaderProperties(properties, generationMode);
properties.AddShaderProperty(new Vector4ShaderProperty
{
overrideReferenceName = string.Format("_{0}_InvertColors", GetVariableNameForNode()),
generatePropertyBlock = false
});
}
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
registry.ProvideFunction(GetFunctionName(), s =>
{
s.AppendLine("void {0}({1} In, {2} InvertColors, out {3} Out)",
GetFunctionName(),
FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString(),
FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType.ToShaderString(),
FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString());
using (s.BlockScope())
{
s.AppendLine("Out = abs(InvertColors - In);");
}
});
}
}
}

View file

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

View file

@ -0,0 +1,36 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Artistic", "Adjustment", "Replace Color")]
class ReplaceColorNode : CodeFunctionNode
{
public ReplaceColorNode()
{
name = "Replace Color";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_ReplaceColor", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_ReplaceColor(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None)] ColorRGB From,
[Slot(2, Binding.None)] ColorRGB To,
[Slot(3, Binding.None)] Vector1 Range,
[Slot(5, Binding.None)] Vector1 Fuzziness,
[Slot(4, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return
@"
{
$precision Distance = distance(From, In);
Out = lerp(To, In, saturate((Distance - Range) / max(Fuzziness, 1e-5f)));
}";
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a60be5fb80fbbdb449fcc95fa2256cc5
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,33 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Artistic", "Adjustment", "Saturation")]
class SaturationNode : CodeFunctionNode
{
public SaturationNode()
{
name = "Saturation";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Saturation", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Saturation(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None, 1, 1, 1, 1)] Vector1 Saturation,
[Slot(2, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return @"
{
$precision luma = dot(In, $precision3(0.2126729, 0.7151522, 0.0721750));
Out = luma.xxx + Saturation.xxx * (In - luma.xxx);
}
";
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8f3854e9ab30c854b93e88a2e560463e
timeCreated: 1444218016
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,71 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Artistic", "Adjustment", "White Balance")]
class WhiteBalanceNode : CodeFunctionNode
{
public WhiteBalanceNode()
{
name = "White Balance";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_WhiteBalance", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_WhiteBalance(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None)] Vector1 Temperature,
[Slot(2, Binding.None)] Vector1 Tint,
[Slot(3, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return @"
{
// Range ~[-1.67;1.67] works best
$precision t1 = Temperature * 10 / 6;
$precision t2 = Tint * 10 / 6;
// Get the CIE xy chromaticity of the reference white point.
// Note: 0.31271 = x value on the D65 white point
$precision x = 0.31271 - t1 * (t1 < 0 ? 0.1 : 0.05);
$precision standardIlluminantY = 2.87 * x - 3 * x * x - 0.27509507;
$precision y = standardIlluminantY + t2 * 0.05;
// Calculate the coefficients in the LMS space.
$precision3 w1 = $precision3(0.949237, 1.03542, 1.08728); // D65 white point
// CIExyToLMS
$precision Y = 1;
$precision X = Y * x / y;
$precision Z = Y * (1 - x - y) / y;
$precision L = 0.7328 * X + 0.4296 * Y - 0.1624 * Z;
$precision M = -0.7036 * X + 1.6975 * Y + 0.0061 * Z;
$precision S = 0.0030 * X + 0.0136 * Y + 0.9834 * Z;
$precision3 w2 = $precision3(L, M, S);
$precision3 balance = $precision3(w1.x / w2.x, w1.y / w2.y, w1.z / w2.z);
$precision3x3 LIN_2_LMS_MAT = {
3.90405e-1, 5.49941e-1, 8.92632e-3,
7.08416e-2, 9.63172e-1, 1.35775e-3,
2.31082e-2, 1.28021e-1, 9.36245e-1
};
$precision3x3 LMS_2_LIN_MAT = {
2.85847e+0, -1.62879e+0, -2.48910e-2,
-2.10182e-1, 1.15820e+0, 3.24281e-4,
-4.18120e-2, -1.18169e-1, 1.06867e+0
};
$precision3 lms = mul(LIN_2_LMS_MAT, In);
lms *= balance;
Out = mul(LMS_2_LIN_MAT, lms);
}
";
}
}
}

View file

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