commit but not pushed because skybox puf
This commit is contained in:
parent
cfd744b476
commit
1645ef73cd
@ -15,8 +15,12 @@
|
||||
<None Include="shaders\shader_4_sun.vert" />
|
||||
<None Include="shaders\shader_4_tex.frag" />
|
||||
<None Include="shaders\shader_4_tex.vert" />
|
||||
<None Include="shaders\shader_bloom.frag" />
|
||||
<None Include="shaders\shader_bloom.vert" />
|
||||
<None Include="shaders\shader_bloom1.frag" />
|
||||
<None Include="shaders\shader_bloom1.vert" />
|
||||
<None Include="shaders\shader_bloom2.frag" />
|
||||
<None Include="shaders\shader_bloom2.vert" />
|
||||
<None Include="shaders\shader_bloom3.frag" />
|
||||
<None Include="shaders\shader_bloom3.vert" />
|
||||
<None Include="shaders\shader_color.frag" />
|
||||
<None Include="shaders\shader_color.vert" />
|
||||
<None Include="shaders\shader_skybox.frag" />
|
||||
@ -57,7 +61,7 @@
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
|
@ -48,10 +48,22 @@
|
||||
<None Include="shaders\shader_skybox.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom.frag">
|
||||
<None Include="shaders\shader_bloom2.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom.vert">
|
||||
<None Include="shaders\shader_bloom2.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom3.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom3.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom1.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom1.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
@ -1,5 +1,8 @@
|
||||
#version 430 core
|
||||
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 color;
|
||||
@ -45,5 +48,6 @@ void main()
|
||||
fragColor += mix(texture,texture*diffuse+vec3(1)*specular,0.9);
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(fragColor, 1.0) + ambient;
|
||||
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
FragColor = vec4(fragColor, 1.0) + ambient;
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
#version 430 core
|
||||
layout (location = 0) out vec4 fragColor;
|
||||
layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
in vec3 fragPos;
|
||||
in vec3 interpNormal;
|
||||
in vec2 vTexCoords;
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 color;
|
||||
};
|
||||
|
||||
#define NR_POINT_LIGHTS 2
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 cameraPos;
|
||||
uniform sampler2D colorTexture;
|
||||
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 result = vec3(0,0,0);
|
||||
vec4 textureColor = texture2D(colorTexture, -vTexCoords);
|
||||
vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * textureColor;
|
||||
vec3 normal = normalize(interpNormal);
|
||||
for(int i = 0; i < NR_POINT_LIGHTS; i++)
|
||||
{
|
||||
vec3 lightDir = normalize(pointLights[i].position - fragPos);
|
||||
|
||||
vec3 V = normalize(cameraPos-fragPos);
|
||||
vec3 R = reflect(-normalize(lightDir),normal);
|
||||
|
||||
float specular = pow(max(0,dot(R,V)),10);
|
||||
float diffuse = max(0,dot(normal,normalize(lightDir)));
|
||||
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * pointLights[i].color;
|
||||
result += mix(texture,texture*diffuse+vec3(1)*specular,0.9);
|
||||
}
|
||||
|
||||
result = (fragColor + ambient).xyz;
|
||||
|
||||
// check whether result is higher than some threshold, if so, output as bloom threshold color
|
||||
float brightness = dot(result, vec3(0.2126, 0.7152, 0.0722));
|
||||
if(brightness > 1.0)
|
||||
BrightColor = vec4(result, 1.0);
|
||||
else
|
||||
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
fragColor = vec4(result, 1.0);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 vertexPosition;
|
||||
layout (location = 1) in vec3 vertexNormal;
|
||||
layout (location = 2) in vec2 vertexTexCoords;
|
||||
|
||||
out vec3 fragPos;
|
||||
out vec3 interpNormal;
|
||||
out vec2 vTexCoords;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 matrixModel;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragPos = vec3(matrixModel * vec4(vertexPosition, 1.0));
|
||||
vTexCoords = vertexTexCoords;
|
||||
|
||||
mat3 normalMatrix = transpose(inverse(mat3(matrixModel)));
|
||||
interpNormal = normalize(normalMatrix * vertexNormal);
|
||||
|
||||
gl_Position = transformation * matrixModel * vec4(vertexPosition, 1.0);
|
||||
}
|
28
shaders/shader_bloom1.frag
Normal file
28
shaders/shader_bloom1.frag
Normal file
@ -0,0 +1,28 @@
|
||||
#version 430 core
|
||||
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 cameraPos;
|
||||
uniform sampler2D colorTexture;
|
||||
uniform vec3 colorTex;
|
||||
in vec3 interpNormal;
|
||||
in vec3 fragPos;
|
||||
in vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = normalize(interpNormal);
|
||||
vec3 V = normalize(cameraPos-fragPos);
|
||||
float coef = pow(max(0,dot(normal,V)),2);
|
||||
vec4 textureColor = texture2D(colorTexture, -vTexCoord);
|
||||
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z) * colorTex;
|
||||
FragColor = vec4(texture + texture * coef, 1.0);
|
||||
|
||||
float brightness = dot(FragColor.rgb, vec3(0.2, 0.7, 0.07));
|
||||
if(brightness > 1.0)
|
||||
BrightColor = vec4(FragColor.rgb, 1.0);
|
||||
else
|
||||
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
19
shaders/shader_bloom1.vert
Normal file
19
shaders/shader_bloom1.vert
Normal file
@ -0,0 +1,19 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec2 vertexTexCoord;
|
||||
layout(location = 2) in vec3 vertexNormal;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
out vec3 interpNormal;
|
||||
out vec3 fragPos;
|
||||
out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
interpNormal = (modelMatrix*vec4(vertexNormal,0)).xyz;
|
||||
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
|
||||
vTexCoord = vertexTexCoord;
|
||||
}
|
32
shaders/shader_bloom2.frag
Normal file
32
shaders/shader_bloom2.frag
Normal file
@ -0,0 +1,32 @@
|
||||
#version 430 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 vTexCoords;
|
||||
|
||||
uniform sampler2D image;
|
||||
|
||||
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, vTexCoords).rgb * weight[0];
|
||||
if(horizontal)
|
||||
{
|
||||
for(int i = 1; i < 5; ++i)
|
||||
{
|
||||
result += texture(image, vTexCoords + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
|
||||
result += texture(image, vTexCoords - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 1; i < 5; ++i)
|
||||
{
|
||||
result += texture(image, vTexCoords + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
|
||||
result += texture(image, vTexCoords - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
|
||||
}
|
||||
}
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
11
shaders/shader_bloom2.vert
Normal file
11
shaders/shader_bloom2.vert
Normal file
@ -0,0 +1,11 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 vertexPosition;
|
||||
layout (location = 1) in vec2 vertexTexCoords;
|
||||
|
||||
out vec2 vTexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
vTexCoords = vertexTexCoords;
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
}
|
20
shaders/shader_bloom3.frag
Normal file
20
shaders/shader_bloom3.frag
Normal file
@ -0,0 +1,20 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 vTexCoords;
|
||||
|
||||
uniform sampler2D scene;
|
||||
uniform sampler2D bloomBlur;
|
||||
|
||||
void main()
|
||||
{
|
||||
const float gamma = 2.2;
|
||||
vec3 hdrColor = texture(scene, vTexCoords).rgb;
|
||||
vec3 bloomColor = texture(bloomBlur, vTexCoords).rgb;
|
||||
hdrColor += bloomColor; // additive blending
|
||||
// tone mapping
|
||||
vec3 result = vec3(1.0) - exp(-hdrColor * 1.0f);
|
||||
// also gamma correct while we're at it
|
||||
result = pow(result, vec3(1.0 / gamma));
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
11
shaders/shader_bloom3.vert
Normal file
11
shaders/shader_bloom3.vert
Normal file
@ -0,0 +1,11 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 vertexPosition;
|
||||
layout (location = 1) in vec2 vertexTexCoords;
|
||||
|
||||
out vec2 vTexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
vTexCoords = vertexTexCoords;
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
}
|
@ -1,17 +1,53 @@
|
||||
#version 430 core
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
uniform vec3 lightDir;
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 color;
|
||||
float intensity;
|
||||
};
|
||||
|
||||
#define NR_POINT_LIGHTS 5
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 cameraPos;
|
||||
uniform sampler2D colorTexture;
|
||||
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||
|
||||
in vec3 interpNormal;
|
||||
in vec2 interpTexCoord;
|
||||
in vec3 fragPos;
|
||||
in vec2 vTexCoord;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y); // Poprawka dla tekstur Ziemi, ktore bez tego wyswietlaja sie 'do gory nogami'
|
||||
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
|
||||
vec3 fragColor = vec3(0,0,0);
|
||||
vec4 textureColor = texture2D(colorTexture, vTexCoord);
|
||||
vec4 ambient = vec4(0.1, 0.1, 0.1, 1.0) * textureColor;
|
||||
vec3 normal = normalize(interpNormal);
|
||||
float ambient = 0.2;
|
||||
float diffuse = max(dot(normal, -lightDir), 0.0);
|
||||
gl_FragColor = vec4(color * (ambient + (1-ambient) * diffuse), 1.0);
|
||||
for(int i = 0; i < NR_POINT_LIGHTS; i++)
|
||||
{
|
||||
vec3 lightDir = normalize(pointLights[i].position - fragPos);
|
||||
|
||||
vec3 V = normalize(cameraPos-fragPos);
|
||||
vec3 R = reflect(-lightDir,normal);
|
||||
|
||||
float dist = distance(fragPos, pointLights[i].position) / 5;
|
||||
float distance = (1/dist) * (1/dist);
|
||||
|
||||
float spec = pow(max(0,dot(R,V)),2);
|
||||
float diff = max(0,dot(normal,normalize(lightDir)));
|
||||
|
||||
vec3 diffuse = pointLights[i].color * diff * distance * pointLights[i].intensity;
|
||||
vec3 specular = spec * pointLights[i].color * (pointLights[i].intensity/dist);
|
||||
|
||||
vec3 texture = vec3(textureColor.x, textureColor.y, textureColor.z); // * pointLights[i].color;
|
||||
fragColor += mix(texture,texture*diffuse+vec3(1)*specular,0.9);
|
||||
}
|
||||
|
||||
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
FragColor = vec4(fragColor, 1.0) + ambient;
|
||||
}
|
||||
|
@ -4,15 +4,17 @@ layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec2 vertexTexCoord;
|
||||
layout(location = 2) in vec3 vertexNormal;
|
||||
|
||||
uniform mat4 modelViewProjectionMatrix;
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
out vec3 interpNormal;
|
||||
out vec2 interpTexCoord;
|
||||
out vec3 fragPos;
|
||||
out vec2 vTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
||||
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
||||
interpTexCoord = vertexTexCoord;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
interpNormal = (modelMatrix*vec4(vertexNormal,0)).xyz;
|
||||
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
|
||||
vTexCoord = vertexTexCoord;
|
||||
}
|
||||
|
212
src/main.cpp
212
src/main.cpp
@ -18,14 +18,29 @@
|
||||
#include <assimp/postprocess.h>
|
||||
#include "model.h"
|
||||
|
||||
int SCR_WIDTH = 1240;
|
||||
int SCR_HEIGHT = 720;
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
//int winId;
|
||||
GLuint program;
|
||||
GLuint programTex;
|
||||
GLuint programSun;
|
||||
GLuint programSkybox;
|
||||
|
||||
|
||||
|
||||
|
||||
GLuint programBloom1;
|
||||
GLuint programBloom2;
|
||||
GLuint programBloom3;
|
||||
|
||||
unsigned int pingpongFBO[2];
|
||||
unsigned int pingpongColorbuffers[2];
|
||||
unsigned int FBO;
|
||||
unsigned int colorBuffers[2];
|
||||
|
||||
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
Core::RenderContext armContext;
|
||||
@ -91,8 +106,22 @@ void keyboard(unsigned char key, int x, int y)
|
||||
float moveSpeed = 0.1f;
|
||||
switch (key)
|
||||
{
|
||||
case 'q': cameraAngle -= angleSpeed; break;
|
||||
case 'e': cameraAngle += angleSpeed; break;
|
||||
case 'q':
|
||||
{
|
||||
cameraAngle -= angleSpeed;
|
||||
lights[3].intensity = 0.001;
|
||||
engineLightTimer = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'e':
|
||||
{
|
||||
cameraAngle += angleSpeed;
|
||||
lights[2].intensity = 0.001;
|
||||
engineLightTimer = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'w':
|
||||
{
|
||||
cameraPos += cameraDir * moveSpeed;
|
||||
@ -109,6 +138,37 @@ void keyboard(unsigned char key, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
// renderQuad() renders a 1x1 XY quad in NDC
|
||||
// -----------------------------------------
|
||||
unsigned int quadVAO = 0;
|
||||
unsigned int quadVBO;
|
||||
void renderQuad()
|
||||
{
|
||||
if (quadVAO == 0)
|
||||
{
|
||||
float quadVertices[] = {
|
||||
// positions // texture Coords
|
||||
-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,
|
||||
};
|
||||
// setup plane VAO
|
||||
glGenVertexArrays(1, &quadVAO);
|
||||
glGenBuffers(1, &quadVBO);
|
||||
glBindVertexArray(quadVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
}
|
||||
glBindVertexArray(quadVAO);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
// Obliczanie kierunku patrzenia kamery (w plaszczyznie x-z) przy uzyciu zmiennej cameraAngle kontrolowanej przez klawisze.
|
||||
@ -191,15 +251,17 @@ unsigned int loadCubemap(std::vector<std::string> faces)
|
||||
void drawSkybox(GLuint program, Core::RenderContext context, GLuint texID)
|
||||
{
|
||||
glUseProgram(program);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glm::mat4 transformation = perspectiveMatrix * glm::mat4(glm::mat3(cameraMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glDepthMask(GL_FALSE);
|
||||
//glDepthMask(GL_FALSE);
|
||||
//Core::SetActiveTexture(texID, "skybox", program, 0);
|
||||
glUniform1i(glGetUniformLocation(program, "skybox"), 0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
|
||||
Core::DrawContext(context);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDepthFunc(GL_LESS);
|
||||
//glDepthMask(GL_TRUE);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
@ -246,26 +308,22 @@ void renderScene()
|
||||
perspectiveMatrix = Core::createPerspectiveMatrix(0.01f, 1000.0f, frustumScale);
|
||||
float time = glutGet(GLUT_ELAPSED_TIME) / 1000.f;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
drawSkybox(programSkybox, cubeContext, skyboxTexture);
|
||||
|
||||
glUseProgram(programSun);
|
||||
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
|
||||
//ustalanie pozycji s³oñc (lightPos)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
//rysowanie s³oñc
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
|
||||
//ustalanie pozycji slonc (lightPos)
|
||||
glm::mat4 sunModelMatrix = glm::mat4(1.0f);
|
||||
sunModelMatrix = glm::translate(sunModelMatrix, sunPos);
|
||||
sunModelMatrix = glm::scale(sunModelMatrix, glm::vec3(3.0f, 3.0f, 3.0f));
|
||||
drawObjectTexture(programSun, sphereContext, sunModelMatrix, glm::vec3(1.5f, 1.8f, 1.8f), sunTexture);
|
||||
|
||||
glm::mat4 sunModelMatrix2 = glm::mat4(1.0f);
|
||||
sunModelMatrix2 = glm::translate(sunModelMatrix2, sunPos2);
|
||||
drawObjectTexture(programSun, sphereContext, sunModelMatrix2, glm::vec3(0.9f, 0.9f, 2.0f), sunTexture);
|
||||
|
||||
glUseProgram(programTex);
|
||||
|
||||
@ -313,6 +371,49 @@ void renderScene()
|
||||
drawObjectTexture(programTex, sphereContext, earth, glm::vec3(0.8f, 0.8f, 0.8f), earthTexture);
|
||||
drawObjectTexture(programTex, sphereContext, moon, glm::vec3(0.9f, 1.0f, 0.9f), moonTexture);
|
||||
|
||||
|
||||
|
||||
//rysowanie sloñc
|
||||
|
||||
glUseProgram(programBloom1);
|
||||
glUniform3f(glGetUniformLocation(programBloom1, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
drawObjectTexture(programBloom1, sphereContext, sunModelMatrix, glm::vec3(3.5f, 3.8f, 3.8f), sunTexture);
|
||||
|
||||
drawObjectTexture(programBloom1, sphereContext, sunModelMatrix2, glm::vec3(0.9f, 0.9f, 2.0f), sunTexture);
|
||||
|
||||
|
||||
drawSkybox(programSkybox, cubeContext, skyboxTexture);
|
||||
|
||||
//zabawa z bloomem
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
bool horizontal = true, first_iteration = true;
|
||||
unsigned int amount = 10;
|
||||
glUseProgram(programBloom2);
|
||||
for (unsigned int i = 0; i < amount; i++)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
|
||||
//shaderBlur.setInt("horizontal", horizontal);
|
||||
glUniform1i(glGetUniformLocation(programBloom2, "horizontal"), horizontal);
|
||||
glBindTexture(GL_TEXTURE_2D, first_iteration ? colorBuffers[1] : pingpongColorbuffers[!horizontal]); // bind texture of other framebuffer (or scene if first iteration)
|
||||
renderQuad();
|
||||
horizontal = !horizontal;
|
||||
if (first_iteration)
|
||||
first_iteration = false;
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// 3. now render floating point color buffer to 2D quad and tonemap HDR colors to default framebuffer's (clamped) color range
|
||||
// --------------------------------------------------------------------------------------------------------------------------
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glUseProgram(programBloom3);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[!horizontal]);
|
||||
renderQuad();
|
||||
|
||||
|
||||
if (engineLightTimer < 50) engineLightTimer++;
|
||||
else
|
||||
{
|
||||
@ -320,6 +421,7 @@ void renderScene()
|
||||
lights[3].intensity = 0.00001;
|
||||
}
|
||||
|
||||
|
||||
glUseProgram(0);
|
||||
glutSwapBuffers();
|
||||
}
|
||||
@ -327,14 +429,25 @@ void renderScene()
|
||||
void init()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
program = shaderLoader.CreateProgram("shaders/shader_4_1.vert", "shaders/shader_4_1.frag");
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_4_tex.vert", "shaders/shader_4_tex.frag");
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_4_sun.vert", "shaders/shader_4_sun.frag");
|
||||
programSkybox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||
|
||||
|
||||
|
||||
|
||||
programBloom1 = shaderLoader.CreateProgram("shaders/shader_bloom1.vert", "shaders/shader_bloom1.frag");
|
||||
programBloom2 = shaderLoader.CreateProgram("shaders/shader_bloom2.vert", "shaders/shader_bloom2.frag");
|
||||
programBloom3 = shaderLoader.CreateProgram("shaders/shader_bloom3.vert", "shaders/shader_bloom3.frag");
|
||||
|
||||
glUseProgram(programBloom2);
|
||||
glUniform1i(glGetUniformLocation(programBloom2, "image"), 0);
|
||||
glUseProgram(programBloom3);
|
||||
glUniform1i(glGetUniformLocation(programBloom3, "scene"), 0);
|
||||
glUniform1i(glGetUniformLocation(programBloom3, "bloomBlur"), 1);
|
||||
|
||||
|
||||
|
||||
corvette = std::make_shared<Model>("models/Corvette-F3.obj");
|
||||
crewmate = std::make_shared<Model>("models/space_humster.obj");
|
||||
//shipModel = obj::loadModelFromFile("models/spaceship.obj");
|
||||
@ -350,6 +463,63 @@ void init()
|
||||
moonTexture = Core::LoadTexture("textures/moon.png");
|
||||
skyboxTexture = loadCubemap(faces);
|
||||
|
||||
|
||||
|
||||
glGenFramebuffers(1, &FBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
|
||||
|
||||
glGenTextures(2, colorBuffers);
|
||||
for (unsigned int i = 0; i < 2; i++)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffers[i]);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGBA16F, SCR_WIDTH, SCR_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
|
||||
);
|
||||
}
|
||||
// create and attach depth buffer (renderbuffer)
|
||||
unsigned int rboDepth;
|
||||
glGenRenderbuffers(1, &rboDepth);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, SCR_WIDTH, SCR_HEIGHT);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboDepth);
|
||||
//
|
||||
// tell OpenGL which color attachments we'll use (of this framebuffer) for rendering
|
||||
unsigned int attachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
|
||||
glDrawBuffers(2, attachments);
|
||||
// finally check if framebuffer is complete
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||
std::cout << "Framebuffer not complete!" << std::endl;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// ping-pong-framebuffer for blurring
|
||||
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, SCR_WIDTH, SCR_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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Light l1;
|
||||
l1.position = sunPos;
|
||||
l1.color = glm::vec3(0.8f, 0.8f, 0.7f);
|
||||
@ -379,7 +549,7 @@ void init()
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
shaderLoader.DeleteProgram(program);
|
||||
|
||||
}
|
||||
|
||||
void onReshape(int width, int height)
|
||||
@ -389,6 +559,8 @@ void onReshape(int width, int height)
|
||||
// Oblicz odpowiednio globalna zmienna "frustumScale".
|
||||
// Ustaw odpowiednio viewport - zobacz:
|
||||
// https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glViewport.xhtml
|
||||
SCR_WIDTH = width;
|
||||
SCR_HEIGHT = height;
|
||||
frustumScale = (float)width / (float)height;
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
@ -404,7 +576,7 @@ int main(int argc, char** argv)
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
glutInitWindowPosition(100, 200);
|
||||
glutInitWindowSize(1240, 720);
|
||||
glutInitWindowSize(SCR_WIDTH, SCR_HEIGHT);
|
||||
glutCreateWindow("GRK-PROJECT WIP");
|
||||
//winId = glutCreateWindow("OpenGL + PhysX");
|
||||
//glutFullScreen();
|
||||
|
Loading…
Reference in New Issue
Block a user