diff --git a/cw 9/Debug/Box.obj b/cw 9/Debug/Box.obj index 3ab6155..2d8ffe6 100644 Binary files a/cw 9/Debug/Box.obj and b/cw 9/Debug/Box.obj differ diff --git a/cw 9/Debug/Camera.obj b/cw 9/Debug/Camera.obj index 19f1346..42b0429 100644 Binary files a/cw 9/Debug/Camera.obj and b/cw 9/Debug/Camera.obj differ diff --git a/cw 9/Debug/Render_Utils.obj b/cw 9/Debug/Render_Utils.obj index 2fa824d..d1aecb6 100644 Binary files a/cw 9/Debug/Render_Utils.obj and b/cw 9/Debug/Render_Utils.obj differ diff --git a/cw 9/Debug/SOIL.obj b/cw 9/Debug/SOIL.obj index 993ed3d..5a43150 100644 Binary files a/cw 9/Debug/SOIL.obj and b/cw 9/Debug/SOIL.obj differ diff --git a/cw 9/Debug/Shader_Loader.obj b/cw 9/Debug/Shader_Loader.obj index 9731480..2b9e80f 100644 Binary files a/cw 9/Debug/Shader_Loader.obj and b/cw 9/Debug/Shader_Loader.obj differ diff --git a/cw 9/Debug/Texture.obj b/cw 9/Debug/Texture.obj index 0ac257b..6f58084 100644 Binary files a/cw 9/Debug/Texture.obj and b/cw 9/Debug/Texture.obj differ diff --git a/cw 9/Debug/grk-cw9.log b/cw 9/Debug/grk-cw9.log index 86e6428..2053f55 100644 --- a/cw 9/Debug/grk-cw9.log +++ b/cw 9/Debug/grk-cw9.log @@ -1,64 +1,33 @@ -c:\software\vs19\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(513,5): warning MSB8028: The intermediate directory (Debug\) contains files shared from another project (grk-cw9.vcxproj). This can lead to incorrect clean and rebuild behavior. +C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(513,5): warning MSB8028: Katalog pośredni (Debug\) zawiera pliki udostępnione z innego projektu (grk-cw9.vcxproj). Może to spowodować niepoprawne zachowanie podczas oczyszczania i ponownej kompilacji. main.cpp -C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition -J:\GrafikaKomputerowa\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY' -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(74,30): warning C4305: 'initializing': truncation from 'double' to 'float' -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(88,38): warning C4305: '=': truncation from 'double' to 'float' -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(111,16): warning C4305: 'initializing': truncation from 'double' to 'float' -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(159,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(176,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(183,108): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: "APIENTRY": ponowna definicja makra +C:\Users\Genos\Source\Repos\GRK_Room\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY” +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(95,30): warning C4305: "inicjowanie": obcięcie z "double" do "float" +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(116,38): warning C4305: "=": obcięcie z "double" do "float" +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(139,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(158,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(250,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(271,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(280,108): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(191,87): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(288,87): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(191,223): warning C4305: 'argument': truncation from 'double' to 'float' -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(194,59): warning C4305: 'argument': truncation from 'double' to 'T' +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(288,223): warning C4305: "argument": obcięcie z "double" do "float" +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(291,59): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(195,37): warning C4305: 'argument': truncation from 'double' to 'float' -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(227,2): warning C4305: 'argument': truncation from 'double' to 'float' -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(330,21): warning C4305: '-=': truncation from 'double' to 'float' -J:\GrafikaKomputerowa\grk\cw 9\src\room.hpp(332,21): warning C4305: '+=': truncation from 'double' to 'float' - Render_Utils.cpp - Texture.cpp - Generating Code... - image_DXT.c -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_DXT.c(92,9): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. - image_helper.c -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(325,1): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(366,58): warning C4244: '=': conversion from 'double' to 'float', possible loss of data -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(373,46): warning C4244: '=': conversion from 'float' to 'int', possible loss of data -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(415,58): warning C4244: '=': conversion from 'double' to 'float', possible loss of data -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\image_helper.c(422,62): warning C4244: '=': conversion from 'float' to 'int', possible loss of data - SOIL.c -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\SOIL.c(1719,36): warning C4018: '<=': signed/unsigned mismatch -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\SOIL.c(1729,19): warning C4018: '<': signed/unsigned mismatch -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\SOIL.c(1841,6): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. - stb_image_aug.c -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(177,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(251,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(303,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(1557,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(2394,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(2709,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(2995,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(3209,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(3548,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stb_image_aug.c(3644,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(362,19): warning C4018: '>': signed/unsigned mismatch -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(366,19): warning C4018: '>': signed/unsigned mismatch -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(390,19): warning C4018: '<': signed/unsigned mismatch -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(427,19): warning C4018: '<': signed/unsigned mismatch -J:\GrafikaKomputerowa\grk\cw 9\src\SOIL\stbi_DDS_aug_c.h(498,14): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. - Generating Code... -Box.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification -LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library - grk-cw9.vcxproj -> J:\GrafikaKomputerowa\grk\Debug\room.exe +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(292,37): warning C4305: "argument": obcięcie z "double" do "float" +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(324,2): warning C4305: "argument": obcięcie z "double" do "float" +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(433,21): warning C4305: "-=": obcięcie z "double" do "float" +C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(435,21): warning C4305: "+=": obcięcie z "double" do "float" +Box.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO” +LINK : warning LNK4098: domyślna biblioteka „MSVCRT” powoduje konflikt z innymi bibliotekami; użyj opcji /NODEFAULTLIB:biblioteka + grk-cw9.vcxproj -> C:\Users\Genos\Source\Repos\GRK_Room\Debug\room.exe diff --git a/cw 9/Debug/image_DXT.obj b/cw 9/Debug/image_DXT.obj index a3d6ec3..29d349d 100644 Binary files a/cw 9/Debug/image_DXT.obj and b/cw 9/Debug/image_DXT.obj differ diff --git a/cw 9/Debug/image_helper.obj b/cw 9/Debug/image_helper.obj index 0ecdc3d..b176253 100644 Binary files a/cw 9/Debug/image_helper.obj and b/cw 9/Debug/image_helper.obj differ diff --git a/cw 9/Debug/main.obj b/cw 9/Debug/main.obj index 28f9409..f173242 100644 Binary files a/cw 9/Debug/main.obj and b/cw 9/Debug/main.obj differ diff --git a/cw 9/Debug/room.exe.recipe b/cw 9/Debug/room.exe.recipe index ab0edaf..f5db61d 100644 --- a/cw 9/Debug/room.exe.recipe +++ b/cw 9/Debug/room.exe.recipe @@ -2,7 +2,7 @@ - J:\GrafikaKomputerowa\grk\Debug\room.exe + C:\Users\Genos\Source\Repos\GRK_Room\Debug\room.exe diff --git a/cw 9/Debug/room.tlog/CL.command.1.tlog b/cw 9/Debug/room.tlog/CL.command.1.tlog index a598d1c..9db3035 100644 Binary files a/cw 9/Debug/room.tlog/CL.command.1.tlog and b/cw 9/Debug/room.tlog/CL.command.1.tlog differ diff --git a/cw 9/Debug/room.tlog/CL.read.1.tlog b/cw 9/Debug/room.tlog/CL.read.1.tlog index 401eb0f..10ebfb8 100644 Binary files a/cw 9/Debug/room.tlog/CL.read.1.tlog and b/cw 9/Debug/room.tlog/CL.read.1.tlog differ diff --git a/cw 9/Debug/room.tlog/CL.write.1.tlog b/cw 9/Debug/room.tlog/CL.write.1.tlog index 67762a4..70e984d 100644 Binary files a/cw 9/Debug/room.tlog/CL.write.1.tlog and b/cw 9/Debug/room.tlog/CL.write.1.tlog differ diff --git a/cw 9/Debug/room.tlog/link.command.1.tlog b/cw 9/Debug/room.tlog/link.command.1.tlog index 2f6240e..ed9824f 100644 Binary files a/cw 9/Debug/room.tlog/link.command.1.tlog and b/cw 9/Debug/room.tlog/link.command.1.tlog differ diff --git a/cw 9/Debug/room.tlog/link.read.1.tlog b/cw 9/Debug/room.tlog/link.read.1.tlog index 3c1c46d..87c9e76 100644 Binary files a/cw 9/Debug/room.tlog/link.read.1.tlog and b/cw 9/Debug/room.tlog/link.read.1.tlog differ diff --git a/cw 9/Debug/room.tlog/link.write.1.tlog b/cw 9/Debug/room.tlog/link.write.1.tlog index 627ad72..7d3b8db 100644 Binary files a/cw 9/Debug/room.tlog/link.write.1.tlog and b/cw 9/Debug/room.tlog/link.write.1.tlog differ diff --git a/cw 9/Debug/room.tlog/room.lastbuildstate b/cw 9/Debug/room.tlog/room.lastbuildstate index 12ab8a8..360eb4e 100644 --- a/cw 9/Debug/room.tlog/room.lastbuildstate +++ b/cw 9/Debug/room.tlog/room.lastbuildstate @@ -1,2 +1,2 @@ PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0: -Debug|Win32|J:\GrafikaKomputerowa\grk\| +Debug|Win32|C:\Users\Genos\Source\Repos\GRK_Room\| diff --git a/cw 9/Debug/stb_image_aug.obj b/cw 9/Debug/stb_image_aug.obj index f2d3c01..a82081e 100644 Binary files a/cw 9/Debug/stb_image_aug.obj and b/cw 9/Debug/stb_image_aug.obj differ diff --git a/cw 9/Debug/vc142.idb b/cw 9/Debug/vc142.idb index e5aa654..de4e1a9 100644 Binary files a/cw 9/Debug/vc142.idb and b/cw 9/Debug/vc142.idb differ diff --git a/cw 9/Debug/vc142.pdb b/cw 9/Debug/vc142.pdb index 2e2617e..595175f 100644 Binary files a/cw 9/Debug/vc142.pdb and b/cw 9/Debug/vc142.pdb differ diff --git a/cw 9/grk-cw9.vcxproj b/cw 9/grk-cw9.vcxproj index c9e3783..04488ff 100644 --- a/cw 9/grk-cw9.vcxproj +++ b/cw 9/grk-cw9.vcxproj @@ -41,6 +41,10 @@ + + + + diff --git a/cw 9/grk-cw9.vcxproj.filters b/cw 9/grk-cw9.vcxproj.filters index a011d53..02d13f3 100644 --- a/cw 9/grk-cw9.vcxproj.filters +++ b/cw 9/grk-cw9.vcxproj.filters @@ -109,5 +109,17 @@ Shader Files + + Shader Files + + + Shader Files + + + Shader Files + + + Shader Files + \ No newline at end of file diff --git a/cw 9/models/cube.obj b/cw 9/models/cube.obj new file mode 100644 index 0000000..4eb693e --- /dev/null +++ b/cw 9/models/cube.obj @@ -0,0 +1,40 @@ +# Blender v2.90.0 OBJ File: '' +# www.blender.org +mtllib cube.mtl +o Cube +v -10.000000 -10.000000 10.000000 +v -10.000000 10.000000 10.000000 +v -10.000000 -10.000000 -10.000000 +v -10.000000 10.000000 -10.000000 +v 10.000000 -10.000000 10.000000 +v 10.000000 10.000000 10.000000 +v 10.000000 -10.000000 -10.000000 +v 10.000000 10.000000 -10.000000 +vt 0.375000 0.000000 +vt 0.625000 0.000000 +vt 0.625000 0.250000 +vt 0.375000 0.250000 +vt 0.625000 0.500000 +vt 0.375000 0.500000 +vt 0.625000 0.750000 +vt 0.375000 0.750000 +vt 0.625000 1.000000 +vt 0.375000 1.000000 +vt 0.125000 0.500000 +vt 0.125000 0.750000 +vt 0.875000 0.500000 +vt 0.875000 0.750000 +vn -1.0000 0.0000 0.0000 +vn 0.0000 0.0000 -1.0000 +vn 1.0000 0.0000 0.0000 +vn 0.0000 0.0000 1.0000 +vn 0.0000 -1.0000 0.0000 +vn 0.0000 1.0000 0.0000 +usemtl _PBR +s 1 +f 1/1/1 2/2/1 4/3/1 3/4/1 +f 3/4/2 4/3/2 8/5/2 7/6/2 +f 7/6/3 8/5/3 6/7/3 5/8/3 +f 5/8/4 6/7/4 2/9/4 1/10/4 +f 3/11/5 7/6/5 5/8/5 1/12/5 +f 8/5/6 4/13/6 2/14/6 6/7/6 diff --git a/cw 9/shaders/shader_shadowmapsun.frag b/cw 9/shaders/shader_shadowmapsun.frag new file mode 100644 index 0000000..4116012 --- /dev/null +++ b/cw 9/shaders/shader_shadowmapsun.frag @@ -0,0 +1,5 @@ +#version 430 core + +void main() +{ +} \ No newline at end of file diff --git a/cw 9/shaders/shader_shadowmapsun.vert b/cw 9/shaders/shader_shadowmapsun.vert new file mode 100644 index 0000000..c018240 --- /dev/null +++ b/cw 9/shaders/shader_shadowmapsun.vert @@ -0,0 +1,13 @@ +#version 430 core + +layout(location = 0) in vec3 vertexPosition; +layout(location = 1) in vec3 vertexNormal; +layout(location = 2) in vec2 vertexTexCoord; + +uniform mat4 viewProjectionMatrix; +uniform mat4 modelMatrix; + +void main() +{ + gl_Position = viewProjectionMatrix * modelMatrix * vec4(vertexPosition, 1.0); +} \ No newline at end of file diff --git a/cw 9/shaders/shader_skybox.frag b/cw 9/shaders/shader_skybox.frag new file mode 100644 index 0000000..7052ca9 --- /dev/null +++ b/cw 9/shaders/shader_skybox.frag @@ -0,0 +1,12 @@ +#version 430 core + +uniform samplerCube skybox; + +in vec3 texCoord; + +out vec4 out_color; + +void main() +{ + out_color = texture(skybox,texCoord); +} \ No newline at end of file diff --git a/cw 9/shaders/shader_skybox.vert b/cw 9/shaders/shader_skybox.vert new file mode 100644 index 0000000..9fee19a --- /dev/null +++ b/cw 9/shaders/shader_skybox.vert @@ -0,0 +1,13 @@ +#version 430 core + +layout(location = 0) in vec3 vertexPosition; + +uniform mat4 transformation; + +out vec3 texCoord; + +void main() +{ + texCoord = vertexPosition; + gl_Position = transformation * vec4(vertexPosition, 1.0); +} \ No newline at end of file diff --git a/cw 9/src/room.hpp b/cw 9/src/room.hpp index be99109..b84d879 100644 --- a/cw 9/src/room.hpp +++ b/cw 9/src/room.hpp @@ -15,6 +15,9 @@ #include #include +#include "SOIL/SOIL.h" +#include "SOIL/stb_image_aug.h" + const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024; int WIDTH = 500, HEIGHT = 500; @@ -34,8 +37,24 @@ namespace models { Core::RenderContext sphereContext; Core::RenderContext windowContext; Core::RenderContext testContext; + } +namespace texture { + GLuint cubemapTexture; +} + +Core::RenderContext cubeContext;; +std::vector faces = +{ + "textures/skybox/right2.jpg", + "textures/skybox/left2.jpg", + "textures/skybox/top2.jpg", + "textures/skybox/bottom2.jpg", + "textures/skybox/front2.jpg", + "textures/skybox/back2.jpg", +}; + GLuint depthMapFBO; GLuint depthMap; @@ -43,6 +62,8 @@ GLuint program; GLuint programSun; GLuint programTest; GLuint programTex; +GLuint programDepth; +GLuint programSkybox; Core::Shader_Loader shaderLoader; @@ -73,6 +94,8 @@ glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0); glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9)*3; float spotlightPhi = 3.14 / 4; +glm::mat4 lightVP = glm::ortho(-10.f, 10.f, -10.f, 10.f, 1.0f, 30.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0)); + glm::mat4 scaleToRoom(glm::mat4 mat) { @@ -111,7 +134,7 @@ glm::mat4 createCameraMatrix() glm::mat4 createPerspectiveMatrix() { - + glm::mat4 perspectiveMatrix; float n = 0.05; float f = 20.; @@ -120,16 +143,60 @@ glm::mat4 createPerspectiveMatrix() perspectiveMatrix = glm::mat4({ 1,0.,0.,0., 0.,aspectRatio,0.,0., - 0.,0.,(f+n) / (n - f),2*f * n / (n - f), + 0.,0.,(f + n) / (n - f),2 * f * n / (n - f), 0.,0.,-1.,0., }); - - perspectiveMatrix=glm::transpose(perspectiveMatrix); + + perspectiveMatrix = glm::transpose(perspectiveMatrix); return perspectiveMatrix; } +void loadCubemap(std::vector faces) +{ + unsigned int textureID; + glGenTextures(1, &texture::cubemapTexture); + glBindTexture(GL_TEXTURE_CUBE_MAP, texture::cubemapTexture); + + int w, h; + unsigned char* data; + for (unsigned int i = 0; i < 6; i++) + { + data = SOIL_load_image(faces[i].c_str(), &w, &h, 0, SOIL_LOAD_RGBA); + glTexImage2D( + GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, + 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data + ); + } + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); +} + +void drawObjectDepth(Core::RenderContext& context, glm::mat4 viewProjection, glm::mat4 modelMatrix) +{ + glUseProgram(programDepth); + glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjection); + glUniformMatrix4fv(glGetUniformLocation(programDepth, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix); + + Core::DrawContext(context); + +} + +void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) { + glDisable(GL_DEPTH_TEST); + glUseProgram(programSkybox); + glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); + glm::mat4 transformation = viewProjectionMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(programSkybox, "transformation"), 1, GL_FALSE, (float*)&transformation); + glUniform1i(glGetUniformLocation(programSkybox, "skybox"), 0); + Core::DrawContext(context); + glEnable(GL_DEPTH_TEST); +} + void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) { glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); @@ -157,18 +224,41 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z); glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi); Core::DrawContext(context); - } +void initDepthMap() { + glGenFramebuffers(1, &depthMapFBO); + glGenTextures(1, &depthMap); + glBindTexture(GL_TEXTURE_2D, depthMap); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, + SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0); + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + glBindFramebuffer(GL_FRAMEBUFFER, 0); +} + + + void renderShadowapSun() { float time = glfwGetTime(); glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT); //uzupelnij o renderowanie glebokosci do tekstury - - - - + //ustawianie przestrzeni rysowania + glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT); + //bindowanie FBO + glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); + //czyszczenie mapy głębokości + glClear(GL_DEPTH_BUFFER_BIT); + //ustawianie programu + glUseProgram(programDepth); glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, WIDTH, HEIGHT); @@ -182,6 +272,8 @@ void renderScene(GLFWwindow* window) updateDeltaTime(time); renderShadowapSun(); + drawSkyBox(cubeContext, glm::translate(cameraPos)); + //space lamp glUseProgram(programSun); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); @@ -274,9 +366,15 @@ void init(GLFWwindow* window) program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag"); programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag"); programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag"); + programDepth = shaderLoader.CreateProgram("shaders/shader_shadowmapsun.vert", "shaders/shader_shadowmapsun.frag"); + + programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag"); + loadCubemap(faces); + initDepthMap(); loadModelToContext("./models/sphere.obj", sphereContext); loadModelToContext("./models/spaceship.obj", shipContext); + loadModelToContext("./models/cube.obj", cubeContext); loadModelToContext("./models/bed.obj", models::bedContext); diff --git a/cw 9/textures/room/Concrete_Wall_009_ambientOcclusion.jpg b/cw 9/textures/room/Concrete_Wall_009_ambientOcclusion.jpg new file mode 100644 index 0000000..3d2c313 Binary files /dev/null and b/cw 9/textures/room/Concrete_Wall_009_ambientOcclusion.jpg differ diff --git a/cw 9/textures/room/Concrete_Wall_009_basecolor.jpg b/cw 9/textures/room/Concrete_Wall_009_basecolor.jpg new file mode 100644 index 0000000..a01e092 Binary files /dev/null and b/cw 9/textures/room/Concrete_Wall_009_basecolor.jpg differ diff --git a/cw 9/textures/room/Concrete_Wall_009_height.png b/cw 9/textures/room/Concrete_Wall_009_height.png new file mode 100644 index 0000000..283b2cf Binary files /dev/null and b/cw 9/textures/room/Concrete_Wall_009_height.png differ diff --git a/cw 9/textures/room/Concrete_Wall_009_normal.jpg b/cw 9/textures/room/Concrete_Wall_009_normal.jpg new file mode 100644 index 0000000..d21d03c Binary files /dev/null and b/cw 9/textures/room/Concrete_Wall_009_normal.jpg differ diff --git a/cw 9/textures/room/wall_roughness.jpg b/cw 9/textures/room/wall_roughness.jpg new file mode 100644 index 0000000..f67ede4 Binary files /dev/null and b/cw 9/textures/room/wall_roughness.jpg differ diff --git a/cw 9/textures/skybox/back.jpg b/cw 9/textures/skybox/back.jpg new file mode 100644 index 0000000..470a679 Binary files /dev/null and b/cw 9/textures/skybox/back.jpg differ diff --git a/cw 9/textures/skybox/back2.jpg b/cw 9/textures/skybox/back2.jpg new file mode 100644 index 0000000..bdcd248 Binary files /dev/null and b/cw 9/textures/skybox/back2.jpg differ diff --git a/cw 9/textures/skybox/bottom.jpg b/cw 9/textures/skybox/bottom.jpg new file mode 100644 index 0000000..893f394 Binary files /dev/null and b/cw 9/textures/skybox/bottom.jpg differ diff --git a/cw 9/textures/skybox/bottom2.jpg b/cw 9/textures/skybox/bottom2.jpg new file mode 100644 index 0000000..579f002 Binary files /dev/null and b/cw 9/textures/skybox/bottom2.jpg differ diff --git a/cw 9/textures/skybox/front.jpg b/cw 9/textures/skybox/front.jpg new file mode 100644 index 0000000..4e17b77 Binary files /dev/null and b/cw 9/textures/skybox/front.jpg differ diff --git a/cw 9/textures/skybox/front2.jpg b/cw 9/textures/skybox/front2.jpg new file mode 100644 index 0000000..3be69fe Binary files /dev/null and b/cw 9/textures/skybox/front2.jpg differ diff --git a/cw 9/textures/skybox/left.jpg b/cw 9/textures/skybox/left.jpg new file mode 100644 index 0000000..5750b91 Binary files /dev/null and b/cw 9/textures/skybox/left.jpg differ diff --git a/cw 9/textures/skybox/left2.jpg b/cw 9/textures/skybox/left2.jpg new file mode 100644 index 0000000..9935b65 Binary files /dev/null and b/cw 9/textures/skybox/left2.jpg differ diff --git a/cw 9/textures/skybox/right.jpg b/cw 9/textures/skybox/right.jpg new file mode 100644 index 0000000..8963037 Binary files /dev/null and b/cw 9/textures/skybox/right.jpg differ diff --git a/cw 9/textures/skybox/right2.jpg b/cw 9/textures/skybox/right2.jpg new file mode 100644 index 0000000..dd4768d Binary files /dev/null and b/cw 9/textures/skybox/right2.jpg differ diff --git a/cw 9/textures/skybox/top.jpg b/cw 9/textures/skybox/top.jpg new file mode 100644 index 0000000..4db3c2a Binary files /dev/null and b/cw 9/textures/skybox/top.jpg differ diff --git a/cw 9/textures/skybox/top2.jpg b/cw 9/textures/skybox/top2.jpg new file mode 100644 index 0000000..6f3f0e3 Binary files /dev/null and b/cw 9/textures/skybox/top2.jpg differ