Skip to content

Commit 5ceaeea

Browse files
authored
Merge pull request #13 from Mikeysax/main
Add hsv_adjustment function to colors
2 parents bf0732d + fa492fe commit 5ceaeea

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ All these shader functions are based on publicly available shader functions (ope
6060
* `greyscale`
6161
* `hsv_to_rgb`
6262
* `rgb_to_hsv`
63+
* `hsv_adjustment`
6364

6465
### Noise
6566
* `psrdnoise3_with_gradient`

addons/ShaderFunction-Extras/Color/color_conversion.gdshaderinc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,16 @@ vec3 rgb_to_hsv(vec3 color) {
1818
float e = 1.0e-10;
1919
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
2020
}
21+
22+
vec3 hsv_adjustment(vec3 col, float hue_offset, float sat_offset, float val_offset) {
23+
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
24+
vec4 p = mix(vec4(col.bg, K.wz), vec4(col.gb, K.xy), step(col.b, col.g));
25+
vec4 q = mix(vec4(p.xyw, col.r), vec4(col.r, p.yzx), step(p.x, col.r));
26+
float d = q.x - min(q.w, q.y);
27+
float e = 1.0e-10;
28+
vec3 hsv = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
29+
hsv.x += hue_offset / 360.0;
30+
hsv.y += sat_offset;
31+
hsv.z += val_offset;
32+
return hsv;
33+
}

0 commit comments

Comments
 (0)