Merge branch 'bloom'

This commit is contained in:
Anna Śmigiel 2023-02-09 22:34:30 +01:00
commit f285c95732
60 changed files with 311 additions and 112 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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.
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.
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
D:\UAM\Grafika komputerowa\projekt\GRK_Room\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : zobacz poprzednią definicję „APIENTRY”
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(111,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(130,38): warning C4305: "=": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(153,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(172,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(190,15): warning C4101: "textureID": lokalna zmienna, do której nie istnieje odwołanie
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(276,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(287,96): warning C4305: "argument": obcięcie z "double" do "T"
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\minwindef.h(130,1): warning C4005: 'APIENTRY': macro redefinition
C:\Users\s464961\Source\Repos\GRK_Room\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123): message : see previous definition of 'APIENTRY'
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(107,30): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(122,38): warning C4305: '=': truncation from 'double' to 'float'
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(145,16): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(166,16): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(185,15): warning C4101: 'textureID': unreferenced local variable
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(268,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(279,96): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(291,59): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(283,59): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(388,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(412,109): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(440,29): warning C4018: '<': signed/unsigned mismatch
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(480,13): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(493,108): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(421,87): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(504,59): warning C4305: 'argument': truncation from 'double' to 'T'
with
[
T=float
]
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(421,223): warning C4305: "argument": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(424,59): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(425,37): warning C4305: "argument": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(462,2): warning C4305: "argument": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(594,21): warning C4305: "-=": obcięcie z "double" do "float"
D:\UAM\Grafika komputerowa\projekt\GRK_Room\cw 9\src\room.hpp(596,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 -> D:\UAM\Grafika komputerowa\projekt\GRK_Room\Debug\room.exe
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(505,37): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(538,2): warning C4305: 'argument': truncation from 'double' to 'float'
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(662,21): warning C4305: '-=': truncation from 'double' to 'float'
C:\Users\s464961\source\repos\GRK_Room\cw 9\src\room.hpp(664,21): warning C4305: '+=': truncation from 'double' to 'float'
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 -> C:\Users\s464961\Source\Repos\GRK_Room\Debug\room.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>D:\UAM\Grafika komputerowa\projekt\GRK_Room\Debug\room.exe</FullPath>
<FullPath>C:\Users\Genos\Source\Repos\GRK_Room22\Debug\room.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|D:\UAM\Grafika komputerowa\projekt\GRK_Room\|
Debug|Win32|C:\Users\Genos\Source\Repos\GRK_Room22\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,46 +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\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(94,30): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(109,38): warning C4305: "=": obcięcie z "double" do "float"
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(132,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(153,16): warning C4305: "inicjowanie": obcięcie z "double" do "float"
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(172,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(252,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(263,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(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(293,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(304,96): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(267,59): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(308,59): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(343,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(353,108): warning C4305: "argument": obcięcie z "double" do "T"
C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(472,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku
C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(497,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(514,109): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(361,87): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(361,223): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(364,59): warning C4305: "argument": obcięcie z "double" do "T"
with
[
T=float
]
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(365,37): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(393,2): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(501,21): warning C4305: "-=": obcięcie z "double" do "float"
C:\Users\Genos\source\repos\GRK_Room\cw 9\src\room.hpp(503,21): warning C4305: "+=": obcięcie z "double" do "float"
C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(570,2): warning C4305: "argument": obcięcie z "double" do "float"
C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(709,21): warning C4305: "-=": obcięcie z "double" do "float"
C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(711,21): warning C4305: "+=": obcięcie z "double" do "float"
Trwa generowanie kodu
35 of 586 functions ( 6.0%) 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
15 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\Genos\source\repos\GRK_Room\Release\room.exe
grk-cw9.vcxproj -> C:\Users\annas\Desktop\graf\Release\room.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\Genos\source\repos\GRK_Room\Release\room.exe</FullPath>
<FullPath>C:\Users\annas\Desktop\graf\Release\room.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1,2 @@
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:TargetPlatformVersion=10.0.19041.0:
Release|Win32|C:\Users\Genos\source\repos\GRK_Room\|
Release|Win32|C:\Users\annas\Desktop\graf\|

Binary file not shown.

Binary file not shown.

View File

@ -41,6 +41,8 @@
<None Include="shaders\shader_9_1.vert" />
<None Include="shaders\shader_8_sun.frag" />
<None Include="shaders\shader_8_sun.vert" />
<None Include="shaders\shader_blur.frag" />
<None Include="shaders\shader_blur.vert" />
<None Include="shaders\shader_shadowmapsun.frag" />
<None Include="shaders\shader_shadowmapsun.vert" />
<None Include="shaders\shader_skybox.frag" />

View File

@ -121,5 +121,11 @@
<None Include="shaders\shader_shadowmapsun.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_blur.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_blur.frag">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>
</Project>

View File

@ -1,11 +1,20 @@
#version 430 core
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 BloomColor;
uniform vec3 color;
uniform float exposition;
out vec4 outColor;
void main()
{
outColor = vec4(vec3(1.0) - exp(-color*exposition),1);
//outColor = vec4(color, 1.0);
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);
BloomColor = vec4(color, 1.0);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -1,12 +1,21 @@
#version 430 core
uniform samplerCube skybox;
uniform float exposition;
in vec3 texCoord;
out vec4 outColor;
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 BloomColor;
out vec4 out_color;
void main()
{
out_color = texture(skybox,texCoord);
outColor = vec4(vec3(1.0) - exp(-texture(skybox,texCoord).rgb*exposition),1);
FragColor = outColor;
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);
}

View File

@ -3,17 +3,46 @@ out vec4 FragColor;
in vec2 tc;
uniform sampler2D depthMap;
uniform sampler2D color;
uniform sampler2D highlight;
float rescale_z(float z){
float n = 0.05;
float f = 20.;
return (2*n*f/(z*(n-f)+n+f))/f;
}
float weight[5] = float[] (0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216);
vec4 blur()
{
vec2 tex_offset = 1.0 / textureSize(color, 0); // gets size of single texel
vec3 result = texture(highlight, tc).rgb * weight[0]; // current fragment's contribution
bool horizontal = true;
if(horizontal)
{
for(int i = 1; i < 5; ++i)
{
result += texture(highlight, tc + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
result += texture(highlight, tc - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
}
}
else
{
for(int i = 1; i < 5; ++i)
{
result += texture(highlight, tc + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
result += texture(highlight, tc - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
}
}
return vec4(result, 1.0);
}
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).rgb+texture(color, tc).rgb,1);
//FragColor = vec4( (texture(color, tc)-0.98)*50);
}

View File

@ -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);
}

View File

@ -23,7 +23,7 @@ int main(int argc, char** argv)
#endif
// tworzenie okna za pomoca glfw
GLFWwindow* window = glfwCreateWindow(500, 500, "The Best Room", NULL, NULL);
GLFWwindow* window = glfwCreateWindow(800, 800, "The Best Room", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
@ -34,7 +34,7 @@ int main(int argc, char** argv)
// ladowanie OpenGL za pomoca glew
glewInit();
glViewport(0, 0, 500, 500);
glViewport(0, 0, 800, 800);
init(window);

View File

@ -15,13 +15,13 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
#include<array>
#include "SOIL/SOIL.h"
#include "SOIL/stb_image_aug.h"
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
int WIDTH = 500, HEIGHT = 500;
int WIDTH = 800, HEIGHT = 800;
namespace models {
Core::RenderContext couchContext;
@ -48,7 +48,6 @@ namespace models {
Core::RenderContext lightSwitchContext;
Core::RenderContext easelContext;
Core::RenderContext carContext;
Core::RenderContext flowerContext;
Core::RenderContext vaseContext;
}
@ -76,12 +75,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;
@ -97,20 +99,25 @@ 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);
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;
@ -119,7 +126,6 @@ float deltaTime = 0.f;
bool lightOn = true;
glm::vec3 carPosTranform = glm::vec3(0, 0, 0);
void updateDeltaTime(float time) {
if (lastTime < 0) {
lastTime = time;
@ -147,7 +153,7 @@ glm::mat4 createCameraMatrix()
return cameraMatrix;
}
glm::mat4 createPerspectiveMatrix()
glm::mat4 createPerspectiveMatrix() //do shaderow
{
glm::mat4 perspectiveMatrix;
float n = 0.05;
@ -224,10 +230,17 @@ void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programSkybox, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform1i(glGetUniformLocation(programSkybox, "skybox"), 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 drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
glActiveTexture(GL_TEXTURE0);
glUniform1i(glGetUniformLocation(program, "depthMap"), 0);
@ -260,14 +273,15 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
else
glUniform3f(glGetUniformLocation(program, "lightPos"), 1000.f, 1000.f, 1000.f);
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::DrawContext(context);
}
void renderShadowapSun(GLuint depthFBO, glm::mat4 light) {
@ -284,12 +298,32 @@ void renderShadowapSun(GLuint depthFBO, glm::mat4 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));
drawObjectDepth(models::coffeeTableContext, light, glm::translate(glm::vec3(2.8f, 0, 0.5f)));
drawObjectDepth(models::doorContext, light, glm::mat4());
drawObjectDepth(models::planeContext, light, glm::mat4());
drawObjectDepth(models::roomContext, light, glm::mat4());
drawObjectDepth(models::deskContext, light,glm::eulerAngleY(3.14f) * glm::translate(glm::vec3(2.8f, 0.0f, 1.9f)));
// 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)));
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)));
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)));
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(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());
@ -300,13 +334,8 @@ 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::flowerContext, light, glm::mat4());
drawObjectDepth(models::vaseContext, light, glm::translate(glm::vec3(1.1f, 1.41f, -2.2f)));
drawObjectDepth(models::windowContext, light, glm::scale(glm::vec3(1.0f, 1.0f, 2.3f)) * glm::translate(glm::vec3(-2.9f, 0, -0.2f)));
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)));
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)));
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({
@ -316,6 +345,8 @@ void renderShadowapSun(GLuint depthFBO, glm::mat4 light) {
0.,0.,0.,1.,
});
//drawObjectDepth(shipContext,
drawObjectDepth(models::spaceshipContext,
light,
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f))
@ -363,31 +394,110 @@ 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
);
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);
}
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(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);
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));
if (lightOn) {
glUseProgram(programSun);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
@ -398,21 +508,20 @@ void renderScene(GLFWwindow* window)
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::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::mat4(), glm::vec3(1.0f, 1.0f, 1.0f), 0.8f, 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(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);
@ -425,19 +534,43 @@ 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::flowerContext, glm::mat4(), glm::vec3(1.0f, 1.0f, 1.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);
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.,
});
//drawObjectPBR(shipContext,
drawObjectPBR(models::spaceshipContext,
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)),
glm::vec3(0.3, 0.3, 0.5),
0.2,1.0
);
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);
}
@ -447,6 +580,9 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
glViewport(0, 0, width, height);
WIDTH = width;
HEIGHT = height;
initBloom();
initPingPong();
}
void loadModelToContext(std::string path, Core::RenderContext& context)
@ -475,6 +611,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();
@ -489,6 +626,7 @@ void init(GLFWwindow* window)
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);
@ -508,11 +646,14 @@ 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/flower/flower.obj", models::flowerContext);
loadModelToContext("./models/ceramic_vase_02_4k.obj", models::vaseContext);
initDepthMap();
initDepthMapShip();
initBloom();
initPingPong();
}
void shutdown(GLFWwindow* window)
@ -563,10 +704,10 @@ void processInput(GLFWwindow* window)
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)
@ -575,14 +716,18 @@ void processInput(GLFWwindow* window)
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();
}
}