diff --git a/.vs/grk-project/v16/.suo b/.vs/grk-project/v16/.suo index 5564810..2e55598 100644 Binary files a/.vs/grk-project/v16/.suo and b/.vs/grk-project/v16/.suo differ diff --git a/Release/room.exe b/Release/room.exe index ffae9a8..c4e0ad5 100644 Binary files a/Release/room.exe and b/Release/room.exe differ diff --git a/Release/room.pdb b/Release/room.pdb index 5212b00..c770eaa 100644 Binary files a/Release/room.pdb and b/Release/room.pdb differ diff --git a/cw 9/Release/grk-cw9.log b/cw 9/Release/grk-cw9.log index d4188e8..d37adfd 100644 --- a/cw 9/Release/grk-cw9.log +++ b/cw 9/Release/grk-cw9.log @@ -1,35 +1,35 @@  main.cpp 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\annas\Desktop\graf\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY” -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(118,30): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(136,38): warning C4305: "=": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(159,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(180,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(199,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(305,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(316,96): warning C4305: "argument": obcięcie z "double" do "T" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(119,30): warning C4305: "inicjowanie": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(137,38): warning C4305: "=": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(160,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(181,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(200,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(306,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(317,96): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(320,59): warning C4305: "argument": obcięcie z "double" do "T" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(321,59): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(489,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(532,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(554,109): warning C4305: "argument": obcięcie z "double" do "T" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(493,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(536,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(570,109): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(614,2): warning C4305: "argument": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(755,21): warning C4305: "-=": obcięcie z "double" do "float" -C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(757,21): warning C4305: "+=": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(633,2): warning C4305: "argument": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(775,21): warning C4305: "-=": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(777,21): warning C4305: "+=": obcięcie z "double" do "float" Trwa generowanie kodu - 1 of 607 functions ( 0.2%) were compiled, the rest were copied from previous compilation. + 2 of 608 functions ( 0.3%) were compiled, the rest were copied from previous compilation. 0 functions were new in current compilation - 8 functions had inline decision re-evaluated but remain unchanged + 6 functions had inline decision re-evaluated but remain unchanged Zakończono generowanie kodu grk-cw9.vcxproj -> C:\Users\annas\Desktop\graf\Release\room.exe diff --git a/cw 9/Release/main.obj b/cw 9/Release/main.obj index f192f8a..c352bb3 100644 Binary files a/cw 9/Release/main.obj and b/cw 9/Release/main.obj differ diff --git a/cw 9/Release/room.iobj b/cw 9/Release/room.iobj index ec45081..9058f5b 100644 Binary files a/cw 9/Release/room.iobj and b/cw 9/Release/room.iobj differ diff --git a/cw 9/Release/room.ipdb b/cw 9/Release/room.ipdb index 2e9cb55..a080262 100644 Binary files a/cw 9/Release/room.ipdb and b/cw 9/Release/room.ipdb differ diff --git a/cw 9/Release/room.tlog/link.read.1.tlog b/cw 9/Release/room.tlog/link.read.1.tlog index 8c4df49..c1fa650 100644 Binary files a/cw 9/Release/room.tlog/link.read.1.tlog and b/cw 9/Release/room.tlog/link.read.1.tlog differ diff --git a/cw 9/Release/vc142.pdb b/cw 9/Release/vc142.pdb index a0992a2..bf0f9a5 100644 Binary files a/cw 9/Release/vc142.pdb and b/cw 9/Release/vc142.pdb differ diff --git a/cw 9/src/room.hpp b/cw 9/src/room.hpp index bc448ef..786cec5 100644 --- a/cw 9/src/room.hpp +++ b/cw 9/src/room.hpp @@ -47,6 +47,7 @@ namespace models { Core::RenderContext lightSwitchContext; Core::RenderContext easelContext; Core::RenderContext carContext; + Core::RenderContext vaseContext; } namespace texture { @@ -63,7 +64,7 @@ std::vector faces = "textures/skybox/left2.jpg", "textures/skybox/top2.jpg", "textures/skybox/bottom2.jpg", - "textures/skybox/front2.jpg", + "textures/skybox/front2.jpg", "textures/skybox/back2.jpg", }; @@ -343,9 +344,11 @@ void renderShadowapSun(GLuint depthFBO, glm::mat4 light) { drawObjectDepth(models::windowContext, light, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.45f)) * glm::translate(glm::vec3(-0.6f, 0, -0.25f))); //drawObjectPBR(models::windowContext, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.45f)) * glm::translate(glm::vec3(-0.6f, 0, -0.25f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); - drawObjectDepth(models::deskContext, light, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(0.2, 0.2, 0.2)) * glm::translate(glm::vec3(7.5f, 0.0f, -15.0f))); + //drawObjectDepth(models::deskContext, light, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(0.2, 0.2, 0.2)) * glm::translate(glm::vec3(7.5f, 0.0f, -15.0f))); + drawObjectDepth(models::deskContext, light, glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.9f))); drawObjectDepth(models::displayScreenContext, light, glm::scale(glm::vec3(0.1, 0.1, 0.1)) * glm::translate(glm::vec3(-28.5f, 9.0f, -20.0f))); - drawObjectDepth(models::chairContext, light, glm::scale(glm::vec3(0.03, 0.03, 0.03)) * glm::translate(glm::vec3(-100.5f, 0.0f, -35.0f))); + //drawObjectDepth(models::chairContext, light, glm::scale(glm::vec3(0.03, 0.03, 0.03)) * glm::translate(glm::vec3(-100.5f, 0.0f, -35.0f))); + drawObjectDepth(models::chairContext, light, glm::scale(glm::vec3(1.0f, 1.2f, 1.0f)) * glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.5f))); drawObjectDepth(models::ps5Context, light, glm::mat4()); drawObjectDepth(models::tvStandContext, light, glm::mat4()); drawObjectDepth(models::carpetContext, light, glm::mat4()); @@ -355,6 +358,7 @@ void renderShadowapSun(GLuint depthFBO, glm::mat4 light) { drawObjectDepth(models::bookshelfContext, light, glm::mat4()); drawObjectDepth(models::easelContext, light, glm::mat4()); drawObjectDepth(models::carContext, light, glm::translate(carPosTranform)); + drawObjectDepth(models::vaseContext, light, glm::translate(glm::vec3(1.1f, 1.41f, -2.2f))); glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir)); @@ -531,6 +535,18 @@ void renderScene(GLFWwindow* window) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float time = glfwGetTime(); updateDeltaTime(time); + // glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); + //glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir)); + //glm::mat4 specshipCameraRotrationMatrix = glm::mat4({ + // spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0, + // spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0, + // -spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0, + // 0.,0.,0.,1., + // }); + + //spotlightPos = spaceshipPos + 0.4 * spaceshipDir; + //spotlightConeDir = spaceshipDir; + renderShadowapSun(depthMapFBO, lightVP); renderShadowapSun(depthMapShipFBO, lightShipVP); glBindFramebuffer(GL_FRAMEBUFFER, bloomTextureFBO); @@ -573,9 +589,11 @@ void renderScene(GLFWwindow* window) drawObjectPBR(models::planeContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); //drawObjectPBR(models::roomContext, glm::scale(glm::vec3(2.5f, 1.0f, 1.f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.8f, 0.0f); drawObjectPBR(models::roomContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.8f, 0.0f); - drawObjectPBR(models::deskContext, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(0.2, 0.2, 0.2)) * glm::translate(glm::vec3(7.5f, 0.0f, -15.0f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.0f); + //drawObjectPBR(models::deskContext, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(0.2, 0.2, 0.2)) * glm::translate(glm::vec3(7.5f, 0.0f, -15.0f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.0f); + drawObjectPBR(models::deskContext, glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.9f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.0f); drawObjectPBR(models::displayScreenContext, glm::scale(glm::vec3(0.1, 0.1, 0.1)) * glm::translate(glm::vec3(-28.5f, 9.0f, -20.0f)), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.3f); - drawObjectPBR(models::chairContext, glm::scale(glm::vec3(0.03, 0.03, 0.03)) * glm::translate(glm::vec3(-100.5f, 0.0f, -35.0f)), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.2f); + //drawObjectPBR(models::chairContext, glm::scale(glm::vec3(0.03, 0.03, 0.03)) * glm::translate(glm::vec3(-100.5f, 0.0f, -35.0f)), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.2f); + drawObjectPBR(models::chairContext, glm::scale(glm::vec3(1.0f, 1.2f, 1.0f)) * glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.5f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.0f, 0.2f); drawObjectPBR(models::tvContext, glm::mat4(), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.2f); drawObjectPBR(models::ps5Context, glm::mat4(), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.2f); drawObjectPBR(models::tvStandContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); @@ -587,6 +605,7 @@ void renderScene(GLFWwindow* window) drawObjectPBR(models::lightSwitchContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); drawObjectPBR(models::easelContext, glm::mat4(), glm::vec3(0.6745098039215686f, 0.6352941176470588f, 0.6235294117647059f), 0.0f, 0.2f); drawObjectPBR(models::carContext, glm::translate(carPosTranform), glm::vec3(1.0f, 0.0f, 0.0f), 0.0f, 0.2f); + drawObjectPBR(models::vaseContext, glm::translate(glm::vec3(1.1f, 1.41f, -2.2f)), glm::vec3(244.0f / 255.0f, 245.0f / 255.0f, 220.0f / 255.0f), 0.0f, 0.2f); // draw windows drawObjectPBR(models::windowContext, glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.2f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); drawObjectPBR(models::windowContext, glm::eulerAngleY(3.14f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.3f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); @@ -703,6 +722,7 @@ void init(GLFWwindow* window) loadModelToContext("./models/light_switch/light_switch.obj", models::lightSwitchContext); loadModelToContext("./models/easel/easel3.obj", models::easelContext); loadModelToContext("./models/car/car.obj", models::carContext); + loadModelToContext("./models/ceramic_vase_02_4k.obj", models::vaseContext); initDepthMap(); initDepthMapShip(); diff --git a/enc_temp_folder/7db4ba62dac9767a19dadd6a101862/room.hpp b/enc_temp_folder/7db4ba62dac9767a19dadd6a101862/room.hpp new file mode 100644 index 0000000..002ab19 --- /dev/null +++ b/enc_temp_folder/7db4ba62dac9767a19dadd6a101862/room.hpp @@ -0,0 +1,810 @@ +#include "glew.h" +#include +#include "glm.hpp" +#include "ext.hpp" +#include +#include + +#include "Shader_Loader.h" +#include "Render_Utils.h" +#include "Texture.h" + +#include "Box.cpp" +#include +#include +#include +#include +#include +#include "SOIL/SOIL.h" +#include "SOIL/stb_image_aug.h" + +const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024; + +int WIDTH = 800, HEIGHT = 800; + +namespace models { + Core::RenderContext couchContext; + Core::RenderContext coffeeTableContext; + Core::RenderContext doorContext; + Core::RenderContext drawerContext; + Core::RenderContext planeContext; + Core::RenderContext roomContext; + Core::RenderContext deskContext; + Core::RenderContext spaceshipContext; + Core::RenderContext sphereContext; + Core::RenderContext windowContext; + Core::RenderContext testContext; + Core::RenderContext chairContext; + Core::RenderContext displayScreenContext; + Core::RenderContext tvContext; + Core::RenderContext ps5Context; + Core::RenderContext tvStandContext; + Core::RenderContext carpetContext; + Core::RenderContext cabinet1Context; + Core::RenderContext cabinet2Context; + Core::RenderContext lampContext; + Core::RenderContext bookshelfContext; + Core::RenderContext lightSwitchContext; + Core::RenderContext easelContext; + Core::RenderContext carContext; + Core::RenderContext vaseContext; +} + +namespace texture { + GLuint cubemapTexture; + + GLuint earth; + GLuint earthNormal; +} + +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; + +GLuint depthMapShipFBO; +GLuint depthMapShip; + +GLuint bloomTextureFBO; + +GLuint program; +GLuint programSun; +GLuint programTest; +GLuint programTex; +GLuint programDepth; +GLuint programSkybox; +GLuint programBlur; + +Core::Shader_Loader shaderLoader; + +Core::RenderContext shipContext; +Core::RenderContext sphereContext; + +glm::vec3 sunPos = glm::vec3(-4.740971f, 2.149999f, 0.369280f); +glm::vec3 sunDir = glm::vec3(-0.93633f, 0.351106, 0.003226f); +glm::vec3 sunColor = glm::vec3(0.9f, 0.9f, 0.7f)*5; + +glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f); +glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f); + + +glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f); +glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f); + +unsigned int colorBuffers[2]; +unsigned int pingpongFBO[2]; +unsigned int pingpongBuffer[2]; + +GLuint VAO,VBO; + +float aspectRatio = 1.f; + +float exposition = 1.f; + +glm::vec3 pointlightPos = glm::vec3(0, 2, 0); +glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6); //cienie z latarki + +glm::vec3 spotlightPos = glm::vec3(0, 0, 0); +glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0); +glm::vec3 spotlightColor = glm::vec3(1.0, 1.0, 1.0)*10; +float spotlightPhi = 3.14 / 4; + +glm::mat4 lightVP = glm::ortho(-4.f, 3.f, -2.5f, 5.f, -10.0f, 20.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0)); // +glm::mat4 lightShipVP; + +float lastTime = -1.f; +float deltaTime = 0.f; + +bool lightOn = true; +glm::vec3 carPosTranform = glm::vec3(0, 0, 0); + +void updateDeltaTime(float time) { + if (lastTime < 0) { + lastTime = time; + return; + } + + deltaTime = time - lastTime; + if (deltaTime > 0.1) deltaTime = 0.1; + lastTime = time; +} +glm::mat4 createCameraMatrix() +{ + glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir,glm::vec3(0.f,1.f,0.f))); + glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide,cameraDir)); + glm::mat4 cameraRotrationMatrix = glm::mat4({ + cameraSide.x,cameraSide.y,cameraSide.z,0, + cameraUp.x,cameraUp.y,cameraUp.z ,0, + -cameraDir.x,-cameraDir.y,-cameraDir.z,0, + 0.,0.,0.,1., + }); + cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix); + glm::mat4 cameraMatrix = cameraRotrationMatrix * glm::translate(-cameraPos); + + return cameraMatrix; +} + +glm::mat4 createPerspectiveMatrix() //do shaderow +{ + + glm::mat4 perspectiveMatrix; + float n = 0.05; + float f = 20.; + float a1 = glm::min(aspectRatio, 1.f); + float a2 = glm::min(1 / aspectRatio, 1.f); + perspectiveMatrix = glm::mat4({ + 1,0.,0.,0., + 0.,aspectRatio,0.,0., + 0.,0.,(f + n) / (n - f),2 * f * n / (n - f), + 0.,0.,-1.,0., + }); + + + perspectiveMatrix = glm::transpose(perspectiveMatrix); + + return perspectiveMatrix; +} + +glm::mat4 createPerspectiveMatrix(float scale) +{ + + glm::mat4 perspectiveMatrix; + float n = 0.05; + float f = 20.; + float a1 = glm::min(aspectRatio, 1.f); + float a2 = glm::min(1 / aspectRatio, 1.f); + perspectiveMatrix = glm::mat4({ + 1 * scale,0,0.,0., + 0.,1 * scale,0.,0., + 0.,0.,(f + n) / (n - f),2 * f * n / (n - f), + 0.,0.,-1.,0., + }); + + + 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::SetActiveTexture(texture::cubemapTexture, "skybox", programSkybox, 0); + glUniform1f(glGetUniformLocation(programSkybox, "exposition"), exposition); + if (lightOn) + glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z); + else + glUniform3f(glGetUniformLocation(program, "lightPos"), 1000.f, 1000.f, 1000.f); + Core::DrawContext(context); + glEnable(GL_DEPTH_TEST); +} + +//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); +// Core::SetActiveTexture(texture::cubemapTexture, "skybox", programSkybox, 0); +// glUniform1f(glGetUniformLocation(programSkybox, "exposition"), exposition); +// +// Core::DrawContext(context); +// +// glEnable(GL_DEPTH_TEST); +//} + +void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) { + glActiveTexture(GL_TEXTURE0); + glUniform1i(glGetUniformLocation(program, "depthMap"), 0); + glBindTexture(GL_TEXTURE_2D, depthMap); + glUniformMatrix4fv(glGetUniformLocation(program, "lightVP"), 1, GL_FALSE, (float*)&lightVP); + + glActiveTexture(GL_TEXTURE1); + glUniform1i(glGetUniformLocation(program, "depthMapShip"), 1); + glBindTexture(GL_TEXTURE_2D, depthMapShip); + glUniformMatrix4fv(glGetUniformLocation(program, "lightShipVP"), 1, GL_FALSE, (float*)&lightShipVP); + + glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); + glm::mat4 transformation = viewProjectionMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation); + glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix); + + glUniform1f(glGetUniformLocation(program, "exposition"), exposition); + + glUniform1f(glGetUniformLocation(program, "roughness"), roughness); + glUniform1f(glGetUniformLocation(program, "metallic"), metallic); + + glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z); + + glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z); + + glUniform3f(glGetUniformLocation(program, "sunDir"), sunDir.x, sunDir.y, sunDir.z); + glUniform3f(glGetUniformLocation(program, "sunColor"), sunColor.x, sunColor.y, sunColor.z); + + glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z); + glUniform3f(glGetUniformLocation(program, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z); + + glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spotlightConeDir.x, spotlightConeDir.y, spotlightConeDir.z); + glUniform3f(glGetUniformLocation(program, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z); + glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z); + glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi); + + //Core::SetActiveTexture(texture::earth, "colorTexture", program, 2); + //Core::SetActiveTexture(texture::earthNormal, "normalSampler", program, 3); + Core::DrawContext(context); +} +void renderShadowapSun(GLuint depthFBO, glm::mat4 light) { + float time = glfwGetTime(); + //uzupelnij o renderowanie glebokosci do tekstury + //ustawianie przestrzeni rysowania + glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT); + //bindowanie FBO + glBindFramebuffer(GL_FRAMEBUFFER, depthFBO); + //czyszczenie mapy głębokości + glClear(GL_DEPTH_BUFFER_BIT); + //ustawianie programu + glUseProgram(programDepth); + + drawObjectDepth(sphereContext, light, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f))); + + drawObjectDepth(sphereContext, + light, + glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f))); + + drawObjectDepth(models::couchContext, light, glm::scale(glm::vec3(0.5f)) * glm::translate(glm::vec3(8.4f, 0, -0.4f)) * glm::eulerAngleY(3.15f)); + //drawObjectPBR(models::couchContext, glm::scale(glm::vec3(0.5f)) * glm::translate(glm::vec3(8.4f, 0, -0.4f)) * glm::eulerAngleY(3.15f), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f); + + drawObjectDepth(models::coffeeTableContext, light, glm::translate(glm::vec3(2.8f, 0, 0.5f))); + //drawObjectPBR(models::coffeeTableContext, glm::translate(glm::vec3(2.8f, 0, 0.5f)), glm::vec3(1.f, 1.f, 1.f), 0.4f, 0.0f); + + drawObjectDepth(models::doorContext, light, glm::mat4()); + //drawObjectPBR(models::doorContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + + drawObjectDepth(models::planeContext, light, glm::mat4()); + //drawObjectPBR(models::planeContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + + drawObjectDepth(models::roomContext, light, glm::mat4()); + //drawObjectPBR(models::roomContext, glm::scale(glm::vec3(2.5f, 1.0f, 1.f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.8f, 0.0f); + + // draw windows + drawObjectDepth(models::windowContext, light, glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.2f))); + //drawObjectPBR(models::windowContext, glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.2f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + + drawObjectDepth(models::windowContext, light, glm::eulerAngleY(3.14f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.3f))); + //drawObjectPBR(models::windowContext, glm::eulerAngleY(3.14f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.3f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + + drawObjectDepth(models::windowContext, light, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.45f)) * glm::translate(glm::vec3(-0.6f, 0, -0.25f))); + //drawObjectPBR(models::windowContext, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.45f)) * glm::translate(glm::vec3(-0.6f, 0, -0.25f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + //drawObjectDepth(models::deskContext, light, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(0.2, 0.2, 0.2)) * glm::translate(glm::vec3(7.5f, 0.0f, -15.0f))); + drawObjectDepth(models::deskContext, light, glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.9f))); + drawObjectDepth(models::displayScreenContext, light, glm::scale(glm::vec3(0.1, 0.1, 0.1)) * glm::translate(glm::vec3(-28.5f, 9.0f, -20.0f))); + //drawObjectDepth(models::chairContext, light, glm::scale(glm::vec3(0.03, 0.03, 0.03)) * glm::translate(glm::vec3(-100.5f, 0.0f, -35.0f))); + drawObjectDepth(models::chairContext, light, glm::scale(glm::vec3(1.0f, 1.2f, 1.0f)) * glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.5f))); + drawObjectDepth(models::ps5Context, light, glm::mat4()); + drawObjectDepth(models::tvStandContext, light, glm::mat4()); + drawObjectDepth(models::carpetContext, light, glm::mat4()); + drawObjectDepth(models::cabinet1Context, light, glm::mat4()); + drawObjectDepth(models::cabinet2Context, light, glm::mat4()); + drawObjectDepth(models::lampContext, light, glm::mat4()); + drawObjectDepth(models::bookshelfContext, light, glm::mat4()); + drawObjectDepth(models::easelContext, light, glm::mat4()); + drawObjectDepth(models::carContext, light, glm::translate(carPosTranform)); + drawObjectDepth(models::vaseContext, light, glm::translate(glm::vec3(1.1f, 1.41f, -2.2f))); + + glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); + glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir)); + glm::mat4 specshipCameraRotrationMatrix = glm::mat4({ + spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0, + spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0, + -spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0, + 0.,0.,0.,1., + }); + + /*drawObjectDepth(models::deskContext,light, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(0.2,0.2,0.2)) * glm::translate(glm::vec3(7.5f,0.0f, -15.0f))); + drawObjectDepth(models::displayScreenContext,light, glm::scale(glm::vec3(0.1,0.1,0.1)) * glm::translate(glm::vec3(-28.5f,9.0f, -20.0f))); + drawObjectDepth(models::chairContext, light, glm::scale(glm::vec3(0.03,0.03,0.03)) * glm::translate(glm::vec3(-100.5f,0.0f, -35.0f)));*/ + + + //drawObjectColor(shipContext, + // glm::translate(cameraPos + 1.5 * cameraDir + cameraUp * -0.5f) * inveseCameraRotrationMatrix * glm::eulerAngleY(glm::pi()), + // glm::vec3(0.3, 0.3, 0.5) + // ); + drawObjectDepth(shipContext, + light, + glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi()) * glm::scale(glm::vec3(0.03f)) + ); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glViewport(0, 0, WIDTH, HEIGHT); +} + +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 initDepthMapShip() +{ + glGenFramebuffers(1, &depthMapShipFBO); + glGenTextures(1, &depthMapShip); + glBindTexture(GL_TEXTURE_2D, depthMapShip); + 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, depthMapShipFBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMapShip, 0); + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + glBindFramebuffer(GL_FRAMEBUFFER, 0); +} + +void initBloom() +{ + // set up floating point framebuffer to render scene to + glGenFramebuffers(1, &bloomTextureFBO); + glBindFramebuffer(GL_FRAMEBUFFER, bloomTextureFBO); + + glGenTextures(2, colorBuffers); + for (unsigned int i = 0; i < 2; i++) + { + glBindTexture(GL_TEXTURE_2D, colorBuffers[i]); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGBA16F, WIDTH, HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + // attach texture to framebuffer + glFramebufferTexture2D( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, colorBuffers[i], 0 + ); + unsigned int rboDepth; + + glGenRenderbuffers(1, &rboDepth); + glBindRenderbuffer(GL_RENDERBUFFER, rboDepth); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, WIDTH, HEIGHT); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth); + + unsigned int attachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 }; + glDrawBuffers(2, attachments); + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + std::cout << "Framebuffer not complete!" << std::endl; + } +} + +void initPingPong() +{ + + glGenFramebuffers(2, pingpongFBO); + glGenTextures(2, pingpongBuffer); + for (unsigned int i = 0; i < 2; i++) + { + glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]); + glBindTexture(GL_TEXTURE_2D, pingpongBuffer[i]); + glTexImage2D( + GL_TEXTURE_2D, 0, GL_RGBA16F, WIDTH, HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL + ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glFramebufferTexture2D( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongBuffer[i], 0 + ); + glBindTexture(GL_TEXTURE_2D, 0); + } +} + +void pingPongBluring() +{ + + bool horizontal = true, first_iteration = true; + int amount = 50; + glUseProgram(programBlur); + + for (unsigned int i = 0; i < amount; i++) + { + glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]); + glUniform1i(glGetUniformLocation(programBlur, "horizontal"), horizontal); + glBindTexture( + GL_TEXTURE_2D, first_iteration ? colorBuffers[1] : pingpongBuffer[!horizontal] + ); + Core::SetActiveTexture(first_iteration ? colorBuffers[1] : pingpongBuffer[!horizontal], "image",programBlur, 0); + Core::DrawContext(models::testContext); + horizontal = !horizontal; + if (first_iteration) + first_iteration = false; + } + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + /**for (unsigned int i = 0; i < amount; i++) + { + glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]); + glUniform1i(glGetUniformLocation(programBlur, "horizontal"), horizontal); + + if (first_iteration) + { + glBindTexture(GL_TEXTURE_2D, bloomTextureFBO); + first_iteration = false; + } + else + { + glBindTexture(GL_TEXTURE_2D, pingpongBuffer[!horizontal]); + } + //Tu powinnismy rysować obiekt? wywołac funkcje drawObjectPBR? + Core::DrawContext(models::couchContext); + horizontal = !horizontal; + } + glBindFramebuffer(GL_FRAMEBUFFER, 0);**/ +} + +void renderScene(GLFWwindow* window) +{ + spotlightPos = spaceshipPos + 0.2 * spaceshipDir; + spotlightConeDir = spaceshipDir; + lightShipVP = createPerspectiveMatrix(0.5) * glm::lookAt(spotlightPos, spotlightPos + spotlightConeDir, glm::vec3(0, 1, 0)); + glClearColor(1.f, 1, 1, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + float time = glfwGetTime(); + updateDeltaTime(time); + // glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); + //glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir)); + //glm::mat4 specshipCameraRotrationMatrix = glm::mat4({ + // spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0, + // spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0, + // -spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0, + // 0.,0.,0.,1., + // }); + + //spotlightPos = spaceshipPos + 0.4 * spaceshipDir; + //spotlightConeDir = spaceshipDir; + + renderShadowapSun(depthMapFBO, lightVP); + renderShadowapSun(depthMapShipFBO, lightShipVP); + glBindFramebuffer(GL_FRAMEBUFFER, bloomTextureFBO); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glViewport(0,0,WIDTH, HEIGHT); + + drawSkyBox(cubeContext, glm::translate(cameraPos)); + + //space lamp + /*glUseProgram(programSun); + glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); + glm::mat4 transformation = viewProjectionMatrix * glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)); + glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation); + glUniform3f(glGetUniformLocation(programSun, "color"), sunColor.x / 2, sunColor.y / 2, sunColor.z / 2); + glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition); + Core::DrawContext(sphereContext);*/ + + if (lightOn) { + glUseProgram(programSun); + glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); + glm::mat4 transformation = viewProjectionMatrix * glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)); + glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation); + glUniform3f(glGetUniformLocation(programSun, "color"), sunColor.x / 2, sunColor.y / 2, sunColor.z / 2); + glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition); + Core::DrawContext(sphereContext); + } + + //pingPongBluring(time); + glUseProgram(program); + + + /*drawObjectPBR(sphereContext, + glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)), + glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0);*/ + + //drawObjectPBR(models::drawerContext, glm::mat4(), glm::vec3(0.428691f, 0.08022f, 0.036889f), 0.2f, 0.0f); + //drawObjectPBR(models::couchContext, glm::scale(glm::vec3(0.5f)) * glm::translate(glm::vec3(8.4f, 0, -0.4f)) * glm::eulerAngleY(3.15f), glm::vec3(0.03f, 0.03f, 0.03f), 0.2f, 0.0f); + drawObjectPBR(models::coffeeTableContext, glm::translate(glm::vec3(2.8f, 0, 0.5f)), glm::vec3(1.f, 1.f, 1.f), 0.4f, 0.0f); + drawObjectPBR(models::doorContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + drawObjectPBR(models::planeContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + //drawObjectPBR(models::roomContext, glm::scale(glm::vec3(2.5f, 1.0f, 1.f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.8f, 0.0f); + drawObjectPBR(models::roomContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.8f, 0.0f); + //drawObjectPBR(models::deskContext, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(0.2, 0.2, 0.2)) * glm::translate(glm::vec3(7.5f, 0.0f, -15.0f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.0f); + drawObjectPBR(models::deskContext, glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.9f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.0f); + drawObjectPBR(models::displayScreenContext, glm::scale(glm::vec3(0.1, 0.1, 0.1)) * glm::translate(glm::vec3(-28.5f, 9.0f, -20.0f)), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.3f); + //drawObjectPBR(models::chairContext, glm::scale(glm::vec3(0.03, 0.03, 0.03)) * glm::translate(glm::vec3(-100.5f, 0.0f, -35.0f)), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.2f); + drawObjectPBR(models::chairContext, glm::scale(glm::vec3(1.0f, 1.2f, 1.0f)) * glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.5f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.0f, 0.2f); + drawObjectPBR(models::tvContext, glm::mat4(), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.2f); + drawObjectPBR(models::ps5Context, glm::mat4(), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.2f); + drawObjectPBR(models::tvStandContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); + drawObjectPBR(models::carpetContext, glm::mat4(), glm::vec3(0.6745098039215686f, 0.6352941176470588f, 0.6235294117647059f), 0.0f, 0.2f); + drawObjectPBR(models::cabinet1Context, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); + drawObjectPBR(models::cabinet2Context, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); + drawObjectPBR(models::lampContext, glm::translate(glm::vec3(0.023f, 0.15f, 0.0f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); + drawObjectPBR(models::bookshelfContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); + drawObjectPBR(models::lightSwitchContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.2f); + drawObjectPBR(models::easelContext, glm::mat4(), glm::vec3(0.6745098039215686f, 0.6352941176470588f, 0.6235294117647059f), 0.0f, 0.2f); + drawObjectPBR(models::carContext, glm::translate(carPosTranform), glm::vec3(1.0f, 0.0f, 0.0f), 0.0f, 0.2f); + drawObjectPBR(models::vaseContext, glm::translate(glm::vec3(1.1f, 1.41f, -2.2f)), glm::vec3(244.0f / 255.0f, 245.0f / 255.0f, 220.0f / 255.0f), 0.0f, 0.2f); + // draw windows + drawObjectPBR(models::windowContext, glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.2f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + drawObjectPBR(models::windowContext, glm::eulerAngleY(3.14f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.3f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + drawObjectPBR(models::windowContext, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(1.0f, 1.0f, 2.45f)) * glm::translate(glm::vec3(-0.6f, 0, -0.25f)), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f); + + + glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f))); + glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir)); + glm::mat4 specshipCameraRotrationMatrix = glm::mat4({ + spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0, + spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0, + -spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0, + 0.,0.,0.,1., + }); + + + //drawObjectColor(shipContext, + // glm::translate(cameraPos + 1.5 * cameraDir + cameraUp * -0.5f) * inveseCameraRotrationMatrix * glm::eulerAngleY(glm::pi()), + // glm::vec3(0.3, 0.3, 0.5) + // ); + drawObjectPBR(shipContext, + glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi()) * glm::scale(glm::vec3(0.03f)), + glm::vec3(0.3, 0.3, 0.5), + 0.2,1.0 + ); + + /*drawObjectPBR(models::deskContext, glm::eulerAngleY(1.57f) * glm::scale(glm::vec3(0.2,0.2,0.2)) * glm::translate(glm::vec3(7.5f,0.0f, -15.0f)), glm::vec3(1.0f, 1.0f, 1.0f), 0.0f, 0.0f); + drawObjectPBR(models::displayScreenContext, glm::scale(glm::vec3(0.1,0.1,0.1)) * glm::translate(glm::vec3(-28.5f,9.0f, -20.0f)), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.3f); + drawObjectPBR(models::chairContext, glm::scale(glm::vec3(0.03,0.03,0.03)) * glm::translate(glm::vec3(-100.5f,0.0f, -35.0f)), glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, 0.2f);*/ + + pingPongBluring(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + //test depth buffer + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glUseProgram(programTest); + Core::SetActiveTexture(colorBuffers[0], "color", programTest, 0); + Core::SetActiveTexture(pingpongBuffer[1], "highlight", programTest, 1); + //Core::SetActiveTexture(colorBuffers[0],prog) + Core::DrawContext(models::testContext); + + glUseProgram(0); + glfwSwapBuffers(window); +} +void framebuffer_size_callback(GLFWwindow* window, int width, int height) +{ + aspectRatio = width / float(height); + glViewport(0, 0, width, height); + WIDTH = width; + HEIGHT = height; + initBloom(); + initPingPong(); + +} + +void loadModelToContext(std::string path, Core::RenderContext& context) +{ + Assimp::Importer import; + const aiScene* scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_CalcTangentSpace); + + if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) + { + std::cout << "ERROR::ASSIMP::" << import.GetErrorString() << std::endl; + return; + } + context.initFromAssimpMesh(scene->mMeshes[0]); +} + +void init(GLFWwindow* window) +{ + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + + glEnable(GL_DEPTH_TEST); + 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"); + programBlur = shaderLoader.CreateProgram("shaders/shader_blur.vert", "shaders/shader_blur.frag"); + loadCubemap(faces); + initDepthMap(); + + texture::earth = Core::LoadTexture("textures/room/earth.png"); + texture::earthNormal = Core::LoadTexture("textures/room/earth_normalmap.png"); + + loadModelToContext("./models/sphere.obj", sphereContext); + loadModelToContext("./models/spaceship.obj", shipContext); + loadModelToContext("./models/cube.obj", cubeContext); + + + loadModelToContext("./models/couch.obj", models::couchContext); + loadModelToContext("./models/coffeeTable.obj", models::coffeeTableContext); + loadModelToContext("./models/door.obj", models::doorContext); + loadModelToContext("./models/drawer.obj", models::drawerContext); + loadModelToContext("./models/plane.obj", models::planeContext); + //loadModelToContext("./models/room_2.obj", models::roomContext); + loadModelToContext("./models/room/room3.obj", models::roomContext); + loadModelToContext("./models/spaceship.obj", models::spaceshipContext); + loadModelToContext("./models/sphere.obj", models::sphereContext); + loadModelToContext("./models/window.obj", models::windowContext); + loadModelToContext("./models/test.obj", models::testContext); + loadModelToContext("./models/desk.obj", models::deskContext); + loadModelToContext("./models/monitor.obj", models::displayScreenContext); + loadModelToContext("./models/chair.obj", models::chairContext); + loadModelToContext("./models/tv/tv.obj", models::tvContext); + loadModelToContext("./models/tv_stand/tv_stand.obj", models::tvStandContext); + loadModelToContext("./models/ps5/ps5.obj", models::ps5Context); + loadModelToContext("./models/carpet/carpet.obj", models::carpetContext); + loadModelToContext("./models/cabinet_1/cabinet.obj", models::cabinet1Context); + loadModelToContext("./models/cabinet_2/cabinet.obj", models::cabinet2Context); + loadModelToContext("./models/lamp/lamp.obj", models::lampContext); + loadModelToContext("./models/bookshelf/bookshelf.obj", models::bookshelfContext); + loadModelToContext("./models/light_switch/light_switch.obj", models::lightSwitchContext); + loadModelToContext("./models/easel/easel3.obj", models::easelContext); + loadModelToContext("./models/car/car.obj", models::carContext); + loadModelToContext("./models/ceramic_vase_02_4k.obj", models::vaseContext); + + initDepthMap(); + initDepthMapShip(); + + initBloom(); + initPingPong(); + +} + +void shutdown(GLFWwindow* window) +{ + shaderLoader.DeleteProgram(program); +} + +//obsluga wejscia +void processInput(GLFWwindow* window) +{ + glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f,1.f,0.f))); + glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f); + + glm::vec3 carSide = glm::vec3(0.f, 0.f, 1.f); + glm::vec3 carUp = glm::vec3(1.f, 0.f, 0.f); + + float angleSpeed = 0.05f * deltaTime * 60; + float moveSpeed = 0.05f * deltaTime * 60; + if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { + glfwSetWindowShouldClose(window, true); + } + if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) + spaceshipPos += spaceshipDir * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) + spaceshipPos -= spaceshipDir * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) + spaceshipPos += spaceshipSide * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) + spaceshipPos -= spaceshipSide * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) + spaceshipPos += spaceshipUp * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) + spaceshipPos -= spaceshipUp * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) + spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0)); + if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) + spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0)); + + cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f; + cameraDir = spaceshipDir; + + if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) + exposition -= 0.05; + if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS) + exposition += 0.05; + + if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) { + printf("spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", spaceshipPos.x, spaceshipPos.y, spaceshipPos.z); + printf("spaceshipDir = glm::vec3(%ff, %ff, %ff);\n", spaceshipDir.x, spaceshipDir.y, spaceshipDir.z); + } + if (glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) + lightOn = !lightOn; + + // if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) + if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) + carPosTranform += carUp * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) + carPosTranform -= carUp * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) + carPosTranform -= carSide * moveSpeed; + if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) + carPosTranform += carSide * moveSpeed; + //cameraDir = glm::normalize(-cameraPos); + +} + + +// funkcja jest glowna petla +void renderLoop(GLFWwindow* window) { + while (!glfwWindowShouldClose(window)) + { + processInput(window); + renderScene(window); + //glfwSwapBuffers(window); + glfwPollEvents(); + } +} +//} \ No newline at end of file