Compare commits
33 Commits
00-getting
...
main
Author | SHA1 | Date | |
---|---|---|---|
71f6d03635 | |||
e9a9b8a2cf | |||
ce561fc44d | |||
acefc1d254 | |||
f65410b7ad | |||
0e43f07d80 | |||
e8f4f4ae12 | |||
3aed2a9614 | |||
21b8cc56f3 | |||
e6d5aac3d4 | |||
e29b519977 | |||
13bedc164c | |||
68cc990650 | |||
9de54d016d | |||
8447717875 | |||
ebcfe3eca9 | |||
19e722459d | |||
0a4fb8e76f | |||
806c260893 | |||
bfbdbf75f3 | |||
c4a607f660 | |||
c65a3ba314 | |||
b7e5eea448 | |||
e720355d04 | |||
fbda4821ee | |||
cc1f6afb26 | |||
621204abe5 | |||
1193e128e8 | |||
d0070045b1 | |||
6bcd4802aa | |||
9cbfa55c89 | |||
d8ab418180 | |||
babe58f0a5 |
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.cache
|
.cache
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
main
|
main
|
||||||
|
*.py
|
||||||
|
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "src/assimp"]
|
||||||
|
path = src/assimp
|
||||||
|
url = git@github.com:assimp/assimp
|
6
compile
@ -3,15 +3,15 @@
|
|||||||
CC=clang
|
CC=clang
|
||||||
CFLAGS="-g -c -Wall -Isrc/glad/include"
|
CFLAGS="-g -c -Wall -Isrc/glad/include"
|
||||||
CXX=clang++
|
CXX=clang++
|
||||||
CXXFLAGS="-g -Wall -std=c++20 $(pkg-config --cflags sdl2) -Isrc/glad/include -Isrc/glm"
|
CXXFLAGS="-g -Wall -std=c++20 $(pkg-config --cflags sdl2) -Isrc/glad/include -Isrc/glm -Isrc/assimp/include -Isrc/assimp/build/include"
|
||||||
LIBS="$(pkg-config --libs sdl2) -ldl"
|
LIBS="$(pkg-config --libs sdl2) -ldl -lz -lminizip -Lsrc/assimp/build/lib/ -lassimp"
|
||||||
GLAD_SRC="src/glad/src/glad.c"
|
GLAD_SRC="src/glad/src/glad.c"
|
||||||
GLAD_OBJ="glad.o"
|
GLAD_OBJ="glad.o"
|
||||||
SRC="src/*.cc $GLAD_OBJ src/glm/glm/glm.cppm"
|
SRC="src/*.cc $GLAD_OBJ src/glm/glm/glm.cppm"
|
||||||
OUT=main
|
OUT=main
|
||||||
|
|
||||||
(set -x ; $CC $CFLAGS $GLAD_SRC -o $GLAD_OBJ)
|
(set -x ; $CC $CFLAGS $GLAD_SRC -o $GLAD_OBJ)
|
||||||
(set -x ; $CXX $CXXFLAGS $LIBS $SRC -o $OUT)
|
(set -x ; $CXX $CXXFLAGS $SRC $LIBS -o $OUT)
|
||||||
|
|
||||||
if [[ -f $GLAD_OBJ ]]; then
|
if [[ -f $GLAD_OBJ ]]; then
|
||||||
rm $GLAD_OBJ
|
rm $GLAD_OBJ
|
||||||
|
BIN
images/container2.png
Normal file
After Width: | Height: | Size: 457 KiB |
BIN
images/container2_specular.png
Normal file
After Width: | Height: | Size: 141 KiB |
BIN
images/skybox/back.jpg
Normal file
After Width: | Height: | Size: 723 KiB |
BIN
images/skybox/bottom.jpg
Normal file
After Width: | Height: | Size: 274 KiB |
BIN
images/skybox/front.jpg
Normal file
After Width: | Height: | Size: 462 KiB |
BIN
images/skybox/left.jpg
Normal file
After Width: | Height: | Size: 588 KiB |
BIN
images/skybox/right.jpg
Normal file
After Width: | Height: | Size: 525 KiB |
BIN
images/skybox/top.jpg
Normal file
After Width: | Height: | Size: 338 KiB |
BIN
models/suzanne/diffuse.png
Normal file
After Width: | Height: | Size: 67 KiB |
BIN
models/suzanne/specular.png
Normal file
After Width: | Height: | Size: 526 KiB |
12
models/suzanne/suzanne.mtl
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Blender 4.3.2 MTL File: 'None'
|
||||||
|
# www.blender.org
|
||||||
|
|
||||||
|
newmtl Material
|
||||||
|
Ka 1.000000 1.000000 1.000000
|
||||||
|
Ks 0.500000 0.500000 0.500000
|
||||||
|
Ke 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.450000
|
||||||
|
d 1.000000
|
||||||
|
illum 2
|
||||||
|
map_Kd diffuse.png
|
||||||
|
map_Ks specular.png
|
2541
models/suzanne/suzanne.obj
Normal file
@ -1,13 +1,118 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
in vec2 tex_coords;
|
#define POINT_LIGHT_COUNT 4
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
sampler2D diffuse1;
|
||||||
|
sampler2D specular1;
|
||||||
|
float shininess;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DirLight {
|
||||||
|
vec3 direction;
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PointLight {
|
||||||
|
vec3 position;
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SpotLight {
|
||||||
|
vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
vec3 ambient;
|
||||||
|
vec3 diffuse;
|
||||||
|
vec3 specular;
|
||||||
|
float cutoff;
|
||||||
|
float outer_cutoff;
|
||||||
|
};
|
||||||
|
|
||||||
|
in VS_OUT {
|
||||||
|
vec3 vert_normal;
|
||||||
|
vec3 frag_position;
|
||||||
|
vec2 uv_coords;
|
||||||
|
} fs_in;
|
||||||
|
|
||||||
|
uniform Material material;
|
||||||
|
uniform DirLight directional_light;
|
||||||
|
uniform PointLight point_lights[POINT_LIGHT_COUNT];
|
||||||
|
uniform SpotLight spot_light;
|
||||||
|
|
||||||
|
layout (std140) uniform Common {
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
vec3 calc_dir_light(DirLight light, vec3 normal, vec3 view_direction);
|
||||||
|
vec3 calc_point_light(PointLight light, vec3 normal, vec3 frag_position, vec3 view_direction);
|
||||||
|
vec3 calc_spot_light(SpotLight light, vec3 normal, vec3 frag_position, vec3 view_direction);
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
uniform float mix_factor;
|
|
||||||
uniform sampler2D texture0;
|
|
||||||
uniform sampler2D texture1;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
color = mix(texture(texture0, tex_coords), texture(texture1, tex_coords), mix_factor);
|
vec3 normal = normalize(fs_in.vert_normal);
|
||||||
|
vec3 view_direction = normalize(fs_in.frag_position - camera_position);
|
||||||
|
|
||||||
|
vec3 result = calc_dir_light(directional_light, normal, view_direction);
|
||||||
|
|
||||||
|
for (int i = 0; i < POINT_LIGHT_COUNT; ++i) {
|
||||||
|
result += calc_point_light(point_lights[i], normal, fs_in.frag_position, view_direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
result += calc_spot_light(spot_light, normal, fs_in.frag_position, view_direction);
|
||||||
|
|
||||||
|
color = vec4(result, 1.0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
vec3 calc_dir_light(DirLight light, vec3 normal, vec3 view_direction) {
|
||||||
|
vec3 light_direction = normalize(-light.direction);
|
||||||
|
vec3 reflect_direction = reflect(-light_direction, normal);
|
||||||
|
float diff = max(dot(normal, light_direction), 0.0);
|
||||||
|
vec3 diff_tex = vec3(texture(material.diffuse1, fs_in.uv_coords));
|
||||||
|
float spec = pow(max(dot(reflect_direction, view_direction), 0.0), material.shininess);
|
||||||
|
vec3 ambient = light.ambient * diff_tex;
|
||||||
|
vec3 diffuse = light.diffuse * (diff * diff_tex);
|
||||||
|
vec3 specular = light.specular * (spec * vec3(texture(material.specular1, fs_in.uv_coords)));
|
||||||
|
|
||||||
|
return ambient + diffuse + specular;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 calc_point_light(PointLight light, vec3 normal, vec3 frag_position, vec3 view_direction) {
|
||||||
|
vec3 light_direction = normalize(light.position - frag_position);
|
||||||
|
vec3 reflect_direction = reflect(-light_direction, normal);
|
||||||
|
float distance = length(light.position - frag_position);
|
||||||
|
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||||
|
float diff = max(dot(normal, light_direction), 0.0);
|
||||||
|
vec3 diff_tex = vec3(texture(material.diffuse1, fs_in.uv_coords));
|
||||||
|
float spec = pow(max(dot(reflect_direction, view_direction), 0.0), material.shininess);
|
||||||
|
vec3 ambient = light.ambient * diff_tex * attenuation;
|
||||||
|
vec3 diffuse = light.diffuse * (diff * diff_tex) * attenuation;
|
||||||
|
vec3 specular = light.specular * (spec * vec3(texture(material.specular1, fs_in.uv_coords))) * attenuation;
|
||||||
|
|
||||||
|
return ambient + diffuse + specular;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 calc_spot_light(SpotLight light, vec3 normal, vec3 frag_position, vec3 view_direction) {
|
||||||
|
vec3 light_direction = normalize(light.position - frag_position);
|
||||||
|
vec3 reflect_direction = reflect(-light_direction, normal);
|
||||||
|
float theta = dot(light_direction, normalize(-light.direction));
|
||||||
|
float epsilon = light.cutoff - light.outer_cutoff;
|
||||||
|
float intensity = clamp((theta - light.outer_cutoff) / epsilon, 0.0, 1.0);
|
||||||
|
float diff = max(dot(normal, light_direction), 0.0);
|
||||||
|
float spec = pow(max(dot(reflect_direction, view_direction), 0.0), material.shininess);
|
||||||
|
vec3 diff_tex = vec3(texture(material.diffuse1, fs_in.uv_coords));
|
||||||
|
vec3 ambient = light.ambient * diff_tex;
|
||||||
|
vec3 diffuse = light.diffuse * (diff * diff_tex) * intensity;
|
||||||
|
vec3 specular = light.specular * (spec * vec3(texture(material.specular1, fs_in.uv_coords))) * intensity;
|
||||||
|
|
||||||
|
return ambient + diffuse + specular;
|
||||||
|
}
|
||||||
|
9
shaders/light_frag.glsl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
uniform vec3 light_diffuse;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
color = vec4(light_diffuse, 1.0);
|
||||||
|
}
|
18
shaders/light_vert.glsl
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
#define POINT_LIGHT_COUNT 4
|
||||||
|
|
||||||
|
layout(location=0) in vec3 position;
|
||||||
|
layout(location=1) in vec3 normal;
|
||||||
|
layout(location=2) in vec2 uv;
|
||||||
|
layout(location=3) in mat4 model;
|
||||||
|
|
||||||
|
layout (std140) uniform Common {
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = projection * view * model * vec4(position, 1.0);
|
||||||
|
};
|
7
shaders/normal_frag.glsl
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
color = vec4(1.0, 1.0, 0.0, 1.0);
|
||||||
|
}
|
34
shaders/normal_geo.glsl
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
#define MAGNITUDE 0.1
|
||||||
|
|
||||||
|
layout (triangles) in;
|
||||||
|
layout (line_strip, max_vertices = 6) out;
|
||||||
|
|
||||||
|
uniform float time;
|
||||||
|
|
||||||
|
in VS_OUT {
|
||||||
|
vec3 vert_normal;
|
||||||
|
} gs_in[];
|
||||||
|
|
||||||
|
layout (std140) uniform Common {
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
void generate_line(int index) {
|
||||||
|
gl_Position = projection * gl_in[index].gl_Position;
|
||||||
|
EmitVertex();
|
||||||
|
|
||||||
|
gl_Position = projection * (gl_in[index].gl_Position + vec4(gs_in[index].vert_normal, 1.0) * MAGNITUDE);
|
||||||
|
EmitVertex();
|
||||||
|
|
||||||
|
EndPrimitive();
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
for (int i = 0; i < 3; ++i) {
|
||||||
|
generate_line(i);
|
||||||
|
}
|
||||||
|
}
|
25
shaders/normal_vert.glsl
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout(location=0) in vec3 position;
|
||||||
|
layout(location=1) in vec3 normal;
|
||||||
|
layout(location=2) in vec2 uv;
|
||||||
|
|
||||||
|
uniform mat3 normal_mat;
|
||||||
|
uniform mat4 model;
|
||||||
|
|
||||||
|
layout (std140) uniform Common {
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
// interface block
|
||||||
|
out VS_OUT {
|
||||||
|
vec3 vert_normal;
|
||||||
|
} vs_out;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vs_out.vert_normal = normal_mat * normal;
|
||||||
|
|
||||||
|
gl_Position = view * model * vec4(position, 1.0);
|
||||||
|
};
|
17
shaders/pp_frag.glsl
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
sampler2D diffuse1;
|
||||||
|
sampler2D specular1;
|
||||||
|
float shininess;
|
||||||
|
};
|
||||||
|
|
||||||
|
in vec2 uv_coords;
|
||||||
|
|
||||||
|
uniform Material material;
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
color = vec4(vec3(texture(material.diffuse1, uv_coords)), 1.0);
|
||||||
|
}
|
12
shaders/pp_vert.glsl
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout(location=0) in vec3 position;
|
||||||
|
layout(location=1) in vec3 normal;
|
||||||
|
layout(location=2) in vec2 uv;
|
||||||
|
|
||||||
|
out vec2 uv_coords;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(position.x, position.y, 0.0, 1.0);
|
||||||
|
uv_coords = uv;
|
||||||
|
}
|
24
shaders/reflective_frag.glsl
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
in VS_OUT {
|
||||||
|
vec3 vert_normal;
|
||||||
|
vec3 frag_position;
|
||||||
|
vec2 uv_coords;
|
||||||
|
} fs_in;
|
||||||
|
|
||||||
|
uniform samplerCube cubemap;
|
||||||
|
|
||||||
|
layout (std140) uniform Common {
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec3 view_direction = normalize(fs_in.frag_position - camera_position);
|
||||||
|
vec3 reflect_direction = reflect(view_direction, normalize(fs_in.vert_normal));
|
||||||
|
|
||||||
|
color = vec4(texture(cubemap, reflect_direction).rgb, 1.0);
|
||||||
|
}
|
27
shaders/refractive_frag.glsl
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
#define AIR_IOR 1.0
|
||||||
|
#define GLASS_IOR 1.52
|
||||||
|
|
||||||
|
in VS_OUT {
|
||||||
|
vec3 vert_normal;
|
||||||
|
vec3 frag_position;
|
||||||
|
vec2 uv_coords;
|
||||||
|
} fs_in;
|
||||||
|
|
||||||
|
uniform samplerCube cubemap;
|
||||||
|
|
||||||
|
layout (std140) uniform Common {
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec3 view_direction = normalize(fs_in.frag_position - camera_position);
|
||||||
|
vec3 refract_direction = refract(view_direction, normalize(fs_in.vert_normal), AIR_IOR / GLASS_IOR);
|
||||||
|
|
||||||
|
color = vec4(texture(cubemap, refract_direction).rgb, 1.0);
|
||||||
|
}
|
11
shaders/sb_frag.glsl
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
in vec3 uv_coords;
|
||||||
|
|
||||||
|
uniform samplerCube cubemap;
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
color = texture(cubemap, uv_coords);
|
||||||
|
}
|
21
shaders/sb_vert.glsl
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#version 330 core
|
||||||
|
|
||||||
|
layout(location=0) in vec3 position;
|
||||||
|
layout(location=1) in vec3 normal;
|
||||||
|
layout(location=2) in vec2 uv;
|
||||||
|
|
||||||
|
uniform mat4 sb_view;
|
||||||
|
|
||||||
|
layout (std140) uniform Common {
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
out vec3 uv_coords;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 pos = projection * sb_view * vec4(position, 1.0);
|
||||||
|
gl_Position = pos.xyww;
|
||||||
|
uv_coords = position;
|
||||||
|
}
|
@ -1,15 +1,29 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout(location=0) in vec3 position;
|
layout(location=0) in vec3 position;
|
||||||
layout(location=1) in vec2 uv;
|
layout(location=1) in vec3 normal;
|
||||||
|
layout(location=2) in vec2 uv;
|
||||||
|
|
||||||
|
uniform mat3 normal_mat;
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
uniform mat4 view;
|
|
||||||
uniform mat4 projection;
|
|
||||||
|
|
||||||
out vec2 tex_coords;
|
layout (std140) uniform Common {
|
||||||
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
|
vec3 camera_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
// interface block
|
||||||
|
out VS_OUT {
|
||||||
|
vec3 vert_normal;
|
||||||
|
vec3 frag_position;
|
||||||
|
vec2 uv_coords;
|
||||||
|
} vs_out;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
tex_coords = uv;
|
vs_out.frag_position = vec3(model * vec4(position, 1.0));
|
||||||
|
vs_out.vert_normal = normal_mat * normal;
|
||||||
|
vs_out.uv_coords = uv;
|
||||||
|
|
||||||
gl_Position = projection * view * model * vec4(position, 1.0);
|
gl_Position = projection * view * model * vec4(position, 1.0);
|
||||||
};
|
};
|
||||||
|
1
src/assimp
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 258cdfd2bc29a920bbe749962abbcd58caa76422
|