Hi all,

As an exercise to improve my node wielding skills, I decided to try and implement a node-group dedicated to modifying hue, saturation, and lightness. I know there is a node already included with Blender that does this, but I’m not a huge fan of the algorithm and I just wanted a pet project to mess with.

The code I’m implementing is found here.

```
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];
};
HSVtoRGB= function(color) {
var i;
var h,s,v,r,g,b;
h= color[0];
s= color[1];
v= color[2];
if(s === 0 ) {
// achromatic (grey)
r = g = b = v;
return [r,g,b];
}
h /= 60; // sector 0 to 5
i = Math.floor( h );
f = h - i; // factorial part of h
p = v * ( 1 - s );
q = v * ( 1 - s * f );
t = v * ( 1 - s * ( 1 - f ) );
switch( i ) {
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
default: // case 5:
r = v;
g = p;
b = q;
break;
}
return [r,g,b];
}
```

Here are the groups:

**HSV to RGB Conversion:**

**RGB to HSV Conversion:**

Unfortunately after building out the required node groups, they don’t seem to be working. When I test both of them out I get an overwhelming red/pink tint. See the following images:

I’m kind of exhausted after working on this all day and a little put off that they aren’t working correctly, so I decided to throw everything up here to see if any of you know what might be causing the problems. Maybe some of you might find some of the node groups useful as well.

Here is the file:

Happy blending!