Compare commits
1 Commits
main
...
00-getting
Author | SHA1 | Date | |
---|---|---|---|
e503f75d62 |
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
.cache
|
.cache
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
main
|
main
|
||||||
*.py
|
|
||||||
|
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
|||||||
[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 -Isrc/assimp/include -Isrc/assimp/build/include"
|
CXXFLAGS="-g -Wall -std=c++20 $(pkg-config --cflags sdl2) -Isrc/glad/include -Isrc/glm"
|
||||||
LIBS="$(pkg-config --libs sdl2) -ldl -lz -lminizip -Lsrc/assimp/build/lib/ -lassimp"
|
LIBS="$(pkg-config --libs sdl2) -ldl"
|
||||||
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 $SRC $LIBS -o $OUT)
|
(set -x ; $CXX $CXXFLAGS $LIBS $SRC -o $OUT)
|
||||||
|
|
||||||
if [[ -f $GLAD_OBJ ]]; then
|
if [[ -f $GLAD_OBJ ]]; then
|
||||||
rm $GLAD_OBJ
|
rm $GLAD_OBJ
|
||||||
|
Before Width: | Height: | Size: 457 KiB |
Before Width: | Height: | Size: 141 KiB |
Before Width: | Height: | Size: 723 KiB |
Before Width: | Height: | Size: 274 KiB |
Before Width: | Height: | Size: 462 KiB |
Before Width: | Height: | Size: 588 KiB |
Before Width: | Height: | Size: 525 KiB |
Before Width: | Height: | Size: 338 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 526 KiB |
@ -1,12 +0,0 @@
|
|||||||
# 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
|
|
@ -1,118 +1,13 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
#define POINT_LIGHT_COUNT 4
|
in vec2 tex_coords;
|
||||||
|
|
||||||
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() {
|
||||||
vec3 normal = normalize(fs_in.vert_normal);
|
color = mix(texture(texture0, tex_coords), texture(texture1, tex_coords), mix_factor);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
|
|
||||||
out vec4 color;
|
|
||||||
|
|
||||||
uniform vec3 light_diffuse;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
color = vec4(light_diffuse, 1.0);
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
#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);
|
|
||||||
};
|
|
@ -1,7 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
|
|
||||||
out vec4 color;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
color = vec4(1.0, 1.0, 0.0, 1.0);
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
#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);
|
|
||||||
};
|
|
@ -1,17 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
|
|
||||||
in vec3 uv_coords;
|
|
||||||
|
|
||||||
uniform samplerCube cubemap;
|
|
||||||
|
|
||||||
out vec4 color;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
color = texture(cubemap, uv_coords);
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
#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,29 +1,15 @@
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
layout(location=0) in vec3 position;
|
layout(location=0) in vec3 position;
|
||||||
layout(location=1) in vec3 normal;
|
layout(location=1) in vec2 uv;
|
||||||
layout(location=2) in vec2 uv;
|
|
||||||
|
|
||||||
uniform mat3 normal_mat;
|
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
|
uniform mat4 view;
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
layout (std140) uniform Common {
|
out vec2 tex_coords;
|
||||||
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() {
|
||||||
vs_out.frag_position = vec3(model * vec4(position, 1.0));
|
tex_coords = uv;
|
||||||
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 +0,0 @@
|
|||||||
Subproject commit 258cdfd2bc29a920bbe749962abbcd58caa76422
|
|