bloom bez g blura

This commit is contained in:
Anna Śmigiel 2023-01-30 12:10:43 +01:00
parent 8dfd5b1c9b
commit 1f50ab3921
37 changed files with 229 additions and 43 deletions

View File

@ -2,8 +2,9 @@
"ExpandedNodes": [ "ExpandedNodes": [
"", "",
"\\cw 9", "\\cw 9",
"\\cw 9\\shaders",
"\\cw 9\\src" "\\cw 9\\src"
], ],
"SelectedNode": "\\cw 9\\src\\room.hpp", "SelectedNode": "\\cw 9\\src\\main.cpp",
"PreviewInSolutionExplorer": false "PreviewInSolutionExplorer": false
} }

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:\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 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:\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\annas\Desktop\graf\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\annas\Desktop\graf\cw 9\src\room.hpp(107,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\annas\Desktop\graf\cw 9\src\room.hpp(122,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\annas\Desktop\graf\cw 9\src\room.hpp(145,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\annas\Desktop\graf\cw 9\src\room.hpp(166,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\annas\Desktop\graf\cw 9\src\room.hpp(185,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\annas\Desktop\graf\cw 9\src\room.hpp(268,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\cw 9\src\room.hpp(279,96): warning C4305: "argument": obcięcie z "double" do "T"
with with
[ [
T=float 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 with
[ [
T=float 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\annas\Desktop\graf\cw 9\src\room.hpp(440,29): warning C4018: "<": niezgodność typu ze znakiem/bez znaku
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(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 with
[ [
T=float 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 with
[ [
T=float 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\annas\Desktop\graf\cw 9\src\room.hpp(505,37): 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" C:\Users\annas\Desktop\graf\cw 9\src\room.hpp(538,2): warning C4305: "argument": obcięcie z "double" do "float"
with 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"
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"
Box.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO” 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 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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,7 @@
<Project> <Project>
<ProjectOutputs> <ProjectOutputs>
<ProjectOutput> <ProjectOutput>
<FullPath>C:\Users\Genos\source\repos\GRK_Room2\Debug\room.exe</FullPath> <FullPath>C:\Users\annas\Desktop\graf\Debug\room.exe</FullPath>
</ProjectOutput> </ProjectOutput>
</ProjectOutputs> </ProjectOutputs>
<ContentFiles /> <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: 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\|

Binary file not shown.

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_9_1.vert" />
<None Include="shaders\shader_8_sun.frag" /> <None Include="shaders\shader_8_sun.frag" />
<None Include="shaders\shader_8_sun.vert" /> <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.frag" />
<None Include="shaders\shader_shadowmapsun.vert" /> <None Include="shaders\shader_shadowmapsun.vert" />
<None Include="shaders\shader_skybox.frag" /> <None Include="shaders\shader_skybox.frag" />

View File

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

View File

@ -1,4 +1,6 @@
#version 430 core #version 430 core
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 BloomColor;
uniform vec3 color; uniform vec3 color;
uniform float exposition; uniform float exposition;
@ -7,5 +9,6 @@ uniform float exposition;
out vec4 outColor; out vec4 outColor;
void main() 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);
} }

View File

@ -4,10 +4,12 @@ layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal; layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord; layout(location = 2) in vec2 vertexTexCoord;
uniform mat4 transformation; uniform mat4 transformation;
void main() void main()
{ {
gl_Position = transformation * vec4(vertexPosition, 1.0); gl_Position = transformation * vec4(vertexPosition, 1.0);
//gl_Position = vec4(vertexPosition, 1.0); //gl_Position = vec4(vertexPosition, 1.0);
} }

View File

@ -1,5 +1,8 @@
#version 430 core #version 430 core
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 BloomColor;
float AMBIENT = 0.03; float AMBIENT = 0.03;
float PI = 3.14; float PI = 3.14;
@ -148,11 +151,21 @@ void main()
attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2)*calculateShadow(normal, spotlightDir, shipPos, depthMapShip); attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2)*calculateShadow(normal, spotlightDir, shipPos, depthMapShip);
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir); ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
//sun //sun
ilumination=ilumination+PBRLight(sunDir,sunColor*calculateShadow(normal, spotlightDir, sunSpacePos, depthMap),normal,viewDir); 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(roughness,metallic,0,1);
//outColor = vec4(test; //outColor = vec4(test;
} }

View File

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

View File

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

View File

@ -3,7 +3,8 @@ out vec4 FragColor;
in vec2 tc; in vec2 tc;
uniform sampler2D depthMap; uniform sampler2D color;
uniform sampler2D highlight;
float rescale_z(float z){ float rescale_z(float z){
float n = 0.05; float n = 0.05;
@ -13,7 +14,8 @@ float rescale_z(float z){
void main() 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(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));
} }

View File

@ -10,5 +10,5 @@ out vec2 tc;
void main() void main()
{ {
tc = vertexTexCoord; tc = vertexTexCoord;
gl_Position = vec4(vertexPosition*0.5, 1.0); gl_Position = vec4(vertexPosition, 1.0);
} }

View File

@ -62,12 +62,15 @@ GLuint depthMap;
GLuint depthMapShipFBO; GLuint depthMapShipFBO;
GLuint depthMapShip; GLuint depthMapShip;
GLuint bloomTextureFBO;
GLuint program; GLuint program;
GLuint programSun; GLuint programSun;
GLuint programTest; GLuint programTest;
GLuint programTex; GLuint programTex;
GLuint programDepth; GLuint programDepth;
GLuint programSkybox; GLuint programSkybox;
GLuint programBlur;
Core::Shader_Loader shaderLoader; 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 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f);
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f); 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; GLuint VAO,VBO;
float aspectRatio = 1.f; float aspectRatio = 1.f;
@ -91,14 +99,14 @@ float aspectRatio = 1.f;
float exposition = 1.f; float exposition = 1.f;
glm::vec3 pointlightPos = glm::vec3(0, 2, 0); 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 spotlightPos = glm::vec3(0, 0, 0);
glm::vec3 spotlightConeDir = 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; glm::vec3 spotlightColor = glm::vec3(1.0, 1.0, 1.0)*10;
float spotlightPhi = 3.14 / 4; 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; glm::mat4 lightShipVP;
float lastTime = -1.f; float lastTime = -1.f;
@ -121,7 +129,7 @@ glm::mat4 createCameraMatrix()
glm::mat4 cameraRotrationMatrix = glm::mat4({ glm::mat4 cameraRotrationMatrix = glm::mat4({
cameraSide.x,cameraSide.y,cameraSide.z,0, cameraSide.x,cameraSide.y,cameraSide.z,0,
cameraUp.x,cameraUp.y,cameraUp.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., 0.,0.,0.,1.,
}); });
cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix); cameraRotrationMatrix = glm::transpose(cameraRotrationMatrix);
@ -130,7 +138,7 @@ glm::mat4 createCameraMatrix()
return cameraMatrix; return cameraMatrix;
} }
glm::mat4 createPerspectiveMatrix() glm::mat4 createPerspectiveMatrix() //do shaderow
{ {
glm::mat4 perspectiveMatrix; glm::mat4 perspectiveMatrix;
@ -365,15 +373,117 @@ void initDepthMapShip()
glBindFramebuffer(GL_FRAMEBUFFER, 0); 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) void renderScene(GLFWwindow* window)
{ {
lightShipVP = createPerspectiveMatrix(0.5) * glm::lookAt(spotlightPos, spotlightPos + spotlightConeDir, glm::vec3(0, 1, 0)); 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); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float time = glfwGetTime(); float time = glfwGetTime();
updateDeltaTime(time); updateDeltaTime(time);
renderShadowapSun(depthMapFBO, lightVP); renderShadowapSun(depthMapFBO, lightVP);
renderShadowapSun(depthMapShipFBO, lightShipVP); 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)); drawSkyBox(cubeContext, glm::translate(cameraPos));
@ -386,16 +496,16 @@ void renderScene(GLFWwindow* window)
glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition); glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition);
Core::DrawContext(sphereContext); Core::DrawContext(sphereContext);
//pingPongBluring(time);
glUseProgram(program); 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, 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::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); 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::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::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::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::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; spotlightConeDir = spaceshipDir;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//test depth buffer //test depth buffer
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glUseProgram(programTest); glUseProgram(programTest);
//glActiveTexture(GL_TEXTURE0); Core::SetActiveTexture(colorBuffers[0], "color", programTest, 0);
//glBindTexture(GL_TEXTURE_2D, depthMap); Core::SetActiveTexture(colorBuffers[1], "highlight", programTest, 1);
//Core::DrawContext(models::testContext); //Core::SetActiveTexture(colorBuffers[0],prog)
Core::DrawContext(models::testContext);
glUseProgram(0); glUseProgram(0);
glfwSwapBuffers(window); glfwSwapBuffers(window);
@ -477,6 +589,7 @@ void init(GLFWwindow* window)
programDepth = shaderLoader.CreateProgram("shaders/shader_shadowmapsun.vert", "shaders/shader_shadowmapsun.frag"); programDepth = shaderLoader.CreateProgram("shaders/shader_shadowmapsun.vert", "shaders/shader_shadowmapsun.frag");
programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.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); loadCubemap(faces);
initDepthMap(); initDepthMap();
@ -505,6 +618,9 @@ void init(GLFWwindow* window)
initDepthMap(); initDepthMap();
initDepthMapShip(); initDepthMapShip();
initBloom();
initPingPong();
} }
void shutdown(GLFWwindow* window) void shutdown(GLFWwindow* window)