52 lines
1.5 KiB
GLSL
52 lines
1.5 KiB
GLSL
layout (location = 0) in vec3 vertex_position;
|
|
layout (location = 0) uniform mat4 mvp_matrix;
|
|
layout (location = 2) uniform float point_size;
|
|
layout (location = 0) out vec4 frag_color;
|
|
|
|
#ifdef LIGHTING
|
|
layout (location = 4) uniform mat4 model_matrix;
|
|
layout (location = 5) uniform vec3 camera_position;
|
|
layout (location = 1) in vec3 vertex_normal;
|
|
#endif
|
|
|
|
#ifdef RAINBOW
|
|
layout (location = 6) uniform float rainbow_offset_y;
|
|
layout (location = 7) uniform float rainbow_scale_y;
|
|
|
|
// taken from 'https://github.com/hughsk/glsl-hsv2rgb'
|
|
vec3 hue2rgb(float hue)
|
|
{
|
|
vec4 offsets = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
|
vec3 p = abs(fract(vec3(hue) + offsets.xyz) * 6.0 - offsets.www);
|
|
return clamp(p - offsets.xxx, 0.0, 1.0);
|
|
}
|
|
#endif
|
|
|
|
#ifdef REFLECTANCE
|
|
layout (location = 2) in float vertex_reflectance;
|
|
#endif
|
|
|
|
void main()
|
|
{
|
|
gl_Position = mvp_matrix * vec4(vertex_position, 1.0);
|
|
gl_PointSize = point_size / gl_Position.w;
|
|
|
|
frag_color = vec4(1);
|
|
|
|
#ifdef LIGHTING
|
|
vec3 world_position = vec3(model_matrix * vec4(vertex_position, 1.0));
|
|
vec3 world_normal = normalize(mat3(model_matrix) * vertex_normal);
|
|
vec3 view_direction = normalize(camera_position - world_position);
|
|
frag_color.rgb *= max(dot(world_normal, view_direction), 0.0);
|
|
#endif
|
|
|
|
#ifdef RAINBOW
|
|
float rainbow_pos = rainbow_scale_y * (vertex_position.y + rainbow_offset_y);
|
|
frag_color.rgb *= hue2rgb(mod(rainbow_pos, 1.0f));
|
|
#endif
|
|
|
|
#ifdef REFLECTANCE
|
|
frag_color.rgb *= vertex_reflectance;
|
|
#endif
|
|
}
|