bloom gotowy #2
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.
37
.vs/grk-cw/v17/DocumentLayout.json
Normal file
37
.vs/grk-cw/v17/DocumentLayout.json
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"Version": 1,
|
||||||
|
"WorkspaceRootPath": "D:\\STUDIA_sem5\\GRAFIKA-PROJEKT\\grk\\",
|
||||||
|
"Documents": [
|
||||||
|
{
|
||||||
|
"AbsoluteMoniker": "D:0:0:{F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}|projekt_grk\\grk-cw7.vcxproj|D:\\STUDIA_sem5\\GRAFIKA-PROJEKT\\grk\\projekt_grk\\src\\ex_7_1.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||||
|
"RelativeMoniker": "D:0:0:{F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}|projekt_grk\\grk-cw7.vcxproj|solutionrelative:projekt_grk\\src\\ex_7_1.hpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"DocumentGroupContainers": [
|
||||||
|
{
|
||||||
|
"Orientation": 0,
|
||||||
|
"VerticalTabListWidth": 256,
|
||||||
|
"DocumentGroups": [
|
||||||
|
{
|
||||||
|
"DockedWidth": 200,
|
||||||
|
"SelectedChildIndex": 0,
|
||||||
|
"Children": [
|
||||||
|
{
|
||||||
|
"$type": "Document",
|
||||||
|
"DocumentIndex": 0,
|
||||||
|
"Title": "ex_7_1.hpp",
|
||||||
|
"DocumentMoniker": "D:\\STUDIA_sem5\\GRAFIKA-PROJEKT\\grk\\projekt_grk\\src\\ex_7_1.hpp",
|
||||||
|
"RelativeDocumentMoniker": "projekt_grk\\src\\ex_7_1.hpp",
|
||||||
|
"ToolTip": "D:\\STUDIA_sem5\\GRAFIKA-PROJEKT\\grk\\projekt_grk\\src\\ex_7_1.hpp",
|
||||||
|
"RelativeToolTip": "projekt_grk\\src\\ex_7_1.hpp",
|
||||||
|
"ViewState": "AQIAABICAAAAAAAAAAAAAEoCAAAAAAAA",
|
||||||
|
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
||||||
|
"WhenOpened": "2024-02-27T10:49:30.827Z",
|
||||||
|
"EditorCaption": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
BIN
.vs/grk-cw/v17/Solution.VC.db
Normal file
BIN
.vs/grk-cw/v17/Solution.VC.db
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.vs/grk-cw/v17/ipch/AutoPCH/97bba2bfcfe917a6/EX_7_1.ipch
Normal file
BIN
.vs/grk-cw/v17/ipch/AutoPCH/97bba2bfcfe917a6/EX_7_1.ipch
Normal file
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.
@ -1,10 +1,19 @@
|
|||||||
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(531,5): warning MSB8028: Katalog pośredni (Debug\) zawiera pliki udostępnione z innego projektu (grk-cw3.vcxproj, grk-cw4.vcxproj, grk-cw5.vcxproj, grk-cw6.vcxproj, grk-cw7.vcxproj). Może to spowodować niepoprawne zachowanie podczas oczyszczania i ponownej kompilacji.
|
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(531,5): warning MSB8028: Katalog pośredni (Debug\) zawiera pliki udostępnione z innego projektu (grk-cw3.vcxproj, grk-cw4.vcxproj, grk-cw5.vcxproj, grk-cw6.vcxproj, grk-cw7.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.22000.0\shared\minwindef.h(130,1): warning C4005: "APIENTRY": ponowna definicja makra
|
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\minwindef.h(130,1): warning C4005: "APIENTRY": ponowna definicja makra
|
||||||
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123,1): message : zobacz poprzednią definicję „APIENTRY”
|
(kompilowanie pliku źródłowego „src/main.cpp”)
|
||||||
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(96,10): warning C4305: "inicjowanie": obcięcie z "double" do "float"
|
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123,1):
|
||||||
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(204,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
|
zobacz poprzednią definicję „APIENTRY”
|
||||||
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(222,29): warning C4305: "inicjowanie": obcięcie z "double" do "float"
|
|
||||||
|
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(110,10): warning C4305: "inicjowanie": obcięcie z "double" do "float"
|
||||||
|
(kompilowanie pliku źródłowego „src/main.cpp”)
|
||||||
|
|
||||||
|
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(332,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
|
||||||
|
(kompilowanie pliku źródłowego „src/main.cpp”)
|
||||||
|
|
||||||
|
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(350,29): warning C4305: "inicjowanie": obcięcie z "double" do "float"
|
||||||
|
(kompilowanie pliku źródłowego „src/main.cpp”)
|
||||||
|
|
||||||
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-cw7.vcxproj -> D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\Debug\projekt_grk.exe
|
grk-cw7.vcxproj -> D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\Debug\projekt_grk.exe
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
projekt_grk/Debug/projekt_grk.tlog/link.secondary.1.tlog
Normal file
1
projekt_grk/Debug/projekt_grk.tlog/link.secondary.1.tlog
Normal file
@ -0,0 +1 @@
|
|||||||
|
^D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\BOX.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\CAMERA.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\IMAGE_DXT.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\IMAGE_HELPER.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\MAIN.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\RENDER_UTILS.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\SHADER_LOADER.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\SOIL.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\STB_IMAGE_AUG.OBJ|D:\STUDIA_SEM5\GRAFIKA-PROJEKT\GRK\PROJEKT_GRK\DEBUG\TEXTURE.OBJ
|
@ -1,2 +1,2 @@
|
|||||||
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.36.32532:TargetPlatformVersion=10.0.22000.0:
|
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.39.33519:TargetPlatformVersion=10.0.22000.0:
|
||||||
Debug|Win32|D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\|
|
Debug|Win32|D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -41,6 +41,10 @@
|
|||||||
<None Include="shaders\shader_5_1.vert" />
|
<None Include="shaders\shader_5_1.vert" />
|
||||||
<None Include="shaders\shader_5_1_tex_copy.frag" />
|
<None Include="shaders\shader_5_1_tex_copy.frag" />
|
||||||
<None Include="shaders\shader_5_1_tex_copy.vert" />
|
<None Include="shaders\shader_5_1_tex_copy.vert" />
|
||||||
|
<None Include="shaders\shader_bloom.frag" />
|
||||||
|
<None Include="shaders\shader_bloom.vert" />
|
||||||
|
<None Include="shaders\shader_blur.frag" />
|
||||||
|
<None Include="shaders\shader_blur.vert" />
|
||||||
<None Include="shaders\shader_sun.frag" />
|
<None Include="shaders\shader_sun.frag" />
|
||||||
<None Include="shaders\shader_sun.vert" />
|
<None Include="shaders\shader_sun.vert" />
|
||||||
<None Include="shaders\shader_pbr.frag" />
|
<None Include="shaders\shader_pbr.frag" />
|
||||||
|
@ -121,5 +121,17 @@
|
|||||||
<None Include="shaders\shader_pbr.vert">
|
<None Include="shaders\shader_pbr.vert">
|
||||||
<Filter>Shader Files</Filter>
|
<Filter>Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="shaders\shader_bloom.frag">
|
||||||
|
<Filter>Shader Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="shaders\shader_bloom.vert">
|
||||||
|
<Filter>Shader Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="shaders\shader_blur.frag">
|
||||||
|
<Filter>Shader Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="shaders\shader_blur.vert">
|
||||||
|
<Filter>Shader Files</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
23
projekt_grk/shaders/shader_bloom.frag
Normal file
23
projekt_grk/shaders/shader_bloom.frag
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#version 430 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
in vec2 TexCoords;
|
||||||
|
|
||||||
|
uniform sampler2D scene;
|
||||||
|
uniform sampler2D bloomBlur;
|
||||||
|
uniform bool bloom;
|
||||||
|
uniform float exposure;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
const float gamma = 1.5;
|
||||||
|
vec3 hdrColor = texture(scene, TexCoords).rgb;
|
||||||
|
vec3 bloomColor = texture(bloomBlur, TexCoords).rgb;
|
||||||
|
if(bloom)
|
||||||
|
hdrColor += bloomColor; // additive blending
|
||||||
|
// tone mapping
|
||||||
|
vec3 result = vec3(1.0) - exp(-hdrColor * exposure);
|
||||||
|
// also gamma correct while we're at it
|
||||||
|
result = pow(result, vec3(1.0 / gamma));
|
||||||
|
FragColor = vec4(result, 1.0);
|
||||||
|
}
|
11
projekt_grk/shaders/shader_bloom.vert
Normal file
11
projekt_grk/shaders/shader_bloom.vert
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#version 430 core
|
||||||
|
layout (location = 7) in vec3 aPos;
|
||||||
|
layout (location = 8) in vec2 aTexCoords;
|
||||||
|
|
||||||
|
out vec2 TexCoords;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
TexCoords = aTexCoords;
|
||||||
|
gl_Position = vec4(aPos, 1.0);
|
||||||
|
}
|
33
projekt_grk/shaders/shader_blur.frag
Normal file
33
projekt_grk/shaders/shader_blur.frag
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#version 430 core
|
||||||
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
in vec2 TexCoords;
|
||||||
|
|
||||||
|
uniform sampler2D image;
|
||||||
|
|
||||||
|
uniform int count;
|
||||||
|
uniform bool horizontal;
|
||||||
|
uniform float weight[5] = float[] (0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162);
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 tex_offset = 1.0 / textureSize(image, 0); // gets size of single texel
|
||||||
|
vec3 result = texture(image, TexCoords).rgb * weight[0];
|
||||||
|
if(horizontal)
|
||||||
|
{
|
||||||
|
for(int i = 1; i < count; ++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);
|
||||||
|
}
|
11
projekt_grk/shaders/shader_blur.vert
Normal file
11
projekt_grk/shaders/shader_blur.vert
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#version 430 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
layout (location = 1) in vec2 aTexCoords;
|
||||||
|
|
||||||
|
out vec2 TexCoords;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
TexCoords = aTexCoords;
|
||||||
|
gl_Position = vec4(aPos, 1.0);
|
||||||
|
}
|
@ -1,12 +1,21 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
|
|
||||||
|
layout (location = 0) out vec4 outColor;
|
||||||
|
layout (location = 1) out vec4 BrightColor;
|
||||||
|
|
||||||
uniform samplerCube skybox;
|
uniform samplerCube skybox;
|
||||||
|
|
||||||
in vec3 texCoord;
|
in vec3 texCoord;
|
||||||
|
|
||||||
out vec4 out_color;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
out_color = texture(skybox,texCoord);
|
vec4 texColor = texture(skybox, texCoord);
|
||||||
}
|
|
||||||
|
float brightness = dot(texColor.rgb, vec3(0.2126, 0.7152, 0.0722));
|
||||||
|
if (brightness > 0.2)
|
||||||
|
BrightColor = vec4(texColor.rgb, 1.0);
|
||||||
|
else
|
||||||
|
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
outColor = texColor;
|
||||||
|
}
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
|
|
||||||
|
layout (location = 0) out vec4 outColor;
|
||||||
|
layout (location = 1) out vec4 BrightColor;
|
||||||
uniform float exposition;
|
uniform float exposition;
|
||||||
uniform sampler2D sunTexture;
|
uniform sampler2D sunTexture;
|
||||||
|
|
||||||
in vec2 TexCoords;
|
in vec2 TexCoords;
|
||||||
out vec4 outColor;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 textureColor = texture(sunTexture, TexCoords).xyz;
|
vec3 textureColor = texture(sunTexture, TexCoords).xyz;
|
||||||
vec3 adjustedColor = textureColor * exposition;
|
vec3 adjustedColor = textureColor * exposition;
|
||||||
|
vec3 finalColor = clamp(adjustedColor, 0.0, 1.0);
|
||||||
outColor = vec4(clamp(adjustedColor, 0.0, 1.0), 1.0);
|
outColor = vec4(finalColor, 1.0);
|
||||||
|
|
||||||
|
float brightness = dot(finalColor, vec3(0.2126, 0.7152, 0.0722));
|
||||||
|
if(brightness > 0.2)
|
||||||
|
BrightColor = vec4(finalColor, 1.0);
|
||||||
|
else
|
||||||
|
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,8 @@ GLuint programSun;
|
|||||||
GLuint programTex;
|
GLuint programTex;
|
||||||
GLuint programSkyBox;
|
GLuint programSkyBox;
|
||||||
GLuint programSpaceShip;
|
GLuint programSpaceShip;
|
||||||
|
GLuint programBlur;
|
||||||
|
GLuint programBloom;
|
||||||
Core::Shader_Loader shaderLoader;
|
Core::Shader_Loader shaderLoader;
|
||||||
|
|
||||||
Core::RenderContext shipContext;
|
Core::RenderContext shipContext;
|
||||||
@ -72,6 +74,18 @@ GLuint VAO,VBO;
|
|||||||
float aspectRatio = 1.f;
|
float aspectRatio = 1.f;
|
||||||
unsigned int textureID;
|
unsigned int textureID;
|
||||||
|
|
||||||
|
unsigned int hdrFBO;
|
||||||
|
unsigned int colorBuffers[2];
|
||||||
|
unsigned int pingpongFBO[2];
|
||||||
|
unsigned int pingpongColorbuffers[2];
|
||||||
|
unsigned int rboDepth;
|
||||||
|
|
||||||
|
int HDR_WIDTH;
|
||||||
|
int HDR_HEIGHT;
|
||||||
|
int blur_count = 5;
|
||||||
|
float bloom_exposure = 2.0f;
|
||||||
|
bool bloom = true;
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 createCameraMatrix()
|
glm::mat4 createCameraMatrix()
|
||||||
{
|
{
|
||||||
@ -110,6 +124,91 @@ glm::mat4 createPerspectiveMatrix()
|
|||||||
return perspectiveMatrix;
|
return perspectiveMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int quadVAO = 0;
|
||||||
|
unsigned int quadVBO;
|
||||||
|
|
||||||
|
void renderQuad()
|
||||||
|
{
|
||||||
|
if (quadVAO == 0)
|
||||||
|
{
|
||||||
|
float quadVertices[] = {
|
||||||
|
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||||
|
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
||||||
|
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
||||||
|
};
|
||||||
|
glGenVertexArrays(1, &quadVAO);
|
||||||
|
glGenBuffers(1, &quadVBO);
|
||||||
|
|
||||||
|
glBindVertexArray(quadVAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
||||||
|
// locations 7 i 8 aby nie by³o kolizii z shaderem statku
|
||||||
|
glEnableVertexAttribArray(7);
|
||||||
|
glVertexAttribPointer(7, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(8);
|
||||||
|
glVertexAttribPointer(8, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
}
|
||||||
|
glBindVertexArray(quadVAO);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void blur(GLFWwindow* window) {
|
||||||
|
glfwGetWindowSize(window, &HDR_WIDTH, &HDR_HEIGHT);
|
||||||
|
glGenFramebuffers(2, pingpongFBO);
|
||||||
|
glGenTextures(2, pingpongColorbuffers);
|
||||||
|
for (unsigned int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[i]);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, HDR_WIDTH, HDR_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); // we clamp to the edge as the blur filter would otherwise sample repeated texture values!
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongColorbuffers[i], 0);
|
||||||
|
// also check if framebuffers are complete (no need for depth buffer)
|
||||||
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
std::cout << "Framebuffer not complete!" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void initRBOandHDR(GLFWwindow* window) {
|
||||||
|
glfwGetWindowSize(window, &HDR_WIDTH, &HDR_HEIGHT);
|
||||||
|
glGenFramebuffers(1, &hdrFBO);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
|
||||||
|
glGenTextures(2, colorBuffers);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < 2; i++) {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, colorBuffers[i]);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, HDR_WIDTH, HDR_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 + i, GL_TEXTURE_2D, colorBuffers[i], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenRenderbuffers(1, &rboDepth);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, HDR_WIDTH, HDR_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;
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color) {
|
void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color) {
|
||||||
GLuint prog = program;
|
GLuint prog = program;
|
||||||
glUseProgram(prog);
|
glUseProgram(prog);
|
||||||
@ -149,6 +248,36 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture
|
|||||||
Core::DrawContext(context);
|
Core::DrawContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawSunBlur() {
|
||||||
|
bool horizontal = true, first_iteration = true;
|
||||||
|
unsigned int amount = 10;
|
||||||
|
glUseProgram(programBlur);
|
||||||
|
glUniform1i(glGetUniformLocation(programBlur, "count"), blur_count);
|
||||||
|
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] : pingpongColorbuffers[!horizontal]);
|
||||||
|
renderQuad();
|
||||||
|
horizontal = !horizontal;
|
||||||
|
if (first_iteration)
|
||||||
|
first_iteration = false;
|
||||||
|
}
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glUseProgram(programBloom);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
|
||||||
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[!horizontal]);
|
||||||
|
glUniform1i(glGetUniformLocation(programBloom, "bloom"), bloom);
|
||||||
|
glUniform1f(glGetUniformLocation(programBloom, "exposure"), bloom_exposure);
|
||||||
|
renderQuad();
|
||||||
|
}
|
||||||
|
|
||||||
void drawObjectSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
|
void drawObjectSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glUseProgram(programSkyBox);
|
glUseProgram(programSkyBox);
|
||||||
@ -190,7 +319,6 @@ void drawSpaceShip(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void renderPlanet(float time, float orbitRadius, float orbitRotationSpeed, float selfRotationSpeed, float scale, GLuint planetTexture, GLuint normalTexture) {
|
void renderPlanet(float time, float orbitRadius, float orbitRotationSpeed, float selfRotationSpeed, float scale, GLuint planetTexture, GLuint normalTexture) {
|
||||||
glm::mat4 planetTransform = glm::rotate(glm::mat4(1.0f), time * orbitRotationSpeed, glm::vec3(0, 1, 0)) // orbitowanie dooko³a s³oñca
|
glm::mat4 planetTransform = glm::rotate(glm::mat4(1.0f), time * orbitRotationSpeed, glm::vec3(0, 1, 0)) // orbitowanie dooko³a s³oñca
|
||||||
* glm::translate(glm::vec3(orbitRadius, 0, 0)) // translacja na odp. odleg³oœæ
|
* glm::translate(glm::vec3(orbitRadius, 0, 0)) // translacja na odp. odleg³oœæ
|
||||||
@ -267,6 +395,9 @@ void renderScene(GLFWwindow* window)
|
|||||||
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
//skybox
|
//skybox
|
||||||
drawObjectSkyBox(cubeContext, glm::translate(cameraPos));
|
drawObjectSkyBox(cubeContext, glm::translate(cameraPos));
|
||||||
|
|
||||||
@ -276,7 +407,6 @@ void renderScene(GLFWwindow* window)
|
|||||||
//rendering all the planets
|
//rendering all the planets
|
||||||
renderPlanets();
|
renderPlanets();
|
||||||
|
|
||||||
|
|
||||||
// obliczanie orientacji statku
|
// obliczanie orientacji statku
|
||||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
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::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
||||||
@ -297,12 +427,18 @@ void renderScene(GLFWwindow* window)
|
|||||||
texture::ship, texture::shipNormal, texture::shipMetalness, texture::shipRoughness
|
texture::ship, texture::shipNormal, texture::shipMetalness, texture::shipRoughness
|
||||||
);
|
);
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
drawSunBlur();
|
||||||
|
|
||||||
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||||
{
|
{
|
||||||
aspectRatio = width / float(height);
|
aspectRatio = width / float(height);
|
||||||
|
initRBOandHDR(window);
|
||||||
|
blur(window);
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
void loadModelToContext(std::string path, Core::RenderContext& context)
|
void loadModelToContext(std::string path, Core::RenderContext& context)
|
||||||
@ -321,6 +457,7 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
|
|||||||
void init(GLFWwindow* window)
|
void init(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
initRBOandHDR(window);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
program = shaderLoader.CreateProgram("shaders/shader_5_1.vert", "shaders/shader_5_1.frag");
|
program = shaderLoader.CreateProgram("shaders/shader_5_1.vert", "shaders/shader_5_1.frag");
|
||||||
@ -328,6 +465,8 @@ void init(GLFWwindow* window)
|
|||||||
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
|
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
|
||||||
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||||
programSpaceShip = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_pbr.frag");
|
programSpaceShip = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_pbr.frag");
|
||||||
|
programBlur = shaderLoader.CreateProgram("shaders/shader_blur.vert", "shaders/shader_blur.frag");
|
||||||
|
programBloom = shaderLoader.CreateProgram("shaders/shader_bloom.vert", "shaders/shader_bloom.frag");
|
||||||
|
|
||||||
|
|
||||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
loadModelToContext("./models/sphere.obj", sphereContext);
|
||||||
@ -360,7 +499,6 @@ void init(GLFWwindow* window)
|
|||||||
texture::shipMetalness = Core::LoadTexture("textures/new_spaceship/ship_metalic.jpg");
|
texture::shipMetalness = Core::LoadTexture("textures/new_spaceship/ship_metalic.jpg");
|
||||||
texture::shipRoughness = Core::LoadTexture("textures/new_spaceship/ship_roughness.jpg");
|
texture::shipRoughness = Core::LoadTexture("textures/new_spaceship/ship_roughness.jpg");
|
||||||
|
|
||||||
|
|
||||||
//skybox
|
//skybox
|
||||||
glGenTextures(1, &textureID);
|
glGenTextures(1, &textureID);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
|
||||||
@ -393,6 +531,13 @@ void init(GLFWwindow* window)
|
|||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||||
//skybox end
|
//skybox end
|
||||||
|
|
||||||
|
blur(window);
|
||||||
|
|
||||||
|
glUseProgram(programBlur);
|
||||||
|
glUniform1i(glGetUniformLocation(programBloom, "image"), 0);
|
||||||
|
glUseProgram(programBloom);
|
||||||
|
glUniform1i(glGetUniformLocation(programBloom, "scene"), 0);
|
||||||
|
glUniform1i(glGetUniformLocation(programBloom, "bloomBlur"), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdown(GLFWwindow* window)
|
void shutdown(GLFWwindow* window)
|
||||||
@ -400,7 +545,6 @@ void shutdown(GLFWwindow* window)
|
|||||||
shaderLoader.DeleteProgram(program);
|
shaderLoader.DeleteProgram(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
//obsluga wejscia
|
|
||||||
void processInput(GLFWwindow* window)
|
void processInput(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||||
@ -432,13 +576,10 @@ void processInput(GLFWwindow* window)
|
|||||||
cameraDir = spaceshipDir;
|
cameraDir = spaceshipDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void renderLoop(GLFWwindow* window) {
|
void renderLoop(GLFWwindow* window) {
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
|
|
||||||
processInput(window);
|
processInput(window);
|
||||||
|
|
||||||
renderScene(window);
|
renderScene(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user