initial commit
This commit is contained in:
59
shaders/mesh/vertex_point.glsl
Normal file
59
shaders/mesh/vertex_point.glsl
Normal file
@@ -0,0 +1,59 @@
|
||||
layout (location = 0) uniform mat4 mvp_matrix;
|
||||
layout (location = 2) uniform float point_size;
|
||||
layout (location = 0) in vec3 vertex_position;
|
||||
layout (location = 0) out vec4 frag_color;
|
||||
|
||||
#ifdef TEXTURE
|
||||
layout (location = 3) uniform sampler2D tex;
|
||||
layout (location = 2) in vec2 vertex_tex_coord;
|
||||
#endif
|
||||
|
||||
#ifdef LIGHTING
|
||||
layout (location = 1) uniform mat4 model_matrix;
|
||||
layout (location = 4) uniform vec3 view_pos;
|
||||
layout (location = 5) uniform vec3 point_light_direction;
|
||||
layout (location = 6) uniform vec3 point_light_color;
|
||||
layout (location = 7) uniform vec3 ambient_light_color;
|
||||
layout (location = 8) uniform vec3 ambient_filter;
|
||||
layout (location = 9) uniform vec3 diffuse_filter;
|
||||
layout (location = 10) uniform vec3 specular_filter;
|
||||
layout (location = 11) uniform float shininess;
|
||||
layout (location = 1) in vec3 vertex_normal;
|
||||
#endif
|
||||
|
||||
#ifdef U_ALPHA
|
||||
layout (location = 12) uniform float alpha;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
||||
gl_Position = mvp_matrix * vec4(vertex_position, 1.0);
|
||||
gl_PointSize = point_size / gl_Position.w;
|
||||
|
||||
frag_color = vec4(1);
|
||||
|
||||
#ifdef TEXTURE
|
||||
frag_color *= texture(tex, vertex_tex_coord);
|
||||
#endif
|
||||
|
||||
#ifdef U_ALPHA
|
||||
frag_color.w *= alpha;
|
||||
#endif
|
||||
|
||||
#ifdef LIGHTING
|
||||
vec3 position = (model_matrix * vec4(vertex_position, 1.0)).xyz;
|
||||
vec3 normal = normalize(mat3(model_matrix) * vertex_normal);
|
||||
|
||||
vec3 ambient = frag_color.rgb * ambient_filter * ambient_light_color;
|
||||
|
||||
float point_light_alignment = max(dot(normal, point_light_direction), 0.0);
|
||||
vec3 diffuse = frag_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;
|
||||
|
||||
frag_color.rgb *= ambient + diffuse + specular;
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user