I am creating a color saturation node group in blender as an exercise. This is the code I'm trying to implement:
RGBtoHSV= function(color) {
var r,g,b,h,s,v;
r= color[0];
g= color[1];
b= color[2];
min = Math.min( r, g, b );
max = Math.max( r, g, b );
v = max;
delta = max - min;
if( max != 0 )
s = delta / max; // s
else {
// r = g = b = 0 // s = 0, v is undefined
s = 0;
h = -1;
return [h, s, undefined];
}
if( r === max )
h = ( g - b ) / delta; // between yellow & magenta
else if( g === max )
h = 2 + ( b - r ) / delta; // between cyan & yellow
else
h = 4 + ( r - g ) / delta; // between magenta & cyan
h *= 60; // degrees
if( h < 0 )
h += 360;
if ( isNaN(h) )
h = 0;
return [h,s,v];
};
This is the part that I am struggling to implement:
if( r === max )
h = ( g - b ) / delta; // between yellow & magenta
else if( g === max )
h = 2 + ( b - r ) / delta; // between cyan & yellow
else
h = 4 + ( r - g ) / delta; // between magenta & cyan
I am trying to figure out how to chain math comparison nodes in the right way but I am just stuck.
Here is the node group so-far (Updated):
At the very end is where I am stuck. I'm not sure how to set up a three-way if/else node structure.
If r === max
, else if g === max
, else catch-all
.
Any help would be hugely, hugely, appreciated!