initial commit
This commit is contained in:
64
shaders/mesh/fragment_face.glsl
Normal file
64
shaders/mesh/fragment_face.glsl
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifdef TEXTURE
|
||||
#ifdef U_COLOR
|
||||
#error Texture and color attribute are mutually exclusive.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
out vec4 pixel_color;
|
||||
|
||||
#ifdef TEXTURE
|
||||
layout (location = 3) uniform sampler2D tex;
|
||||
layout (location = 2) in vec2 frag_tex_coord;
|
||||
#endif
|
||||
|
||||
#ifdef U_COLOR
|
||||
layout (location = 3) uniform vec4 color;
|
||||
#endif
|
||||
|
||||
#ifdef LIGHTING
|
||||
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 = 0) in vec3 frag_position;
|
||||
layout (location = 1) in vec3 frag_normal;
|
||||
#endif
|
||||
|
||||
#ifdef U_ALPHA
|
||||
layout (location = 12) uniform float alpha;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
||||
pixel_color = vec4(1);
|
||||
|
||||
#ifdef TEXTURE
|
||||
pixel_color *= texture(tex, frag_tex_coord);
|
||||
#endif
|
||||
|
||||
#ifdef U_COLOR
|
||||
pixel_color *= color;
|
||||
#endif
|
||||
|
||||
#ifdef U_ALPHA
|
||||
pixel_color.w *= alpha;
|
||||
#endif
|
||||
|
||||
#ifdef LIGHTING
|
||||
vec3 ambient = pixel_color.rgb * ambient_filter * ambient_light_color;
|
||||
|
||||
float point_light_alignment = max(dot(frag_normal, point_light_direction), 0.0);
|
||||
vec3 diffuse = pixel_color.rgb * diffuse_filter * point_light_color * point_light_alignment;
|
||||
|
||||
vec3 reflection_dir = reflect(-point_light_direction, frag_normal);
|
||||
vec3 view_dir = normalize(frag_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;
|
||||
|
||||
pixel_color.rgb *= ambient + diffuse + specular;
|
||||
#endif
|
||||
}
|
||||
7
shaders/mesh/fragment_point.glsl
Normal file
7
shaders/mesh/fragment_point.glsl
Normal file
@@ -0,0 +1,7 @@
|
||||
layout (location = 0) in vec4 frag_color;
|
||||
|
||||
out vec4 pixel_color;
|
||||
|
||||
void main() {
|
||||
pixel_color = frag_color;
|
||||
}
|
||||
27
shaders/mesh/vertex_face.glsl
Normal file
27
shaders/mesh/vertex_face.glsl
Normal file
@@ -0,0 +1,27 @@
|
||||
layout (location = 0) uniform mat4 mvp_matrix;
|
||||
layout (location = 0) in vec3 vertex_position;
|
||||
|
||||
#ifdef LIGHTING
|
||||
layout (location = 1) uniform mat4 model_matrix;
|
||||
layout (location = 1) in vec3 vertex_normal;
|
||||
layout (location = 0) out vec3 frag_position;
|
||||
layout (location = 1) out vec3 frag_normal;
|
||||
#endif
|
||||
|
||||
#ifdef TEXTURE
|
||||
layout (location = 2) in vec2 vertex_tex_coord;
|
||||
layout (location = 2) out vec2 frag_tex_coord;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
gl_Position = mvp_matrix * vec4(vertex_position, 1.0);
|
||||
|
||||
#ifdef LIGHTING
|
||||
frag_position = (model_matrix * vec4(vertex_position, 1.0)).xyz;
|
||||
frag_normal = normalize(mat3(model_matrix) * vertex_normal);
|
||||
#endif
|
||||
|
||||
#ifdef TEXTURE
|
||||
frag_tex_coord = vertex_tex_coord;
|
||||
#endif
|
||||
}
|
||||
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
|
||||
}
|
||||
7
shaders/point_cloud/fragment.glsl
Normal file
7
shaders/point_cloud/fragment.glsl
Normal file
@@ -0,0 +1,7 @@
|
||||
layout (location = 0) in vec4 frag_color;
|
||||
|
||||
out vec4 pixel_color;
|
||||
|
||||
void main() {
|
||||
pixel_color = frag_color;
|
||||
}
|
||||
51
shaders/point_cloud/vertex.glsl
Normal file
51
shaders/point_cloud/vertex.glsl
Normal file
@@ -0,0 +1,51 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user