Close #1: Finally cracked the colored lighting problem
This commit is contained in:
parent
00c2d14a06
commit
cb599f24df
|
@ -6,26 +6,23 @@ public static class Utils
|
||||||
{
|
{
|
||||||
// Expects Hue and Saturation are 0-1, Brightness 0-255
|
// Expects Hue and Saturation are 0-1, Brightness 0-255
|
||||||
// https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
|
// https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
|
||||||
|
// This is actually not accurate to *real* hsb to rgb. But I'm replicating the inaccuracies of Dark :(
|
||||||
|
// See issue#1
|
||||||
public static Vector3 HsbToRgb(float hue, float saturation, float brightness)
|
public static Vector3 HsbToRgb(float hue, float saturation, float brightness)
|
||||||
{
|
{
|
||||||
hue *= 360;
|
hue *= 3;
|
||||||
var hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
|
var color = hue switch
|
||||||
var f = hue / 60 - Math.Floor(hue / 60);
|
|
||||||
|
|
||||||
var v = Convert.ToInt32(brightness);
|
|
||||||
var p = Convert.ToInt32(brightness * (1 - saturation));
|
|
||||||
var q = Convert.ToInt32(brightness * (1 - f * saturation));
|
|
||||||
var t = Convert.ToInt32(brightness * (1 - (1 - f) * saturation));
|
|
||||||
|
|
||||||
return hi switch
|
|
||||||
{
|
{
|
||||||
0 => new Vector3(v, t, p),
|
< 1 => new Vector3(1f - hue, hue, 0),
|
||||||
1 => new Vector3(q, v, p),
|
< 2 => new Vector3(2f - hue, hue - 1f, 0),
|
||||||
2 => new Vector3(p, v, t),
|
_ => new Vector3(3f - hue, hue - 2, 0),
|
||||||
3 => new Vector3(p, q, v),
|
|
||||||
4 => new Vector3(t, p, v),
|
|
||||||
_ => new Vector3(v, p, q),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
color *= saturation;
|
||||||
|
color += Vector3.One * (1.0f - saturation);
|
||||||
|
color *= brightness;
|
||||||
|
|
||||||
|
return color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue