feat: added phong and basic shaders, updated mesh format
This commit is contained in:
46
src/gfx/Color.cpp
Normal file
46
src/gfx/Color.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <cstdint>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include "Color.h"
|
||||
|
||||
auto hue_to_rgb(float p, float q, float t) -> float {
|
||||
if (t < 0) {
|
||||
t += 1;
|
||||
} else if (t > 1) {
|
||||
t -= 1;
|
||||
}
|
||||
if (t < 1.0f / 6) return p + (q - p) * 6 * t;
|
||||
if (t < 1.0f / 2) return q;
|
||||
if (t < 2.0f / 3) return p + (q - p) * (2.0f / 3 - t) * 6;
|
||||
return p;
|
||||
};
|
||||
|
||||
auto hsl_to_hex(float h, float s, float l) -> glm::vec3 {
|
||||
h /= 360;
|
||||
s /= 100;
|
||||
l /= 100;
|
||||
float r, g, b;
|
||||
if (s == 0) {
|
||||
r = g = b = l;
|
||||
} else {
|
||||
auto q = l < 0.5f ? l * (1 + s) : l + s - l * s;
|
||||
auto p = 2 * l - q;
|
||||
r = hue_to_rgb(p, q, h + 1.0f / 3);
|
||||
g = hue_to_rgb(p, q, h);
|
||||
b = hue_to_rgb(p, q, h - 1.0f / 3);
|
||||
}
|
||||
return glm::vec3(r, g, b);
|
||||
}
|
||||
|
||||
auto Color::color_from_index(int index) -> glm::vec3 {
|
||||
auto color_wheel_cycle = floorf(index / 6.0f);
|
||||
auto darkness_cycle = floorf(index / 12.0f);
|
||||
auto spacing = (360.0f / 6.0f);
|
||||
auto offset = color_wheel_cycle == 0 ? 0 : spacing / (color_wheel_cycle + 2);
|
||||
auto hue = spacing * (index % 6) + offset;
|
||||
auto saturation = 100.0f;
|
||||
auto lightness = 1.0f / (2 + darkness_cycle) * 100;
|
||||
return hsl_to_hex(hue, saturation, lightness);
|
||||
}
|
||||
Reference in New Issue
Block a user