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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
*.exe
*.out
*.app

# Custom
.idea/*
build/*
bindings/*
59 changes: 59 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
cmake_minimum_required(VERSION 3.0)
project(Task-2-3Dobject 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(
Task-2-3Dobject

src/main.cpp
src/initials.h
src/buffers.h

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

bindings/imgui_impl_glfw.cpp
bindings/imgui_impl_opengl3.cpp

assets/skybox/skybox.vs
assets/skybox/skybox.fs
assets/nanosuit/nanosuit.vs
assets/nanosuit/nanosuit.fs
)

add_custom_command(
TARGET Task-2-3Dobject
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/assets ${PROJECT_BINARY_DIR}/assets
)

target_compile_definitions(
Task-2-3Dobject
PUBLIC
IMGUI_IMPL_OPENGL_LOADER_GLEW
)

target_link_libraries(
Task-2-3Dobject
imgui::imgui
GLEW::glew_s
glfw::glfw
fmt::fmt
glm::glm
stb::stb
assimp::assimp
)
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# ComputerGraphics-OpenGL
# 3D объект

### Условие
- загрузка и отрисовка 3D модели формата obj с текстурами
- отражения и преломления environment'а (cubemap/sphere map)
- навигация камеры воркуг объекта.
- в качестве образца берем логику навигации отсюда https://threejs.org/examples/#webgl_geometry_teapot
- камера всегда смотрит в центр сцены (условно, lookat=(0, 0, 0))
- mouse drag перемещает камеру по сфере с центром в lookat
- mouse zoom - приближает/отдаляет камеру (меняет радиус сферы)

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

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

## Примеры
- *With Fresnel coefficient*
![](screenshots/nanosuit_2.gif)

- *Without Fresnel coefficient*
![](screenshots/nanosuit.gif)

- *Without Fresnel coefficient*
![](screenshots/aircraft.gif)
111 changes: 111 additions & 0 deletions assets/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/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.
Binary file added assets/aircraft/textures/piper_diffuse.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/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.
40 changes: 40 additions & 0 deletions assets/nanosuit/nanosuit.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#version 330 core

out vec4 FragColor;

in vec3 normal;
in vec3 position;
in vec2 texture_coords;

uniform sampler2D texture_diffuse1;
uniform sampler2D texture_specular1;
uniform vec3 camera_pos;
uniform samplerCube skybox;

uniform float coefficient_texture;
uniform float coefficient_reflection;
uniform float coefficient_refraction;
uniform float fresnel_alpha;
uniform float frag_color_mix;

void main()
{
// Texture
vec4 texel_diffuse = texture2D(texture_diffuse1, texture_coords);
vec4 texel_specular = texture2D(texture_specular1, texture_coords);
vec4 result_texture = mix(texel_diffuse, texel_specular, coefficient_texture);

// Reflect, Refract, Fresnel
float angle = -dot(normalize(position - camera_pos), normalize(normal));
vec3 reflection = reflect(normalize(position - camera_pos), normalize(normal));
vec3 refraction = refract(normalize(position - camera_pos), normalize(normal), coefficient_refraction);
float coefficient_fresnel = pow(1 - angle, fresnel_alpha) * (1 - coefficient_reflection) + coefficient_reflection;

vec4 R = mix(
vec4(texture(skybox, refraction).rgb, 1.0),
vec4(texture(skybox, reflection).rgb, 1.0),
coefficient_fresnel
);

FragColor = mix(R, result_texture, frag_color_mix);
}
21 changes: 21 additions & 0 deletions assets/nanosuit/nanosuit.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#version 330 core

layout (location = 0) in vec3 in_pos;
layout (location = 1) in vec3 in_normal;
layout (location = 2) in vec2 in_texture_coord;

out vec2 texture_coords;
out vec3 normal;
out vec3 position;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main() {
texture_coords = in_texture_coord;
normal = mat3(transpose(inverse(model))) * in_normal;
position = vec3(model * vec4(in_pos, 1.0));

gl_Position = projection * view * model * vec4(in_pos, 1.0);
}
Binary file added assets/nanosuit/scene.bin
Binary file not shown.
Loading