first commit

This commit is contained in:
2026-03-28 22:36:32 +01:00
commit 4ab7f93ac6
39 changed files with 2142 additions and 0 deletions

44
shaders/default.frag Normal file
View File

@@ -0,0 +1,44 @@
#version 460 core
in vec2 v_texcoord;
in vec3 v_normal;
in vec3 v_position;
layout (binding = 1, std140) uniform Light {
uniform vec4 light_color;
uniform vec3 light_pos;
uniform vec3 camera_pos;
};
uniform sampler2D u_texture;
out vec4 f_color;
vec4 pointLight() {
vec3 light_vector = light_pos - v_position;
float dist = length(light_vector);
float a = 1.0;
float b = 0.7;
float intensity = 1 / (a * dist * dist + b * dist + 1.0f);
// ambient lighting
float ambient = 0.2;
// diffuse lighting
float diffuse_light = 0.7;
vec3 normal = normalize(v_normal);
vec3 light_direction = normalize(light_vector);
float diffuse = diffuse_light * max(dot(normal, light_direction), 0);
// specular lighting
float specular_light = 0.7;
vec3 view_direction = normalize(camera_pos - v_position);
vec3 reflection_direction = reflect(-light_direction, normal);
vec3 halfway_vec = normalize(view_direction + light_direction);
float specular = specular_light * pow(max(dot(normal, halfway_vec), 0), 100);
return (texture(u_texture, v_texcoord) * (diffuse * intensity + ambient) + specular * intensity) * light_color;
}
void main() {
f_color = pointLight();
}

72
shaders/default.vert Normal file
View File

@@ -0,0 +1,72 @@
#version 460 core
struct PositionData {
float x;
float y;
float z;
};
struct UvData {
float u;
float v;
};
struct NormalData {
float x;
float y;
float z;
};
layout (binding = 0, std430) restrict readonly buffer _positions {
PositionData pos_data[];
};
layout (binding = 1, std430) restrict readonly buffer _uvs {
UvData uv_data[];
};
layout (binding = 2, std430) restrict readonly buffer _normals {
NormalData norm_data[];
};
vec4 getPosition(int index) {
return vec4(
pos_data[index].x,
pos_data[index].y,
pos_data[index].z,
1
);
}
vec2 getUv(int index) {
return vec2(
uv_data[index].u,
uv_data[index].v
);
}
vec3 getNormal(int index) {
return vec3(
norm_data[index].x,
norm_data[index].y,
norm_data[index].z
);
}
uniform mat4 u_model_matrix;
uniform mat4 u_normal_matrix;
layout (binding = 0, std140) uniform SharedMatrices {
mat4 projection;
mat4 cam_matrix;
};
out vec2 v_texcoord;
out vec3 v_normal;
out vec3 v_position;
void main() {
gl_Position = projection * cam_matrix * u_model_matrix * getPosition(gl_VertexID);
v_texcoord = getUv(gl_VertexID);
v_normal = mat3(u_normal_matrix) * getNormal(gl_VertexID);
v_position = vec3(u_model_matrix * getPosition(gl_VertexID));
}

13
shaders/light.frag Normal file
View File

@@ -0,0 +1,13 @@
#version 460 core
layout (binding = 1, std140) uniform Light {
uniform vec4 light_color;
uniform vec3 light_pos;
uniform vec3 camera_pos;
};
out vec4 f_color;
void main() {
f_color = light_color;
}

19
shaders/light.vert Normal file
View File

@@ -0,0 +1,19 @@
#version 460 core
layout (binding = 0, std140) uniform SharedMatrices {
mat4 projection;
mat4 cam_matrix;
};
layout (binding = 1, std140) uniform Light {
uniform vec4 light_color;
uniform vec3 light_pos;
uniform vec3 camera_pos;
};
uniform vec4 u_position;
void main() {
gl_Position = projection * cam_matrix * u_position;
gl_PointSize = 20 / distance(u_position.xyz, camera_pos);
}

10
shaders/skybox.frag Normal file
View File

@@ -0,0 +1,10 @@
#version 460 core
in vec3 v_texcoord;
out vec4 f_color;
uniform samplerCube cubemap_texture;
void main() {
f_color = texture(cubemap_texture, v_texcoord);
}

35
shaders/skybox.vert Normal file
View File

@@ -0,0 +1,35 @@
#version 460 core
// layout (location = 0) in vec3 a_position;
struct PositionData {
float x;
float y;
float z;
};
layout (binding = 0, std430) restrict readonly buffer _positions {
PositionData pos_data[];
};
vec4 getPosition(int index) {
return vec4(
pos_data[index].x,
pos_data[index].y,
pos_data[index].z,
1
);
}
layout (binding = 0, std140) uniform SharedMatrices {
mat4 projection;
mat4 cam_matrix;
};
out vec3 v_texcoord;
void main() {
vec4 a_position = getPosition(gl_VertexID);
vec4 WVP_position = projection * mat4(mat3(cam_matrix)) * a_position;
gl_Position = WVP_position.xyww;
v_texcoord = a_position.xyz;
}