adding gfx and ui stuff
This commit is contained in:
29
gfx/assets/shaders/phong.fragment.glsl
Normal file
29
gfx/assets/shaders/phong.fragment.glsl
Normal file
@@ -0,0 +1,29 @@
|
||||
#version 330 core
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
uniform vec3 light_pos;
|
||||
uniform vec4 solid_color;
|
||||
uniform vec3 camera;
|
||||
|
||||
in vec3 normal;
|
||||
in vec3 frag_position;
|
||||
|
||||
void main() {
|
||||
vec4 light_color = vec4(1, 1, 1, 1);
|
||||
vec3 normal_norm = normalize(normal);
|
||||
vec3 light_direction_norm = normalize(light_pos - frag_position);
|
||||
|
||||
float ambient_strength = 0.15;
|
||||
vec4 ambient = ambient_strength * light_color;
|
||||
|
||||
float diffuse_strength = max(dot(normal_norm, light_direction_norm), 0.0);
|
||||
vec4 diffuse = diffuse_strength * light_color;
|
||||
|
||||
float specular_strength = 0.9;
|
||||
vec3 view_direction_norm = normalize(camera - frag_position);
|
||||
vec3 reflect_dir = reflect(-light_direction_norm, normal_norm);
|
||||
float spec = pow(max(dot(view_direction_norm, reflect_dir), 0.0), 32);
|
||||
vec4 specular = specular_strength * spec * light_color;
|
||||
|
||||
frag_color = specular + (ambient + diffuse) * solid_color;
|
||||
}
|
||||
19
gfx/assets/shaders/phong.vertex.glsl
Normal file
19
gfx/assets/shaders/phong.vertex.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 a_xyz;
|
||||
layout (location = 1) in vec2 a_uv;
|
||||
layout (location = 2) in vec3 a_normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
out vec3 normal;
|
||||
out vec3 frag_position;
|
||||
|
||||
void main() {
|
||||
vec4 a_xyz_vec4 = vec4(a_xyz, 1);
|
||||
|
||||
frag_position = (model * a_xyz_vec4).xyz;
|
||||
normal = mat3(transpose(inverse(model))) * a_normal;
|
||||
gl_Position = projection * view * model * a_xyz_vec4;
|
||||
}
|
||||
61
gfx/assets/shaders/rect.fragment.glsl
Normal file
61
gfx/assets/shaders/rect.fragment.glsl
Normal file
@@ -0,0 +1,61 @@
|
||||
#version 330 core
|
||||
out vec4 pixel_color;
|
||||
|
||||
in vec4 frag_color;
|
||||
in vec2 frag_dest_position;
|
||||
in vec2 frag_dest_center;
|
||||
in vec2 frag_dest_half_size;
|
||||
in float frag_softness;
|
||||
in float frag_border_radius;
|
||||
in float frag_border_thickness;
|
||||
in vec4 frag_border_color;
|
||||
in vec2 uv;
|
||||
|
||||
uniform sampler2D rect_tex;
|
||||
|
||||
float roundedRectSDF(vec2 sample_pos, vec2 rect_center, vec2 rect_half_size, float r) {
|
||||
vec2 d2 = (abs(rect_center - sample_pos) - rect_half_size + vec2(r, r));
|
||||
return min(max(d2.x, d2.y), 0.0) + length(max(d2, 0.0)) - r;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 softness_padding = vec2(
|
||||
max(0, frag_softness*2-1),
|
||||
max(0, frag_softness*2-1));
|
||||
|
||||
float border_factor = 1.0f;
|
||||
if (frag_border_thickness != 0) {
|
||||
vec2 interior_half_size = frag_dest_half_size - vec2(frag_border_thickness);
|
||||
|
||||
float interior_radius_reduce_f = min(
|
||||
interior_half_size.x / frag_dest_half_size.x,
|
||||
interior_half_size.y / frag_dest_half_size.y);
|
||||
|
||||
float interior_corner_radius = frag_border_radius * interior_radius_reduce_f * interior_radius_reduce_f;
|
||||
|
||||
float inside_d = roundedRectSDF(
|
||||
frag_dest_position,
|
||||
frag_dest_center,
|
||||
interior_half_size - softness_padding,
|
||||
interior_corner_radius);
|
||||
|
||||
|
||||
float inside_f = smoothstep(0, 2*frag_softness, inside_d);
|
||||
border_factor = inside_f;
|
||||
}
|
||||
|
||||
float dist = roundedRectSDF(
|
||||
frag_dest_position,
|
||||
frag_dest_center,
|
||||
frag_dest_half_size - softness_padding,
|
||||
frag_border_radius);
|
||||
|
||||
// For texturing later
|
||||
float sample = 1;
|
||||
|
||||
float sdf_factor = 1 - smoothstep(0, 2*frag_softness, dist);
|
||||
|
||||
vec4 out_color = frag_color; //* texture(rect_tex, uv);
|
||||
pixel_color = frag_border_color * sample * sdf_factor * border_factor
|
||||
+ out_color * sample * sdf_factor;
|
||||
};
|
||||
56
gfx/assets/shaders/rect.vertex.glsl
Normal file
56
gfx/assets/shaders/rect.vertex.glsl
Normal file
@@ -0,0 +1,56 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec2 p0;
|
||||
layout (location = 1) in vec2 p1;
|
||||
layout (location = 2) in vec4 color;
|
||||
layout (location = 3) in float border_radius;
|
||||
layout (location = 4) in float border_thickness;
|
||||
layout (location = 5) in vec4 border_color;
|
||||
layout (location = 6) in float edge_softness;
|
||||
|
||||
uniform mat4 projection;
|
||||
|
||||
out vec4 frag_color;
|
||||
out vec2 frag_dest_position;
|
||||
out vec2 frag_dest_center;
|
||||
out vec2 frag_dest_half_size;
|
||||
out float frag_softness;
|
||||
out float frag_border_radius;
|
||||
out float frag_border_thickness;
|
||||
out vec4 frag_border_color;
|
||||
out vec2 uv;
|
||||
|
||||
const vec2 rectangle_uv[4] = vec2[](
|
||||
vec2(0, 1),
|
||||
vec2(0, 0),
|
||||
vec2(1, 1),
|
||||
vec2(1, 0)
|
||||
);
|
||||
|
||||
const vec2 rectangle_vertices[4] = vec2[](
|
||||
vec2(-1, -1),
|
||||
vec2(-1, 1),
|
||||
vec2( 1, -1),
|
||||
vec2( 1, 1)
|
||||
);
|
||||
|
||||
void main() {
|
||||
vec2 dest_half_size = (p1 - p0) / 2;
|
||||
vec2 dest_center = (p1 + p0) / 2;
|
||||
vec2 dest_position = rectangle_vertices[gl_VertexID] * dest_half_size + dest_center;
|
||||
|
||||
gl_Position = projection * vec4(
|
||||
dest_position,
|
||||
0,
|
||||
1
|
||||
);
|
||||
|
||||
frag_color = color;
|
||||
frag_dest_position = dest_position;
|
||||
frag_dest_center = dest_center;
|
||||
frag_dest_half_size = dest_half_size;
|
||||
frag_border_radius = border_radius;
|
||||
frag_border_thickness = border_thickness;
|
||||
frag_border_color = border_color;
|
||||
frag_softness = edge_softness;
|
||||
uv = rectangle_uv[gl_VertexID];
|
||||
}
|
||||
11
gfx/assets/shaders/text.fragment.glsl
Normal file
11
gfx/assets/shaders/text.fragment.glsl
Normal file
@@ -0,0 +1,11 @@
|
||||
#version 330 core
|
||||
out vec4 pixel_color;
|
||||
|
||||
in vec4 frag_color;
|
||||
in vec2 frag_uv_position;
|
||||
|
||||
uniform sampler2D glyph_atlas;
|
||||
|
||||
void main() {
|
||||
pixel_color = vec4(frag_color.xyz,texture(glyph_atlas, frag_uv_position).r);
|
||||
};
|
||||
58
gfx/assets/shaders/text.vertex.glsl
Normal file
58
gfx/assets/shaders/text.vertex.glsl
Normal file
@@ -0,0 +1,58 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec2 begin;
|
||||
layout (location = 1) in int glyph;
|
||||
layout (location = 2) in float fontSize;
|
||||
layout (location = 3) in vec4 color;
|
||||
|
||||
uniform samplerBuffer glyph_table;
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform sampler2D font;
|
||||
|
||||
out vec4 frag_color;
|
||||
out vec2 frag_uv_position;
|
||||
|
||||
const vec2 rectangle_vertices[4] = vec2[](
|
||||
vec2(-1, -1), // bl
|
||||
vec2(-1, 1), // tl
|
||||
vec2( 1, -1), // br
|
||||
vec2( 1, 1) // tr
|
||||
);
|
||||
|
||||
const vec2 uv0_vertices[4] = vec2[](
|
||||
vec2(1, 0), // bl
|
||||
vec2(1, 1), // tl
|
||||
vec2(0, 0), // br
|
||||
vec2(0, 1) // tr
|
||||
);
|
||||
|
||||
const vec2 uv1_vertices[4] = vec2[](
|
||||
vec2(0, 1),
|
||||
vec2(0, 0),
|
||||
vec2(1, 1),
|
||||
vec2(1, 0)
|
||||
);
|
||||
|
||||
void main() {
|
||||
vec4 chunk1 = texelFetch(glyph_table, glyph * 2 + 0);
|
||||
vec4 chunk2 = texelFetch(glyph_table, glyph * 2 + 1);
|
||||
|
||||
vec2 uv0 = chunk1.xy;
|
||||
vec2 uv1 = chunk1.zw;
|
||||
vec2 offset = chunk2.xy;
|
||||
vec2 dims = chunk2.zw;
|
||||
|
||||
vec2 p0 = begin + offset*fontSize;
|
||||
vec2 p1 = begin + (offset + dims)*fontSize;
|
||||
|
||||
vec2 dest_half_size = (p1 - p0) / 2;
|
||||
vec2 dest_center = (p1 + p0) / 2;
|
||||
vec2 dest_position = rectangle_vertices[gl_VertexID] * dest_half_size + dest_center;
|
||||
|
||||
vec2 uv_position = uv0 * uv0_vertices[gl_VertexID] + uv1 * uv1_vertices[gl_VertexID];
|
||||
|
||||
gl_Position = projection * vec4(dest_position, 0, 1);
|
||||
|
||||
frag_color = color;
|
||||
frag_uv_position = vec2(uv_position.x, uv_position.y);
|
||||
}
|
||||
Reference in New Issue
Block a user