浏览代码

Hue Node

/main
Tim Cooper 7 年前
当前提交
acd0279b
共有 1 个文件被更改,包括 92 次插入11 次删除
  1. 103
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/HueNode.cs

103
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Artistic/Adjustment/HueNode.cs


using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
[Title("Art/Adjustments/Hue")]
public enum HueMode
{
Degrees,
Normalized
};
[Title("Artistic/Adjustment/Hue")]
public class HueNode : CodeFunctionNode
{
public HueNode()

[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;
if(onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
return GetType().GetMethod("Unity_Hue", BindingFlags.Static | BindingFlags.NonPublic);
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 Hue,
[Slot(2, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return
@"
{
// RGB to HSV
{precision}4 K = {precision}4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
{precision}4 P = lerp({precision}4(In.bg, K.wz), {precision}4(In.gb, K.xy), step(In.b, In.g));
{precision}4 Q = lerp({precision}4(P.xyw, In.r), {precision}4(In.r, P.yzx), step(P.x, In.r));
{precision} D = Q.x - min(Q.w, Q.y);
{precision} E = 1e-10;
{precision}3 hsv = {precision}3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
{precision} hue = hsv.x + Hue / 360;
hsv.x = (hue < 0)
? hue + 1
: (hue > 1)
? hue - 1
: hue;
// HSV to RGB
{precision}4 K2 = {precision}4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
{precision}3 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(
[Slot(0, Binding.None)] Vector1 argument,
[Slot(1, Binding.None)] out Vector3 result)
static string Unity_Hue_Normalized(
[Slot(0, Binding.None)] Vector3 In,
[Slot(1, Binding.None, 0.5f, 0.5f, 0.5f, 0.5f)] Vector1 Hue,
[Slot(2, Binding.None)] out Vector3 Out)
result = Vector3.zero;
Out = Vector3.zero;
{precision}4 K = {precision}4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
{precision}3 P = abs(frac(argument.xxx + K.xyz) * 6.0 - K.www);
result = 1 * lerp(K.xxx, saturate(P - K.xxx), 1);
}
";
// RGB to HSV
{precision}4 K = {precision}4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
{precision}4 P = lerp({precision}4(In.bg, K.wz), {precision}4(In.gb, K.xy), step(In.b, In.g));
{precision}4 Q = lerp({precision}4(P.xyw, In.r), {precision}4(In.r, P.yzx), step(P.x, In.r));
{precision} D = Q.x - min(Q.w, Q.y);
{precision} E = 1e-10;
{precision}3 hsv = {precision}3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
{precision} hue = hsv.x + Hue;
hsv.x = (hue < 0)
? hue + 1
: (hue > 1)
? hue - 1
: hue;
// HSV to RGB
{precision}4 K2 = {precision}4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
{precision}3 P2 = abs(frac(hsv.xxx + K2.xyz) * 6.0 - K2.www);
Out = hsv.z * lerp(K2.xxx, saturate(P2 - K2.xxx), hsv.y);
}";
}
}
}
正在加载...
取消
保存