100 lines
2.4 KiB
GLSL
100 lines
2.4 KiB
GLSL
#pragma STAGE: VERTEX
|
|
#pragma GEOMETRY: POINT_CLOUD
|
|
#pragma FEATURES: SQUARE V_L V_RGB V_A LIGHTING U_RGBA RAINBOW
|
|
#pragma STATIC_ENABLE: V_L V_RGB V_A LIGHTING U_RGBA RAINBOW
|
|
#pragma DYNAMIC_ENABLE:
|
|
|
|
#ifdef V_L
|
|
#ifdef V_RGB
|
|
#error Vertex luminance and vertex RGB are mutually exclusive
|
|
#endif
|
|
#endif
|
|
|
|
|
|
//------------[ Uniforms ]------------//
|
|
layout (location = 0) uniform mat4 mvp_matrix;
|
|
layout (location = 1) uniform float point_size;
|
|
|
|
#ifdef U_RGBA
|
|
layout (location = 2) uniform vec4 color;
|
|
#endif
|
|
|
|
|
|
#ifdef LIGHTING
|
|
layout (location = 3) uniform mat4 model_matrix;
|
|
layout (location = 4) uniform vec3 camera_position;
|
|
#endif
|
|
|
|
#ifdef RAINBOW
|
|
layout (location = 5) uniform float rainbow_offset_y;
|
|
layout (location = 6) uniform float rainbow_scale_y;
|
|
#endif
|
|
|
|
|
|
//------------[ Inputs ]------------//
|
|
layout (location = 0) in vec3 model_vertex_position;
|
|
#ifdef LIGHTING
|
|
layout (location = 1) in vec3 model_vertex_normal;
|
|
#endif
|
|
#ifdef V_L
|
|
layout (location = 2) in float model_vertex_l;
|
|
#endif
|
|
#ifdef V_RGB
|
|
layout (location = 2) in vec3 model_vertex_rgb;
|
|
#endif
|
|
#ifdef V_A
|
|
layout (location = 3) in float model_vertex_a;
|
|
#endif
|
|
|
|
|
|
//------------[ Outputs ]------------//
|
|
layout (location = 0) out vec4 clip_vertex_color;
|
|
|
|
|
|
#ifdef RAINBOW
|
|
// 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
|
|
|
|
|
|
void main()
|
|
{
|
|
gl_Position = mvp_matrix * vec4(model_vertex_position, 1.0);
|
|
gl_PointSize = point_size / gl_Position.w;
|
|
|
|
clip_vertex_color = vec4(1);
|
|
|
|
#ifdef V_L
|
|
clip_vertex_color.rgb *= model_vertex_l;
|
|
#endif
|
|
|
|
#ifdef V_RGB
|
|
clip_vertex_color.rgb *= model_vertex_rgb;
|
|
#endif
|
|
|
|
#ifdef V_A
|
|
clip_vertex_color.a *= model_vertex_a;
|
|
#endif
|
|
|
|
#ifdef U_RGBA
|
|
clip_vertex_color *= color;
|
|
#endif
|
|
|
|
#ifdef LIGHTING
|
|
vec3 world_position = vec3(model_matrix * vec4(model_vertex_position, 1.0));
|
|
vec3 world_normal = normalize(mat3(model_matrix) * model_vertex_normal);
|
|
vec3 view_direction = normalize(camera_position - world_position);
|
|
clip_vertex_color.rgb *= max(dot(world_normal, view_direction), 0.0);
|
|
#endif
|
|
|
|
#ifdef RAINBOW
|
|
float rainbow_pos = rainbow_scale_y * (model_vertex_position.y + rainbow_offset_y);
|
|
clip_vertex_color.rgb *= hue2rgb(mod(rainbow_pos, 1.0f));
|
|
#endif
|
|
}
|