"#version 330 core\n"
"layout(location = 0) in vec3 vtx_position;\n"
"layout(location = 1) in vec3 vtx_tex_uv;\n"
- "layout(location = 2) in vec3 vtx_color;\n"
- "layout(location = 3) in vec3 vtx_normal;\n"
+ "layout(location = 2) in vec3 vtx_hsl_mod;\n"
+ "layout(location = 3) in vec3 vtx_rgb_mod;\n"
+ "layout(location = 4) in vec3 vtx_normal;\n"
"uniform mat4 M;\n"
"uniform mat4 MV;\n"
"uniform mat4 MVP;\n"
"out vec3 frag_tex_uv;\n"
- "out vec3 frag_color;\n"
+ "out vec3 frag_hsl_mod;\n"
+ "out vec3 frag_rgb_mod;\n"
"out vec3 vtx_viewspace;\n"
"out vec3 normal;\n"
"void main() {\n"
"vtx_viewspace = (MV * vec4(vtx_position, 1)).xyz;\n"
"normal = (M * vec4(vtx_normal, 0)).xyz;\n"
"frag_tex_uv = vtx_tex_uv;\n"
- "frag_color = vtx_color;\n"
+ "frag_hsl_mod = vtx_hsl_mod;\n"
+ "frag_rgb_mod = vtx_rgb_mod;\n"
"}\n"
);
program.LoadShader(
GL_FRAGMENT_SHADER,
"#version 330 core\n"
"in vec3 frag_tex_uv;\n"
- "in vec3 frag_color;\n"
+ "in vec3 frag_hsl_mod;\n"
+ "in vec3 frag_rgb_mod;\n"
"in vec3 vtx_viewspace;\n"
"in vec3 normal;\n"
"uniform sampler2DArray tex_sampler;\n"
"uniform vec3 light_color;\n"
"uniform float fog_density;\n"
"out vec3 color;\n"
+ "vec3 rgb2hsl(vec3 c) {\n"
+ "vec4 K = vec4(0.0, -1.0/3.0, 2.0/3.0, -1.0);\n"
+ "vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n"
+ "vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n"
+ "float d = q.x - min(q.w, q.y);\n"
+ "float e = 1.0e-10;\n"
+ "return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n"
+ "}\n"
+ "vec3 hsl2rgb(vec3 c) {\n"
+ "vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);\n"
+ "vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n"
+ "return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n"
+ "}\n"
"void main() {\n"
"vec3 tex_color = texture(tex_sampler, frag_tex_uv).rgb;\n"
- "vec3 base_color = tex_color * frag_color;\n"
+ "vec3 hsl_color = rgb2hsl(tex_color);\n"
+ "hsl_color.x += frag_hsl_mod.x;\n"
+ "hsl_color.y *= frag_hsl_mod.y;\n"
+ "hsl_color.z *= frag_hsl_mod.z;\n"
+ "vec3 base_color = hsl2rgb(hsl_color) * frag_rgb_mod;\n"
"vec3 ambient = vec3(0.1, 0.1, 0.1) * base_color;\n"
// this should be the same as the clear color, otherwise looks really weird
"vec3 fog_color = vec3(0, 0, 0);\n"