diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index 71c435c..84bba22 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -2,8 +2,9 @@ "ExpandedNodes": [ "", "\\cw 9", + "\\cw 9\\shaders", "\\cw 9\\src" ], - "SelectedNode": "\\cw 9\\src\\room.hpp", + "SelectedNode": "\\cw 9\\src\\main.cpp", "PreviewInSolutionExplorer": false } \ No newline at end of file diff --git a/.vs/grk-project/v16/.suo b/.vs/grk-project/v16/.suo index 702931c..e87816d 100644 Binary files a/.vs/grk-project/v16/.suo and b/.vs/grk-project/v16/.suo differ diff --git a/.vs/grk-project/v16/Browse.VC.db b/.vs/grk-project/v16/Browse.VC.db index a612fb9..42e3735 100644 Binary files a/.vs/grk-project/v16/Browse.VC.db and b/.vs/grk-project/v16/Browse.VC.db differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 301c17f..9b93704 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/Debug/room.exe b/Debug/room.exe index a7e3c75..46102a0 100644 Binary files a/Debug/room.exe and b/Debug/room.exe differ diff --git a/Debug/room.pdb b/Debug/room.pdb index e00c798..49251f9 100644 Binary files a/Debug/room.pdb and b/Debug/room.pdb differ diff --git a/cw 9/Debug/Box.obj b/cw 9/Debug/Box.obj index e0c386a..5caeb4f 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 cfb82eb..82aca2d 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 b769571..6e6f1e6 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 eba0a08..a87c488 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 c482742..d3ceef2 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 c0b01ab..5704634 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 0a1dd9f..6e73f7d 100644 --- a/cw 9/Debug/grk-cw9.log +++ b/cw 9/Debug/grk-cw9.log @@ -1,44 +1,39 @@ 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": ponowna definicja makra -C:\Users\Genos\source\repos\GRK_Room2\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY” -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(97,30): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(112,38): warning C4305: "=": obcięcie z "double" do "float" -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(135,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(156,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(175,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(258,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(269,96): warning C4305: "argument": obcięcie z "double" do "T" +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(107,30): warning C4305: "inicjowanie": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(122,38): warning C4305: "=": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(145,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(166,16): warning C4305: "inicjowanie": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(185,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(268,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(279,96): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(273,59): warning C4305: "argument": obcięcie z "double" do "T" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(283,59): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(368,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(378,108): warning C4305: "argument": obcięcie z "double" do "T" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(440,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(480,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(493,108): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(386,87): warning C4305: "argument": obcięcie z "double" do "T" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(504,59): warning C4305: "argument": obcięcie z "double" do "T" with [ T=float ] -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(386,223): warning C4305: "argument": obcięcie z "double" do "float" -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(389,59): warning C4305: "argument": obcięcie z "double" do "T" - with - [ - T=float - ] -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(390,37): warning C4305: "argument": obcięcie z "double" do "float" -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(423,2): warning C4305: "argument": obcięcie z "double" do "float" -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(534,21): warning C4305: "-=": obcięcie z "double" do "float" -C:\Users\Genos\source\repos\GRK_Room2\cw 9\src\room.hpp(536,21): warning C4305: "+=": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(505,37): warning C4305: "argument": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(538,2): warning C4305: "argument": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(662,21): warning C4305: "-=": obcięcie z "double" do "float" +C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(664,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_Room2\Debug\room.exe + grk-cw9.vcxproj -> C:\Users\annas\Desktop\graf\Debug\room.exe diff --git a/cw 9/Debug/image_DXT.obj b/cw 9/Debug/image_DXT.obj index b4247f4..8a881fc 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 14acc96..0575597 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 00db99f..46cccc1 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 8c103bb..439d551 100644 --- a/cw 9/Debug/room.exe.recipe +++ b/cw 9/Debug/room.exe.recipe @@ -2,7 +2,7 @@ - C:\Users\Genos\source\repos\GRK_Room2\Debug\room.exe + C:\Users\annas\Desktop\graf\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 9b2049e..b7def3c 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 b0d043f..87e7723 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 96ea420..5bb56c6 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 b4ba1ce..941f4b5 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 8afb293..eea8c73 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 0a81c9c..161ec05 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 3cf7e2e..b3cc5ec 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|C:\Users\Genos\source\repos\GRK_Room2\| +Debug|Win32|C:\Users\annas\Desktop\graf\| diff --git a/cw 9/Debug/stb_image_aug.obj b/cw 9/Debug/stb_image_aug.obj index 7912f15..4adeb0c 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 94b736c..1082b90 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 a988f29..9caedb9 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 04488ff..7520a32 100644 --- a/cw 9/grk-cw9.vcxproj +++ b/cw 9/grk-cw9.vcxproj @@ -41,6 +41,8 @@ + + diff --git a/cw 9/grk-cw9.vcxproj.filters b/cw 9/grk-cw9.vcxproj.filters index 02d13f3..a20ee76 100644 --- a/cw 9/grk-cw9.vcxproj.filters +++ b/cw 9/grk-cw9.vcxproj.filters @@ -121,5 +121,11 @@ Shader Files + + Shader Files + + + Shader Files + \ No newline at end of file diff --git a/cw 9/shaders/shader_8_sun.frag b/cw 9/shaders/shader_8_sun.frag index c4c8a93..27008ba 100644 --- a/cw 9/shaders/shader_8_sun.frag +++ b/cw 9/shaders/shader_8_sun.frag @@ -1,4 +1,6 @@ #version 430 core +layout (location = 0) out vec4 FragColor; +layout (location = 1) out vec4 BloomColor; uniform vec3 color; uniform float exposition; @@ -7,5 +9,6 @@ uniform float exposition; out vec4 outColor; void main() { - outColor = vec4(vec3(1.0) - exp(-color*exposition),1); + //outColor = vec4(vec3(1.0) - exp(-color*exposition),1); + outColor = vec4(color, 1.0); } diff --git a/cw 9/shaders/shader_8_sun.vert b/cw 9/shaders/shader_8_sun.vert index 0699a2e..5c2d818 100644 --- a/cw 9/shaders/shader_8_sun.vert +++ b/cw 9/shaders/shader_8_sun.vert @@ -4,10 +4,12 @@ layout(location = 0) in vec3 vertexPosition; layout(location = 1) in vec3 vertexNormal; layout(location = 2) in vec2 vertexTexCoord; + uniform mat4 transformation; void main() { gl_Position = transformation * vec4(vertexPosition, 1.0); //gl_Position = vec4(vertexPosition, 1.0); + } diff --git a/cw 9/shaders/shader_9_1.frag b/cw 9/shaders/shader_9_1.frag index 7eb79d4..7cfc3a0 100644 --- a/cw 9/shaders/shader_9_1.frag +++ b/cw 9/shaders/shader_9_1.frag @@ -1,5 +1,8 @@ #version 430 core +layout (location = 0) out vec4 FragColor; +layout (location = 1) out vec4 BloomColor; + float AMBIENT = 0.03; float PI = 3.14; @@ -148,11 +151,21 @@ void main() attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2)*calculateShadow(normal, spotlightDir, shipPos, depthMapShip); ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir); + //sun ilumination=ilumination+PBRLight(sunDir,sunColor*calculateShadow(normal, spotlightDir, sunSpacePos, depthMap),normal,viewDir); + - outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1); + outColor = vec4(vec3(1.01) - exp(-ilumination*exposition),1); + + FragColor = outColor; + // check whether fragment output is higher than threshold, if so output as brightness color + float brightness = dot(FragColor.rgb, vec3(0.2126, 0.7152, 0.0722)); + if(brightness > 1.0) + BloomColor = vec4(FragColor.rgb, 1.0); + else + BloomColor = vec4(0.0, 0.0, 0.0, 1.0); //outColor = vec4(roughness,metallic,0,1); //outColor = vec4(test; } diff --git a/cw 9/shaders/shader_blur.frag b/cw 9/shaders/shader_blur.frag new file mode 100644 index 0000000..5fb620e --- /dev/null +++ b/cw 9/shaders/shader_blur.frag @@ -0,0 +1,32 @@ +#version 330 core +out vec4 FragColor; + +in vec2 TexCoords; + +uniform sampler2D image; + +uniform bool horizontal; +uniform float weight[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216); + +void main() +{ + vec2 tex_offset = 1.0 / textureSize(image, 0); // gets size of single texel + vec3 result = texture(image, TexCoords).rgb * weight[0]; // current fragment's contribution + if(horizontal) + { + for(int i = 1; i < 5; ++i) + { + result += texture(image, TexCoords + vec2(tex_offset.x * i, 0.0)).rgb * weight[i]; + result += texture(image, TexCoords - vec2(tex_offset.x * i, 0.0)).rgb * weight[i]; + } + } + else + { + for(int i = 1; i < 5; ++i) + { + result += texture(image, TexCoords + vec2(0.0, tex_offset.y * i)).rgb * weight[i]; + result += texture(image, TexCoords - vec2(0.0, tex_offset.y * i)).rgb * weight[i]; + } + } + FragColor = vec4(result, 1.0); +} \ No newline at end of file diff --git a/cw 9/shaders/shader_blur.vert b/cw 9/shaders/shader_blur.vert new file mode 100644 index 0000000..ca3c4af --- /dev/null +++ b/cw 9/shaders/shader_blur.vert @@ -0,0 +1,14 @@ +#version 430 core + +layout(location = 0) in vec3 vertexPosition; +layout(location = 1) in vec3 vertexNormal; +layout(location = 2) in vec2 vertexTexCoord; + + +out vec2 TexCoords; + +void main() +{ + //gl_Position = vec4(vertexPosition*0.5, 1.0); + TexCoords = vertexTexCoord; +} diff --git a/cw 9/shaders/test.frag b/cw 9/shaders/test.frag index a6a6dc6..b38fef8 100644 --- a/cw 9/shaders/test.frag +++ b/cw 9/shaders/test.frag @@ -3,7 +3,8 @@ out vec4 FragColor; in vec2 tc; -uniform sampler2D depthMap; +uniform sampler2D color; +uniform sampler2D highlight; float rescale_z(float z){ float n = 0.05; @@ -13,7 +14,8 @@ float rescale_z(float z){ void main() { - float depthValue = texture(depthMap, tc).r; + //float depthValue = texture(depthMap, tc).r; //FragColor = vec4(vec3(rescale_z(depthValue)+0.5), 1.0); - FragColor = vec4(vec3((depthValue)+0.5), 1.0); + //FragColor = vec4(vec3((depthValue)+0.5), 1.0); + FragColor = vec4( texture(highlight, tc)); } \ No newline at end of file diff --git a/cw 9/shaders/test.vert b/cw 9/shaders/test.vert index f1a6f7e..f17f83e 100644 --- a/cw 9/shaders/test.vert +++ b/cw 9/shaders/test.vert @@ -10,5 +10,5 @@ out vec2 tc; void main() { tc = vertexTexCoord; - gl_Position = vec4(vertexPosition*0.5, 1.0); + gl_Position = vec4(vertexPosition, 1.0); } diff --git a/cw 9/src/room.hpp b/cw 9/src/room.hpp index 0f61685..9ef50c9 100644 --- a/cw 9/src/room.hpp +++ b/cw 9/src/room.hpp @@ -62,12 +62,15 @@ 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; @@ -84,6 +87,11 @@ 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; @@ -91,14 +99,14 @@ 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); +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 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; @@ -121,7 +129,7 @@ glm::mat4 createCameraMatrix() 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, + -cameraDir.x,-cameraDir.y,-cameraDir.z,0, 0.,0.,0.,1., }); cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix); @@ -130,7 +138,7 @@ glm::mat4 createCameraMatrix() return cameraMatrix; } -glm::mat4 createPerspectiveMatrix() +glm::mat4 createPerspectiveMatrix() //do shaderow { glm::mat4 perspectiveMatrix; @@ -365,15 +373,117 @@ void initDepthMapShip() 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 + ); + } +} + +void pingPongBluring(float time) +{ + + bool horizontal = true, first_iteration = true; + int amount = 10; + 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::DrawContext(models::couchContext); + 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) { lightShipVP = createPerspectiveMatrix(0.5) * glm::lookAt(spotlightPos, spotlightPos + spotlightConeDir, glm::vec3(0, 1, 0)); - glClearColor(0.4f, 0.4f, 0.8f, 1.0f); + glClearColor(1.f, 1, 1, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); float time = glfwGetTime(); updateDeltaTime(time); 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)); @@ -386,16 +496,16 @@ void renderScene(GLFWwindow* window) 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::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0); 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::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); @@ -435,13 +545,15 @@ void renderScene(GLFWwindow* window) spotlightConeDir = spaceshipDir; + glBindFramebuffer(GL_FRAMEBUFFER, 0); //test depth buffer //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - //glUseProgram(programTest); - //glActiveTexture(GL_TEXTURE0); - //glBindTexture(GL_TEXTURE_2D, depthMap); - //Core::DrawContext(models::testContext); + glUseProgram(programTest); + Core::SetActiveTexture(colorBuffers[0], "color", programTest, 0); + Core::SetActiveTexture(colorBuffers[1], "highlight", programTest, 1); + //Core::SetActiveTexture(colorBuffers[0],prog) + Core::DrawContext(models::testContext); glUseProgram(0); glfwSwapBuffers(window); @@ -477,6 +589,7 @@ void init(GLFWwindow* window) 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(); @@ -505,6 +618,9 @@ void init(GLFWwindow* window) initDepthMap(); initDepthMapShip(); + initBloom(); + initPingPong(); + } void shutdown(GLFWwindow* window)