forked from BilalY/Rasagar
2.4 KiB
2.4 KiB
Hue Node
Description
Offsets the hue of input In by the amount of input Offset. The unit of the offset can be set with the parameter Range. Offset in Degrees is in the range -180 to 180. In Radians it is -Pi to Pi.
Ports
Name | Direction | Type | Binding | Description |
---|---|---|---|---|
In | Input | Vector 3 | None | Input value |
Offset | Input | Float | None | Amount to offset hue |
Out | Output | Vector 3 | None | Output value |
Controls
Name | Type | Options | Description |
---|---|---|---|
Range | Dropdown | Degrees, Radians | The unit used for the input Offset |
Generated Code Example
The following example code represents one possible outcome of this node per Base mode.
Degrees
void Unity_Hue_Degrees_float(float3 In, float Offset, out float3 Out)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 P = lerp(float4(In.bg, K.wz), float4(In.gb, K.xy), step(In.b, In.g));
float4 Q = lerp(float4(P.xyw, In.r), float4(In.r, P.yzx), step(P.x, In.r));
float D = Q.x - min(Q.w, Q.y);
float E = 1e-10;
float3 hsv = float3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
float hue = hsv.x + Offset / 360;
hsv.x = (hue < 0)
? hue + 1
: (hue > 1)
? hue - 1
: hue;
float4 K2 = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 P2 = abs(frac(hsv.xxx + K2.xyz) * 6.0 - K2.www);
Out = hsv.z * lerp(K2.xxx, saturate(P2 - K2.xxx), hsv.y);
}
Radians
void Unity_Hue_Radians_float(float3 In, float Offset, out float3 Out)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 P = lerp(float4(In.bg, K.wz), float4(In.gb, K.xy), step(In.b, In.g));
float4 Q = lerp(float4(P.xyw, In.r), float4(In.r, P.yzx), step(P.x, In.r));
float D = Q.x - min(Q.w, Q.y);
float E = 1e-10;
float3 hsv = float3(abs(Q.z + (Q.w - Q.y)/(6.0 * D + E)), D / (Q.x + E), Q.x);
float hue = hsv.x + Offset;
hsv.x = (hue < 0)
? hue + 1
: (hue > 1)
? hue - 1
: hue;
// HSV to RGB
float4 K2 = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 P2 = abs(frac(hsv.xxx + K2.xyz) * 6.0 - K2.www);
Out = hsv.z * lerp(K2.xxx, saturate(P2 - K2.xxx), hsv.y);
}