Help us understand the problem. What is going on with this article?

# HSVからRGBへの変換をGLSLで実装する

## 前提

HSVからRGBへの変換 - Wikipediaに基づいて、HSV色空間からRGB色空間への変換を実装する。変換の対象となるH, S, Vの定義は以下の通りとし、変換後のR, G, Bは0.0 - 1.0の範囲とする。

• H (Hue) : 色相
• 0.0 - 360.0のfloat
• S (Saturation) : 彩度
• 0.0 - 1.0のfloat
• V (Value) : 明度
• 0.0 - 1.0のfloat

## 実装

```vec3 hsvToRgb(float h, float s, float v) {
// h: 0.0 - 360.0, s: 0.0 - 1.0, v: 0.0 - 1.0
float c = s; // float c = v * s;
float h2 = h / 60.0;
float x = c * (1.0 - abs(mod(h2, 2.0) - 1.0));
vec3 rgb = (v - c) * vec3(1.0, 1.0, 1.0);

if (0.0 <= h2 && h2 < 1.0) {
rgb += vec3(c, x, 0.0);
} else if (1.0 <= h2 && h2 < 2.0) {
rgb += vec3(x, c, 0.0);
} else if (2.0 <= h2 && h2 < 3.0) {
rgb += vec3(0.0, c, x);
} else if (3.0 <= h2 && h2 < 4.0) {
rgb += vec3(0.0, x, c);
} else if (4.0 <= h2 && h2 < 5.0) {
rgb += vec3(x, 0.0, c);
} else if (5.0 <= h2 && h2 < 6.0) {
rgb += vec3(c, 0.0, x);
}

return rgb;
}
```

Why do not you register as a user and use Qiita more conveniently?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away