Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
*.exe
*.out
*.app

# Custom
.idea/*
build/*
bindings/*
debug/*
70 changes: 70 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
cmake_minimum_required(VERSION 3.0)
set(PROJECT_NAME "Task-3-3D-scene")

project(${PROJECT_NAME} CXX)

set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_CXX_STANDARD 17)

# CONFIG option is important so that CMake doesnt search for modules into the default modules directory
find_package(imgui CONFIG)
find_package(glfw CONFIG)
find_package(glew CONFIG)
find_package(fmt CONFIG)
find_package(glm CONFIG)
find_package(stb CONFIG)
find_package(assimp CONFIG)

add_executable(
${PROJECT_NAME}

src/main.cpp
src/settings.h

src/utils/mesh.h
src/utils/model.h
src/utils/opengl.h
src/utils/shader.cpp

src/elements/camera.h
src/elements/controller.h
src/elements/light.h
src/elements/object.h
src/elements/cubemap.h
src/elements/torus.h
src/elements/window.h

bindings/imgui_impl_glfw.cpp
bindings/imgui_impl_opengl3.cpp
)

add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/assets ${PROJECT_BINARY_DIR}/assets
)

target_compile_definitions(
${PROJECT_NAME}
PUBLIC
IMGUI_IMPL_OPENGL_LOADER_GLEW
)

target_link_libraries(
${PROJECT_NAME}
imgui::imgui
GLEW::glew_s
glfw::glfw
fmt::fmt
glm::glm
stb::stb
assimp::assimp
)

install(
DIRECTORY
${PROJECT_SOURCE_DIR}/assets

DESTINATION ${PROJECT_BINARY_DIR}
)
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
# ComputerGraphics-OpenGL
# 3D сцена

### Торическая земля:
- **Ландшафт** (max 1.25)
- Генерируется по карте высот (позиции вершин, нормали и текстурные координаты) (0.5)
- Текстурируется набором тайлов (0.25)
- переключение по высоте/нормали либо по карте материалов (+0.25)
- detail текстура при приближении (+0.25)
- **Торический ландшафт** (1)
- Карта высот применяется к тору, как к базовой поверхности.
- **Управляемая 3D модель** (1/1.25)
- Перемещается по поверхности торического ландшафта
- Ориентирована по карте высот
- "Приклеена" к карте высот
- Камера крепится к модели
- "Пружинная" камера (+0.25)
- **Источники света** (0.25/1.25)
- Фары/источник света, связанный с объектом, без теней (0.25)
- Направленный (солнце) + тени
- без каскадов (только объекта на ландшафт) (0.5)
- с каскадами (тени от ландшафта и объекта с самозатенением) (1)

## Запуск
Собираем проект:
1) Windows `build.bat`
2) Linux `build.sh`

Далее запускаем `build/Task-3-3Dscene`

## Примеры
![](screenshots/HW3.png)

![](screenshots/HW3-2.png)

111 changes: 111 additions & 0 deletions assets/objects/aircraft/piper_pa18.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Blender MTL File: 'piper_pa18.blend'
# Material Count: 10

newmtl base
Ns 96.078431
Ka 0.300000 0.300000 0.300000
Kd 0.683972 0.355875 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 5
map_Kd textures/piper_diffuse.jpg
map_Bump textures/piper_bump.jpg

newmtl base_NONE
Ns 96.078431
Ka 0.300000 0.300000 0.300000
Kd 0.683972 0.355875 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 5
map_Bump textures/piper_bump.jpg
map_Kd textures/piper_diffuse.jpg

newmtl glass
Ns 96.078431
Ka 0.080000 0.080000 0.080000
Kd 0.683972 0.683972 0.683972
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.300000
d 0.100000
illum 7
map_Kd textures/piper_diffuse.jpg

newmtl glass_NONE
Ns 96.078431
Ka 0.080000 0.080000 0.080000
Kd 0.683972 0.683972 0.683972
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.300000
d 0.100000
illum 7

newmtl internals_alu
Ns 96.078431
Ka 0.500000 0.500000 0.500000
Kd 0.336015 0.336015 0.336015
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 5
map_Kd textures/piper_diffuse.jpg

newmtl internals_alu_NONE
Ns 96.078431
Ka 0.500000 0.500000 0.500000
Kd 0.336015 0.336015 0.336015
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 5

newmtl internals_b
Ns 96.078431
Ka 0.100000 0.100000 0.100000
Kd 0.007214 0.007214 0.007214
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 3

newmtl mirror
Ns 96.078431
Ka 0.080000 0.080000 0.080000
Kd 0.560000 0.560000 0.560000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 0.200000
illum 5

newmtl prop
Ns 96.078431
Ka 0.100000 0.100000 0.100000
Kd 0.011735 0.011735 0.011735
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 5
map_Kd textures/piper_diffuse.jpg

newmtl tires
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.005754 0.005754 0.005754
Ks 0.300000 0.300000 0.300000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd textures/piper_diffuse.jpg
map_Ks textures/piper_refl.jpg
Binary file added assets/objects/aircraft/textures/piper_bump.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/aircraft/textures/piper_refl.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/ball/Leather_Black_albedo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/ball/Leather_Black_normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/ball/Leather_White_albedo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/ball/Leather_White_normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions assets/objects/ball/Soccer_Ball.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 13.03.2019 02:41:43

newmtl Black
Ns 50.0000
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.5880 0.5880 0.5880
Kd 0.5880 0.5880 0.5880
Ks 0.6300 0.6300 0.6300
Ke 0.0000 0.0000 0.0000
map_Ka Leather_Black_albedo.jpg
map_Kd Leather_Black_albedo.jpg
map_bump Leather_Black_normal.jpg
bump Leather_Black_normal.jpg

newmtl White
Ns 50.0000
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.5880 0.5880 0.5880
Kd 0.5880 0.5880 0.5880
Ks 0.6300 0.6300 0.6300
Ke 0.0000 0.0000 0.0000
map_Ka Leather_White_albedo.jpg
map_Kd Leather_White_albedo.jpg
map_bump Leather_White_normal.jpg
bump Leather_White_normal.jpg

newmtl wire_086086086
Ns 32
d 1
Tr 0
Tf 1 1 1
illum 2
Ka 0.3373 0.3373 0.3373
Kd 0.3373 0.3373 0.3373
Ks 0.3500 0.3500 0.3500
1 change: 1 addition & 0 deletions assets/objects/ball/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Contains textures from Textures.com - Textures may not be redistributed. Check Textures.com for full licensing.
Binary file added assets/objects/skybox/textures/simple/back.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/skybox/textures/simple/bottom.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/skybox/textures/simple/front.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/skybox/textures/simple/left.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/skybox/textures/simple/right.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/skybox/textures/simple/top.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/torus/textures/grass_flower.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/torus/textures/grass_stone.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/torus/textures/height_map.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/torus/textures/height_map_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/torus/textures/plaster_wall.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/objects/torus/textures/soil.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions assets/shaders/cubemap_fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 330 core

out vec4 FragColor;

in vec3 tex_coords;

uniform samplerCube u_skybox;

void main() {
FragColor = texture(u_skybox, tex_coords);
}
14 changes: 14 additions & 0 deletions assets/shaders/cubemap_vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#version 330 core

layout (location = 0) in vec3 in_pos;

out vec3 tex_coords;

uniform mat4 u_projection;
uniform mat4 u_view;

void main() {
tex_coords = in_pos;
vec4 pos = u_projection * u_view * vec4(in_pos, 1.0);
gl_Position = pos.xyww;
}
5 changes: 5 additions & 0 deletions assets/shaders/light_fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#version 330 core

void main() {
gl_FragDepth = gl_FragCoord.z;
}
10 changes: 10 additions & 0 deletions assets/shaders/light_vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 330 core

layout (location = 0) in vec3 in_pos;

uniform mat4 u_projection;
uniform mat4 u_view;

void main() {
gl_Position = u_projection * u_view * vec4(in_pos, 1.0);
}
13 changes: 13 additions & 0 deletions assets/shaders/object_fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 330 core

out vec4 FragColor;

in vec3 vs_position;
in vec3 vs_normal;
in vec2 vs_texture_pos;

uniform sampler2D u_texture_1;

void main() {
FragColor = texture(u_texture_1, vs_texture_pos);
}
21 changes: 21 additions & 0 deletions assets/shaders/object_vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#version 330 core

layout (location = 0) in vec3 in_position;
layout (location = 1) in vec3 in_normal;
layout (location = 2) in vec2 in_texture_pos;

out vec3 vs_position;
out vec3 vs_normal;
out vec2 vs_texture_pos;

uniform mat4 u_model;
uniform mat4 u_view;
uniform mat4 u_projection;

void main() {
vs_position = vec3(u_model * vec4(in_position, 1.0));
vs_normal = mat3(transpose(inverse(u_model))) * in_normal;
vs_texture_pos = in_texture_pos;

gl_Position = u_projection * u_view * u_model * vec4(in_position, 1.0);
}
Loading