100 lines
2.6 KiB
GLSL
100 lines
2.6 KiB
GLSL
#pragma STAGE: VERTEX
|
|
#pragma GEOMETRY: MESH
|
|
#pragma FEATURES: POINT V_L V_RGB V_A LIGHTING U_RGBA
|
|
#pragma STATIC_ENABLE: V_L V_RGB V_A LIGHTING U_RGBA
|
|
#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;
|
|
#ifdef LIGHTING
|
|
layout (location = 1) uniform mat4 model_matrix;
|
|
#endif
|
|
|
|
layout (location = 2) uniform float point_size;
|
|
|
|
#ifdef U_RGBA
|
|
layout (location = 4) uniform vec4 color;
|
|
#endif
|
|
|
|
#ifdef LIGHTING
|
|
|
|
layout (location = 5) uniform vec3 view_pos;
|
|
layout (location = 6) uniform vec3 point_light_direction;
|
|
layout (location = 7) uniform vec3 point_light_color;
|
|
layout (location = 8) uniform vec3 ambient_light_color;
|
|
|
|
layout (location = 9) uniform vec3 ambient_filter;
|
|
layout (location = 10) uniform vec3 diffuse_filter;
|
|
layout (location = 11) uniform vec3 specular_filter;
|
|
layout (location = 12) uniform float shininess;
|
|
#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;
|
|
|
|
|
|
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 position = (model_matrix * vec4(model_vertex_position, 1.0)).xyz;
|
|
vec3 normal = normalize(mat3(model_matrix) * model_vertex_normal);
|
|
|
|
vec3 ambient = clip_vertex_color.rgb * ambient_filter * ambient_light_color;
|
|
|
|
float point_light_alignment = max(dot(normal, point_light_direction), 0.0);
|
|
vec3 diffuse = clip_vertex_color.rgb * diffuse_filter * point_light_color * point_light_alignment;
|
|
|
|
vec3 reflection_dir = reflect(-point_light_direction, normal);
|
|
vec3 view_dir = normalize(position - view_pos);
|
|
float specular_strength = pow(max(dot(view_dir, reflection_dir), 0.0), shininess);
|
|
vec3 specular = specular_filter * point_light_color * specular_strength;
|
|
|
|
clip_vertex_color.rgb *= ambient + diffuse + specular;
|
|
#endif
|
|
}
|