Add bloom
This commit is contained in:
parent
1645ef73cd
commit
b7731e7faf
@ -11,20 +11,16 @@
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\shader_4_sun.frag" />
|
||||
<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_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_bloom.frag" />
|
||||
<None Include="shaders\shader_bloom.vert" />
|
||||
<None Include="shaders\shader_blur.frag" />
|
||||
<None Include="shaders\shader_blur.vert" />
|
||||
<None Include="shaders\shader_color.frag" />
|
||||
<None Include="shaders\shader_color.vert" />
|
||||
<None Include="shaders\shader_skybox.frag" />
|
||||
<None Include="shaders\shader_skybox.vert" />
|
||||
<None Include="shaders\shader_sun.frag" />
|
||||
<None Include="shaders\shader_sun.vert" />
|
||||
<None Include="shaders\shader_tex.frag" />
|
||||
<None Include="shaders\shader_tex.vert" />
|
||||
</ItemGroup>
|
||||
|
@ -30,40 +30,28 @@
|
||||
<None Include="shaders\shader_tex.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_4_tex.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_4_tex.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_4_sun.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_4_sun.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_skybox.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_skybox.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom2.frag">
|
||||
<None Include="shaders\shader_bloom.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom2.vert">
|
||||
<None Include="shaders\shader_bloom.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom3.frag">
|
||||
<None Include="shaders\shader_blur.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom3.vert">
|
||||
<None Include="shaders\shader_blur.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom1.frag">
|
||||
<None Include="shaders\shader_sun.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom1.vert">
|
||||
<None Include="shaders\shader_sun.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
@ -1,21 +0,0 @@
|
||||
#version 430 core
|
||||
|
||||
uniform vec3 objectColor;
|
||||
//uniform vec3 lightDir;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
in vec3 interpNormal;
|
||||
in vec3 fragPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightDir = normalize(lightPos-fragPos);
|
||||
vec3 V = normalize(cameraPos-fragPos);
|
||||
vec3 normal = normalize(interpNormal);
|
||||
vec3 R = reflect(-normalize(lightDir),normal);
|
||||
|
||||
float specular = pow(max(0,dot(R,V)),10);
|
||||
float diffuse = max(0,dot(normal,normalize(lightDir)));
|
||||
gl_FragColor = vec4(mix(objectColor,objectColor*diffuse+vec3(1)*specular,0.9), 1.0);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 2) in vec2 vertexTexCoord;
|
||||
layout(location = 1) in vec3 vertexNormal;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
out vec3 interpNormal;
|
||||
out vec3 fragPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
interpNormal = (modelMatrix*vec4(vertexNormal,0)).xyz;
|
||||
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#version 430 core
|
||||
|
||||
uniform vec3 objectColor;
|
||||
//uniform vec3 lightDir;
|
||||
uniform vec3 lightPos;
|
||||
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;
|
||||
gl_FragColor = vec4(texture + texture * coef, 1.0);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
#version 430 core
|
||||
|
||||
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 vec3 fragPos;
|
||||
in vec2 vTexCoord;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
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);
|
||||
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;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#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;
|
||||
}
|
@ -8,13 +8,11 @@ uniform sampler2D bloomBlur;
|
||||
|
||||
void main()
|
||||
{
|
||||
const float gamma = 2.2;
|
||||
const float gamma = 1.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
|
||||
hdrColor += bloomColor;
|
||||
vec3 result = vec3(1.0) - exp(-hdrColor * 1.0f);
|
||||
result = pow(result, vec3(1.0 / gamma));
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
#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;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 BrightColor;
|
||||
|
||||
in vec3 TexCoords;
|
||||
|
||||
@ -8,4 +9,5 @@ uniform samplerCube skybox;
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(skybox, TexCoords);
|
||||
BrightColor = vec4(0,0,0,1.0);
|
||||
}
|
@ -8,5 +8,5 @@ uniform mat4 transformation;
|
||||
void main()
|
||||
{
|
||||
TexCoords = vertexPosition;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
gl_Position = (transformation * vec4(vertexPosition, 1.0)).xyww;
|
||||
}
|
@ -21,7 +21,7 @@ void main()
|
||||
FragColor = vec4(texture + texture * coef, 1.0);
|
||||
|
||||
float brightness = dot(FragColor.rgb, vec3(0.2, 0.7, 0.07));
|
||||
if(brightness > 1.0)
|
||||
if(brightness > 0.7)
|
||||
BrightColor = vec4(FragColor.rgb, 1.0);
|
||||
else
|
||||
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
172
src/main 2.2.cpp
172
src/main 2.2.cpp
@ -1,172 +0,0 @@
|
||||
#include "glew.h"
|
||||
#include "freeglut.h"
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
|
||||
#include "Shader_Loader.h"
|
||||
#include "Render_Utils.h"
|
||||
#include "Camera.h"
|
||||
|
||||
|
||||
#include "Box.cpp"
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
|
||||
Core::RenderContext armContext;
|
||||
|
||||
|
||||
std::vector<Core::RenderContext> armContexts;
|
||||
std::vector<Core::Node> arm;
|
||||
int ballIndex;
|
||||
|
||||
|
||||
float cameraAngle = 0;
|
||||
glm::vec3 cameraPos = glm::vec3(-6, 0, 0);
|
||||
glm::vec3 cameraDir;
|
||||
|
||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||
|
||||
void keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
float angleSpeed = 0.1f;
|
||||
float moveSpeed = 0.1f;
|
||||
switch (key)
|
||||
{
|
||||
case 'z': cameraAngle -= angleSpeed; break;
|
||||
case 'x': cameraAngle += angleSpeed; break;
|
||||
case 'w': cameraPos += cameraDir * moveSpeed; break;
|
||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
||||
case 'd': cameraPos += glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||
case 'a': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||
case 'e': cameraPos += glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
||||
case 'q': cameraPos -= glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
// Obliczanie kierunku patrzenia kamery (w plaszczyznie x-z) przy uzyciu zmiennej cameraAngle kontrolowanej przez klawisze.
|
||||
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
|
||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
|
||||
return Core::createViewMatrix(cameraPos, cameraDir, up);
|
||||
}
|
||||
|
||||
void drawObject(GLuint program, Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
|
||||
{
|
||||
glUniform3f(glGetUniformLocation(program, "objectColor"), color.x, color.y, color.z);
|
||||
|
||||
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
|
||||
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
void renderScene()
|
||||
{
|
||||
// Aktualizacja macierzy widoku i rzutowania. Macierze sa przechowywane w zmiennych globalnych, bo uzywa ich funkcja drawObject.
|
||||
// (Bardziej elegancko byloby przekazac je jako argumenty do funkcji, ale robimy tak dla uproszczenia kodu.
|
||||
// Jest to mozliwe dzieki temu, ze macierze widoku i rzutowania sa takie same dla wszystkich obiektow!)
|
||||
cameraMatrix = createCameraMatrix();
|
||||
perspectiveMatrix = Core::createPerspectiveMatrix();
|
||||
float time = glutGet(GLUT_ELAPSED_TIME) / 1000.f;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
// Macierz statku "przyczpeia" go do kamery. Wrato przeanalizowac te linijke i zrozumiec jak to dziala.
|
||||
glm::vec3 lightPos = glm::vec3(-4, 1, -4);
|
||||
//glUniform3f(glGetUniformLocation(program, "light_dir"), 2, 1, 0);
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), lightPos.x, lightPos.y, lightPos.z);
|
||||
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
float y = 0;
|
||||
for (auto context : armContexts) {
|
||||
drawObject(program, context, glm::translate(glm::vec3(0, y, 0)), glm::vec3(0.6f));
|
||||
y += 0.1;
|
||||
}
|
||||
|
||||
glUseProgram(0);
|
||||
glutSwapBuffers();
|
||||
}
|
||||
void loadRecusive(const aiScene* scene, aiNode* node) {
|
||||
for (int i = 0; i < node->mNumMeshes; i++) {
|
||||
Core::RenderContext context;
|
||||
context.initFromAssimpMesh(scene->mMeshes[node->mMeshes[i]]);
|
||||
armContexts.push_back(context);
|
||||
}
|
||||
for (int i = 0; i < node->mNumChildren; i++) {
|
||||
loadRecusive(scene, node->mChildren[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
program = shaderLoader.CreateProgram("shaders/shader_4_1.vert", "shaders/shader_4_1.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_4_sun.vert", "shaders/shader_4_sun.frag");
|
||||
|
||||
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile("models/arm.fbx", aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_CalcTangentSpace);
|
||||
// check for errors
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero
|
||||
{
|
||||
std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
|
||||
return;
|
||||
}
|
||||
auto node = scene->mRootNode->mChildren[0];
|
||||
aiMesh* mesh = scene->mMeshes[node->mMeshes[0]];
|
||||
loadRecusive(scene,scene->mRootNode);
|
||||
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
shaderLoader.DeleteProgram(program);
|
||||
}
|
||||
|
||||
void idle()
|
||||
{
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
|
||||
glutInitWindowPosition(200, 300);
|
||||
glutInitWindowSize(600, 600);
|
||||
glutCreateWindow("OpenGL Pierwszy Program");
|
||||
glewInit();
|
||||
|
||||
init();
|
||||
glutKeyboardFunc(keyboard);
|
||||
glutDisplayFunc(renderScene);
|
||||
glutIdleFunc(idle);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
184
src/main 3.cpp
184
src/main 3.cpp
@ -1,184 +0,0 @@
|
||||
#include "glew.h"
|
||||
#include "freeglut.h"
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
|
||||
#include "Shader_Loader.h"
|
||||
#include "Render_Utils.h"
|
||||
#include "Camera.h"
|
||||
|
||||
|
||||
#include "Box.cpp"
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
|
||||
Core::RenderContext armContext;
|
||||
|
||||
|
||||
std::vector<Core::RenderContext> armContexts;
|
||||
|
||||
std::vector<Core::Node> arm;
|
||||
int ballIndex;
|
||||
|
||||
float cameraAngle = 0;
|
||||
glm::vec3 cameraPos = glm::vec3(-6, 0, 0);
|
||||
glm::vec3 cameraDir;
|
||||
|
||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||
|
||||
void keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
float angleSpeed = 0.1f;
|
||||
float moveSpeed = 0.1f;
|
||||
switch (key)
|
||||
{
|
||||
case 'z': cameraAngle -= angleSpeed; break;
|
||||
case 'x': cameraAngle += angleSpeed; break;
|
||||
case 'w': cameraPos += cameraDir * moveSpeed; break;
|
||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
||||
case 'd': cameraPos += glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||
case 'a': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||
case 'e': cameraPos += glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
||||
case 'q': cameraPos -= glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
// Obliczanie kierunku patrzenia kamery (w plaszczyznie x-z) przy uzyciu zmiennej cameraAngle kontrolowanej przez klawisze.
|
||||
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
|
||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
|
||||
return Core::createViewMatrix(cameraPos, cameraDir, up);
|
||||
}
|
||||
|
||||
void drawObject(GLuint program, Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
|
||||
{
|
||||
glUniform3f(glGetUniformLocation(program, "objectColor"), color.x, color.y, color.z);
|
||||
|
||||
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
|
||||
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
void renderScene()
|
||||
{
|
||||
// Aktualizacja macierzy widoku i rzutowania. Macierze sa przechowywane w zmiennych globalnych, bo uzywa ich funkcja drawObject.
|
||||
// (Bardziej elegancko byloby przekazac je jako argumenty do funkcji, ale robimy tak dla uproszczenia kodu.
|
||||
// Jest to mozliwe dzieki temu, ze macierze widoku i rzutowania sa takie same dla wszystkich obiektow!)
|
||||
cameraMatrix = createCameraMatrix();
|
||||
perspectiveMatrix = Core::createPerspectiveMatrix();
|
||||
float time = glutGet(GLUT_ELAPSED_TIME) / 1000.f;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
// Macierz statku "przyczpeia" go do kamery. Wrato przeanalizowac te linijke i zrozumiec jak to dziala.
|
||||
glm::vec3 lightPos = glm::vec3(-4, 1, -4);
|
||||
//glUniform3f(glGetUniformLocation(program, "light_dir"), 2, 1, 0);
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), lightPos.x, lightPos.y, lightPos.z);
|
||||
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
for (auto part : arm) {
|
||||
glm::mat4 transformation=part.matrix;
|
||||
int parent = part.parent;
|
||||
while (parent != -1) {
|
||||
transformation = arm[parent].matrix * transformation;
|
||||
parent = arm[parent].parent;
|
||||
}
|
||||
for (auto context : part.renderContexts) drawObject(program, context, transformation, glm::vec3(0.6f));
|
||||
}
|
||||
|
||||
glUseProgram(0);
|
||||
glutSwapBuffers();
|
||||
}
|
||||
void loadRecusive(const aiScene* scene, aiNode* node,int parentIndex) {
|
||||
int index = arm.size();
|
||||
arm.push_back(Core::Node());
|
||||
arm[index].parent = parentIndex;
|
||||
arm[index].matrix = Core::mat4_cast(node->mTransformation);
|
||||
for (int i = 0; i < node->mNumMeshes; i++) {
|
||||
Core::RenderContext context;
|
||||
context.initFromAssimpMesh(scene->mMeshes[node->mMeshes[i]]);
|
||||
arm[index].renderContexts.push_back(context);
|
||||
}
|
||||
for (int i = 0; i < node->mNumChildren; i++) {
|
||||
loadRecusive(scene, node->mChildren[i],index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
program = shaderLoader.CreateProgram("shaders/shader_4_1.vert", "shaders/shader_4_1.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_4_sun.vert", "shaders/shader_4_sun.frag");
|
||||
|
||||
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile("models/arm.fbx", aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_CalcTangentSpace);
|
||||
// check for errors
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero
|
||||
{
|
||||
std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
|
||||
return;
|
||||
}
|
||||
auto node = scene->mRootNode->mChildren[0];
|
||||
|
||||
//geting name of node
|
||||
//std::cout << node->mName.data << std::endl;
|
||||
//aiMesh* mesh = scene->mMeshes[node->mMeshes[0]];
|
||||
|
||||
loadRecusive(scene,scene->mRootNode,-1);
|
||||
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
shaderLoader.DeleteProgram(program);
|
||||
}
|
||||
|
||||
void idle()
|
||||
{
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
|
||||
glutInitWindowPosition(200, 300);
|
||||
glutInitWindowSize(600, 600);
|
||||
glutCreateWindow("OpenGL Pierwszy Program");
|
||||
glewInit();
|
||||
|
||||
init();
|
||||
glutKeyboardFunc(keyboard);
|
||||
glutDisplayFunc(renderScene);
|
||||
glutIdleFunc(idle);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
189
src/main 4.cpp
189
src/main 4.cpp
@ -1,189 +0,0 @@
|
||||
#include "glew.h"
|
||||
#include "freeglut.h"
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
|
||||
#include "Shader_Loader.h"
|
||||
#include "Render_Utils.h"
|
||||
#include "Camera.h"
|
||||
|
||||
|
||||
#include "Box.cpp"
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
|
||||
Core::RenderContext armContext;
|
||||
|
||||
|
||||
std::vector<Core::RenderContext> armContexts;
|
||||
|
||||
std::vector<Core::Node> arm;
|
||||
int ballIndex;
|
||||
|
||||
float cameraAngle = 0;
|
||||
glm::vec3 cameraPos = glm::vec3(-6, 0, 0);
|
||||
glm::vec3 cameraDir;
|
||||
|
||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||
|
||||
void keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
float angleSpeed = 0.1f;
|
||||
float moveSpeed = 0.1f;
|
||||
switch (key)
|
||||
{
|
||||
case 'z': cameraAngle -= angleSpeed; break;
|
||||
case 'x': cameraAngle += angleSpeed; break;
|
||||
case 'w': cameraPos += cameraDir * moveSpeed; break;
|
||||
case 's': cameraPos -= cameraDir * moveSpeed; break;
|
||||
case 'd': cameraPos += glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||
case 'a': cameraPos -= glm::cross(cameraDir, glm::vec3(0, 1, 0)) * moveSpeed; break;
|
||||
case 'e': cameraPos += glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
||||
case 'q': cameraPos -= glm::cross(cameraDir, glm::vec3(1, 0, 0)) * moveSpeed; break;
|
||||
case 'o': arm[ballIndex].matrix *= glm::eulerAngleZ(0.03f); break;
|
||||
case 'p': arm[ballIndex].matrix *= glm::eulerAngleZ(-0.03f); break;
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
// Obliczanie kierunku patrzenia kamery (w plaszczyznie x-z) przy uzyciu zmiennej cameraAngle kontrolowanej przez klawisze.
|
||||
cameraDir = glm::vec3(cosf(cameraAngle), 0.0f, sinf(cameraAngle));
|
||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
|
||||
return Core::createViewMatrix(cameraPos, cameraDir, up);
|
||||
}
|
||||
|
||||
void drawObject(GLuint program, Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
|
||||
{
|
||||
glUniform3f(glGetUniformLocation(program, "objectColor"), color.x, color.y, color.z);
|
||||
|
||||
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
|
||||
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
void renderScene()
|
||||
{
|
||||
// Aktualizacja macierzy widoku i rzutowania. Macierze sa przechowywane w zmiennych globalnych, bo uzywa ich funkcja drawObject.
|
||||
// (Bardziej elegancko byloby przekazac je jako argumenty do funkcji, ale robimy tak dla uproszczenia kodu.
|
||||
// Jest to mozliwe dzieki temu, ze macierze widoku i rzutowania sa takie same dla wszystkich obiektow!)
|
||||
cameraMatrix = createCameraMatrix();
|
||||
perspectiveMatrix = Core::createPerspectiveMatrix();
|
||||
float time = glutGet(GLUT_ELAPSED_TIME) / 1000.f;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
// Macierz statku "przyczpeia" go do kamery. Wrato przeanalizowac te linijke i zrozumiec jak to dziala.
|
||||
glm::vec3 lightPos = glm::vec3(-4, 1, -4);
|
||||
//glUniform3f(glGetUniformLocation(program, "light_dir"), 2, 1, 0);
|
||||
glUniform3f(glGetUniformLocation(program, "lightPos"), lightPos.x, lightPos.y, lightPos.z);
|
||||
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
for (auto part : arm) {
|
||||
glm::mat4 transformation=part.matrix;
|
||||
int parent = part.parent;
|
||||
while (parent != -1) {
|
||||
transformation = arm[parent].matrix * transformation;
|
||||
parent = arm[parent].parent;
|
||||
}
|
||||
for (auto context : part.renderContexts) drawObject(program, context, transformation, glm::vec3(0.6f));
|
||||
}
|
||||
|
||||
glUseProgram(0);
|
||||
glutSwapBuffers();
|
||||
}
|
||||
void loadRecusive(const aiScene* scene, aiNode* node,int parentIndex) {
|
||||
int index = arm.size();
|
||||
arm.push_back(Core::Node());
|
||||
arm[index].parent = parentIndex;
|
||||
arm[index].matrix = Core::mat4_cast(node->mTransformation);
|
||||
if (node->mName == aiString("Ball")) {
|
||||
ballIndex = index;
|
||||
}
|
||||
for (int i = 0; i < node->mNumMeshes; i++) {
|
||||
Core::RenderContext context;
|
||||
context.initFromAssimpMesh(scene->mMeshes[node->mMeshes[i]]);
|
||||
arm[index].renderContexts.push_back(context);
|
||||
}
|
||||
for (int i = 0; i < node->mNumChildren; i++) {
|
||||
loadRecusive(scene, node->mChildren[i],index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
program = shaderLoader.CreateProgram("shaders/shader_4_1.vert", "shaders/shader_4_1.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_4_sun.vert", "shaders/shader_4_sun.frag");
|
||||
|
||||
|
||||
Assimp::Importer importer;
|
||||
const aiScene* scene = importer.ReadFile("models/arm.fbx", aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_CalcTangentSpace);
|
||||
// check for errors
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero
|
||||
{
|
||||
std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
|
||||
return;
|
||||
}
|
||||
auto node = scene->mRootNode->mChildren[0];
|
||||
|
||||
//geting name of node
|
||||
//std::cout << node->mName.data << std::endl;
|
||||
//aiMesh* mesh = scene->mMeshes[node->mMeshes[0]];
|
||||
|
||||
loadRecusive(scene,scene->mRootNode,-1);
|
||||
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
shaderLoader.DeleteProgram(program);
|
||||
}
|
||||
|
||||
void idle()
|
||||
{
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
|
||||
glutInitWindowPosition(200, 300);
|
||||
glutInitWindowSize(600, 600);
|
||||
glutCreateWindow("OpenGL Pierwszy Program");
|
||||
glewInit();
|
||||
|
||||
init();
|
||||
glutKeyboardFunc(keyboard);
|
||||
glutDisplayFunc(renderScene);
|
||||
glutIdleFunc(idle);
|
||||
|
||||
glutMainLoop();
|
||||
|
||||
shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
130
src/main.cpp
130
src/main.cpp
@ -25,15 +25,10 @@ int SCR_HEIGHT = 720;
|
||||
#include "stb_image.h"
|
||||
//int winId;
|
||||
GLuint programTex;
|
||||
GLuint programSun;
|
||||
GLuint programSkybox;
|
||||
|
||||
|
||||
|
||||
|
||||
GLuint programBloom1;
|
||||
GLuint programBloom2;
|
||||
GLuint programBloom3;
|
||||
GLuint programSun;
|
||||
GLuint programBlur;
|
||||
GLuint programBloom;
|
||||
|
||||
unsigned int pingpongFBO[2];
|
||||
unsigned int pingpongColorbuffers[2];
|
||||
@ -109,7 +104,7 @@ void keyboard(unsigned char key, int x, int y)
|
||||
case 'q':
|
||||
{
|
||||
cameraAngle -= angleSpeed;
|
||||
lights[3].intensity = 0.001;
|
||||
lights[3].intensity = 0.005;
|
||||
engineLightTimer = 0;
|
||||
break;
|
||||
}
|
||||
@ -117,7 +112,7 @@ void keyboard(unsigned char key, int x, int y)
|
||||
case 'e':
|
||||
{
|
||||
cameraAngle += angleSpeed;
|
||||
lights[2].intensity = 0.001;
|
||||
lights[2].intensity = 0.005;
|
||||
engineLightTimer = 0;
|
||||
break;
|
||||
}
|
||||
@ -125,8 +120,8 @@ void keyboard(unsigned char key, int x, int y)
|
||||
case 'w':
|
||||
{
|
||||
cameraPos += cameraDir * moveSpeed;
|
||||
lights[2].intensity = 0.001;
|
||||
lights[3].intensity = 0.001;
|
||||
lights[2].intensity = 0.005;
|
||||
lights[3].intensity = 0.005;
|
||||
engineLightTimer = 0;
|
||||
break;
|
||||
}
|
||||
@ -138,8 +133,7 @@ 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()
|
||||
@ -147,13 +141,11 @@ 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);
|
||||
@ -315,7 +307,6 @@ void renderScene()
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
|
||||
//ustalanie pozycji slonc (lightPos)
|
||||
glm::mat4 sunModelMatrix = glm::mat4(1.0f);
|
||||
@ -325,20 +316,20 @@ void renderScene()
|
||||
glm::mat4 sunModelMatrix2 = glm::mat4(1.0f);
|
||||
sunModelMatrix2 = glm::translate(sunModelMatrix2, sunPos2);
|
||||
|
||||
glm::mat4 crewmateModelMatrix = glm::translate(glm::vec3(0, 1, 1)) * glm::rotate(time / 2, glm::vec3(1, 0, 1)) * glm::scale(glm::vec3(0.1));
|
||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
|
||||
|
||||
|
||||
glUseProgram(programTex);
|
||||
|
||||
|
||||
|
||||
lights[0].position = sunPos;
|
||||
lights[1].position = sunPos2;
|
||||
|
||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
|
||||
glm::mat4 engineLeft = glm::translate(shipModelMatrix, glm::vec3(500,0,-1500));
|
||||
|
||||
glm::mat4 engineLeft = glm::translate(shipModelMatrix, glm::vec3(700,0,-1500));
|
||||
lights[2].position = glm::vec3(engineLeft[3][0], engineLeft[3][1], engineLeft[3][2]);
|
||||
|
||||
glm::mat4 engineRight = glm::translate(shipModelMatrix, glm::vec3(-500, 0, -1500));
|
||||
glm::mat4 engineRight = glm::translate(shipModelMatrix, glm::vec3(-700, 0, -1500));
|
||||
lights[3].position = glm::vec3(engineRight[3][0], engineRight[3][1], engineRight[3][2]);
|
||||
|
||||
|
||||
for (int i = 0; i < lights.size(); i++)
|
||||
{
|
||||
@ -352,50 +343,33 @@ void renderScene()
|
||||
|
||||
glUniform3f(glGetUniformLocation(programTex, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
|
||||
|
||||
//rysowanie statku
|
||||
//glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.6f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
|
||||
|
||||
drawFromAssimpModel(programTex, corvette, shipModelMatrix, glm::vec3(1));
|
||||
|
||||
glm::mat4 crewmateModelMatrix = glm::translate(glm::vec3(0, 1, 1)) * glm::rotate(time/2, glm::vec3(1, 0, 1)) * glm::scale(glm::vec3(0.1));
|
||||
drawFromAssimpModel(programTex, crewmate, crewmateModelMatrix, glm::vec3(1));
|
||||
|
||||
|
||||
|
||||
|
||||
//rysowanie Ziemi z ksiê¿ycem
|
||||
//rysowanie Ziemi z ksiezycem
|
||||
glm::mat4 earth = drawPlanet(time / 5.0f, sunPos*glm::vec3(1.5f,1,1), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(-10.5f, 0.0f, -10.5f), glm::vec3(0.5f, 0.5f, 0.5f));
|
||||
glm::mat4 moon = drawMoon(earth, time/2.0f, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0, 1, 1), glm::vec3(1.5f, 1.0f, 1.0f), glm::vec3(0.3f, 0.3f, 0.3f));
|
||||
earth = glm::rotate(earth, time/3.0f, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
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);
|
||||
|
||||
glUseProgram(programSun);
|
||||
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
|
||||
|
||||
//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);
|
||||
|
||||
|
||||
drawObjectTexture(programSun, sphereContext, sunModelMatrix, glm::vec3(3.5f, 3.8f, 3.8f), sunTexture);
|
||||
drawObjectTexture(programSun, 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);
|
||||
glUseProgram(programBlur);
|
||||
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)
|
||||
glUniform1i(glGetUniformLocation(programBlur, "horizontal"), horizontal);
|
||||
glBindTexture(GL_TEXTURE_2D, first_iteration ? colorBuffers[1] : pingpongColorbuffers[!horizontal]);
|
||||
renderQuad();
|
||||
horizontal = !horizontal;
|
||||
if (first_iteration)
|
||||
@ -403,10 +377,7 @@ void renderScene()
|
||||
}
|
||||
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);
|
||||
glUseProgram(programBloom);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
@ -430,22 +401,17 @@ void init()
|
||||
{
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
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");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
|
||||
programBlur = shaderLoader.CreateProgram("shaders/shader_blur.vert", "shaders/shader_blur.frag");
|
||||
programBloom = shaderLoader.CreateProgram("shaders/shader_bloom.vert", "shaders/shader_bloom.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);
|
||||
|
||||
glUseProgram(programBlur);
|
||||
glUniform1i(glGetUniformLocation(programBlur, "image"), 0);
|
||||
glUseProgram(programBloom);
|
||||
glUniform1i(glGetUniformLocation(programBloom, "scene"), 0);
|
||||
glUniform1i(glGetUniformLocation(programBloom, "bloomBlur"), 1);
|
||||
glUseProgram(0);
|
||||
|
||||
|
||||
corvette = std::make_shared<Model>("models/Corvette-F3.obj");
|
||||
@ -462,8 +428,6 @@ void init()
|
||||
earthTexture = Core::LoadTexture("textures/earth2.png");
|
||||
moonTexture = Core::LoadTexture("textures/moon.png");
|
||||
skyboxTexture = loadCubemap(faces);
|
||||
|
||||
|
||||
|
||||
glGenFramebuffers(1, &FBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
|
||||
@ -479,27 +443,22 @@ void init()
|
||||
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++)
|
||||
@ -509,17 +468,13 @@ void init()
|
||||
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_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, 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);
|
||||
@ -544,21 +499,15 @@ void init()
|
||||
l4.intensity = 0.0001;
|
||||
lights.push_back(l4);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void onReshape(int width, int height)
|
||||
{
|
||||
// Kiedy rozmiar okna sie zmieni, obraz jest znieksztalcony.
|
||||
// Dostosuj odpowiednio macierz perspektywy i viewport.
|
||||
// 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;
|
||||
@ -584,11 +533,10 @@ int main(int argc, char** argv)
|
||||
|
||||
init();
|
||||
glutKeyboardFunc(keyboard);
|
||||
|
||||
//to sprawia, że obiekty ukryte przed kamerą nie są renderowane
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
// glFrontFace(GL_CW);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
//glCullFace(GL_BACK);
|
||||
//glFrontFace(GL_CW);
|
||||
|
||||
glutDisplayFunc(renderScene);
|
||||
glutIdleFunc(idle);
|
||||
|
Loading…
Reference in New Issue
Block a user