GUI: changed the main window

This commit is contained in:
Guillaume Meunier
2024-02-04 11:23:32 +01:00
parent 388f90e6c9
commit 20416aedf2
11 changed files with 1863 additions and 267 deletions
+49 -27
View File
@@ -19,9 +19,15 @@
#version 450
#define NB_TEXCOORDS 2
layout (constant_id = 0) const int nb_texcoords = 2;
layout (constant_id = 1) const int nb_joints = 1;
layout (constant_id = 2) const int nb_clipping = 1;
layout (constant_id = 3) const bool dithering = true;
layout (constant_id = 4) const bool alpha_cutout = false;
#define DITHERING
const float fog_min_dist = 20.0;
const float fog_max_dist = 35.0;
const vec4 fog_color = vec4(0.0, 0.25, 0.5, 1.0);
layout(set = 0, binding = 0) uniform scene_ubo
{
@@ -30,6 +36,7 @@ layout(set = 0, binding = 0) uniform scene_ubo
vec4 light_position;
vec4 ambient_color;
vec4 light_color;
// vec4 clipping_plane[8];
} scene;
layout(set = 0, binding = 1) uniform mesh_ubo
@@ -67,10 +74,10 @@ layout(set = 1, binding = 5) uniform material_ubo
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_normal;
layout(location = 2) in vec3 in_tangent;
layout(location = 3) in vec2 in_texcoord[NB_TEXCOORDS];
layout(location = 3+NB_TEXCOORDS) in vec4 in_color;
layout(location = 4+NB_TEXCOORDS) in vec4 in_joints;
layout(location = 5+NB_TEXCOORDS) in vec4 in_weights;
layout(location = 3) in vec2 in_texcoord[2];
layout(location = 5) in vec4 in_color;
layout(location = 6) in vec4 in_joints[nb_joints];
layout(location = 7) in vec4 in_weights[nb_joints];
#endif
// Vertex-to-fragment
@@ -81,9 +88,9 @@ layout(location = 5+NB_TEXCOORDS) in vec4 in_weights;
#endif
layout(location = 0) VERT_TO_FRAG vec3 normal;
layout(location = 1) VERT_TO_FRAG vec2 texcoord[NB_TEXCOORDS];
layout(location = 1+NB_TEXCOORDS) VERT_TO_FRAG vec3 frag_pos;
layout(location = 2+NB_TEXCOORDS) VERT_TO_FRAG vec4 light_pos;
layout(location = 1) VERT_TO_FRAG vec4 frag_pos;
layout(location = 2) VERT_TO_FRAG vec4 light_pos;
layout(location = 3) VERT_TO_FRAG vec2 texcoord[nb_texcoords];
// Fragment output
#ifdef FRAG_SHADER
@@ -92,35 +99,43 @@ layout(location = 0) out vec4 out_color;
// Shader code
#ifdef VERT_SHADER
// out float gl_ClipDistance[8];
// out float gl_CullDistance[8];
void main()
{
normal = vec3(mesh.modelview * vec4(in_normal, 0.0));
for(int i = 0; i < NB_TEXCOORDS; i++)
for(int i = 0; i < nb_texcoords; i++)
texcoord[i] = in_texcoord[i];
gl_Position = mesh.modelviewproj * vec4(in_position, 1.0);
frag_pos = vec3(mesh.modelview * vec4(in_position, 1.0));
frag_pos = mesh.modelview * vec4(in_position, 1.0);
light_pos = scene.view * scene.light_position;
// for(int i = 0; i < nb_clipping; i++)
// {
// gl_ClipDistance[i] = dot(scene.clipping_plane[i], frag_pos);
// gl_CullDistance[i] = dot(scene.clipping_plane[i], frag_pos);
// }
}
#endif
#ifdef FRAG_SHADER
#ifdef DITHERING
const float dither_pattern[4][4] = {
{ 0.0f, 0.5f, 0.125f, 0.625f},
{ 0.75f, 0.22f, 0.875f, 0.375f},
{ 0.1875f, 0.6875f, 0.0625f, 0.5625},
{ 0.9375f, 0.4375f, 0.8125f, 0.3125}
};
#endif
void main()
{
vec3 light_dir = normalize(light_pos.xyz - frag_pos * light_pos.w);
vec3 view_dir = normalize(frag_pos);
vec3 light_dir = normalize(light_pos.xyz - frag_pos.xyz * light_pos.w);
vec3 view_dir = normalize(frag_pos.xyz);
vec3 normal_unit = normalize(normal);
vec3 reflect_dir = reflect(-light_dir, normal_unit);
@@ -137,21 +152,28 @@ void main()
vec3 light = ambient + diffuse /*+ specular*/;
vec4 c = texture(base_color, texcoord[0]);
vec4 c = texture(base_color, fract(texcoord[0])) * vec4(light, 1.0);
if (c.a <= 0.5)
discard;
float fog = clamp((length(frag_pos) - fog_min_dist) / (fog_max_dist - fog_min_dist), 0.0, 1.0);
#ifdef DITHERING
ivec2 tmp = ivec2(gl_FragCoord.xy) % 4;
float dither_thd = dither_pattern[tmp.x][tmp.y];
c = mix(c, fog_color, fog);
vec4 color = c * vec4(light, 1.0) * 255.0f;
// vec4 c = vec4(1,1,1,1);
bvec4 tmp2 = greaterThan(fract(color), vec4(dither_thd, dither_thd, dither_thd, dither_thd));
out_color = (ceil(color) + vec4(tmp2)) / 255.0;
#else
out_color = c * vec4(light, 1.0);
#endif
// if (alpha_cutout && c.a <= 0.5)
// discard;
if (dithering)
{
ivec2 tmp = ivec2(gl_FragCoord.xy) % 4;
float dither_thd = dither_pattern[tmp.x][tmp.y];
vec4 color = c * 255.0f;
bvec4 tmp2 = greaterThan(fract(color), vec4(dither_thd, dither_thd, dither_thd, dither_thd));
out_color = (ceil(color) + vec4(tmp2)) / 255.0;
}
else
out_color = c;
}
#endif