Started refactor to lazily compilable shaders.

This commit is contained in:
zy4n
2025-03-02 22:56:53 +01:00
parent 447146b7f5
commit 925125e99b
50 changed files with 2181 additions and 738 deletions

View File

@@ -0,0 +1,59 @@
#pragma STAGE: FRAGMENT
#pragma GEOMETRY: MESH
#pragma FEATURES: FACE LINE V_L V_RGB V_A LIGHTING TEXTURE U_RGBA
#pragma FEATURE_TOGGLES: LIGHTING TEXTURE
//------------[ Uniforms ]------------//
#ifdef TEXTURE
layout (location = 3) uniform sampler2D tex;
#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 vec4 frag_color;
#ifdef LIGHTING
layout (location = 1) in vec3 frag_position;
layout (location = 2) in vec3 frag_normal;
#endif
#ifdef TEXTURE
layout (location = 2) in vec2 frag_tex_coord;
#endif
//------------[ Outputs ]------------//
layout (location = 0) out vec4 pixel_color;
void main()
{
pixel_color = frag_color;
#ifdef TEXTURE
pixel_color *= texture(tex, frag_tex_coord);
#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
}

View File

@@ -0,0 +1,18 @@
#pragma STAGE: FRAGMENT
#pragma GEOMETRY: MESH
#pragma FEATURES: POINT V_L V_RGB V_A LIGHTING U_RGBA
#pragma FEATURE_TOGGLES:
//------------[ Inputs ]------------//
layout (location = 0) in vec4 frag_color;
//------------[ Outputs ]------------//
layout (location = 0) out vec4 pixel_color;
void main()
{
pixel_color = frag_color;
}

View File

@@ -0,0 +1,18 @@
#pragma STAGE: FRAGMENT
#pragma GEOMETRY: POINT_CLOUD
#pragma FEATURES: SQUARE V_L V_RGB V_A LIGHTING U_RGBA RAINBOW
#pragma FEATURE_TOGGLES:
//------------[ Inputs ]------------//
layout (location = 0) in vec4 frag_color;
//------------[ Outputs ]------------//
layout (location = 0) out vec4 pixel_color;
void main()
{
pixel_color = frag_color;
}

View File

@@ -1,64 +0,0 @@
#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
}

View File

@@ -1,7 +0,0 @@
layout (location = 0) in vec4 frag_color;
out vec4 pixel_color;
void main() {
pixel_color = frag_color;
}

View File

@@ -1,27 +0,0 @@
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
}

View File

@@ -1,59 +0,0 @@
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
}

View File

@@ -1,7 +0,0 @@
layout (location = 0) in vec4 frag_color;
out vec4 pixel_color;
void main() {
pixel_color = frag_color;
}

View File

@@ -1,51 +0,0 @@
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
}

View File

@@ -0,0 +1,84 @@
#pragma STAGE: VERTEX
#pragma GEOMETRY: MESH
#pragma FEATURES: FACE LINE V_L V_RGB V_A LIGHTING TEXTURE U_RGBA
#pragma FEATURE_TOGGLES: V_L V_RGB V_A LIGHTING TEXTURE U_RGBA
#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
#ifdef U_RGBA
layout (location = 4) uniform vec4 color;
#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
#ifdef TEXTURE
layout (location = 4) in vec2 model_vertex_tex_coord;
#endif
//------------[ Outputs ]------------//
layout (location = 0) out vec4 clip_vertex_color;
#ifdef LIGHTING
layout (location = 1) out vec3 clip_vertex_position;
layout (location = 2) out vec3 clip_vertex_normal;
#endif
#ifdef TEXTURE
layout (location = 3) out vec2 clip_vertex_tex_coord;
#endif
void main()
{
gl_Position = mvp_matrix * vec4(model_vertex_position, 1.0);
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
clip_vertex_position = (model_matrix * vec4(model_vertex_position, 1.0)).xyz;
clip_vertex_normal = normalize(mat3(model_matrix) * model_vertex_normal);
#endif
#ifdef TEXTURE
clip_vertex_tex_coord = model_vertex_tex_coord;
#endif
}

View File

@@ -0,0 +1,94 @@
#pragma STAGE: VERTEX
#pragma GEOMETRY: MESH
#pragma FEATURES: POINT V_L V_RGB V_A LIGHTING U_RGBA
#pragma FEATURE_TOGGLES: V_L V_RGB V_A LIGHTING U_RGBA
#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
}

View File

@@ -0,0 +1,95 @@
#pragma STAGE: VERTEX
#pragma GEOMETRY: POINT_CLOUD
#pragma FEATURES: SQUARE V_L V_RGB V_A LIGHTING U_RGBA RAINBOW
#pragma FEATURE_TOGGLES: V_L V_RGB V_A LIGHTING U_RGBA RAINBOW
#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
}