Back to basic - Just a backpack rendering
This commit is contained in:
parent
3acc8525b0
commit
8890b4d973
@ -12,64 +12,59 @@ void main(){
|
|||||||
// Inversion filter
|
// Inversion filter
|
||||||
//FragColor = vec4( vec3 (1.0 - texture(screenTexure, TexCoords) ), 1.0) ;
|
//FragColor = vec4( vec3 (1.0 - texture(screenTexure, TexCoords) ), 1.0) ;
|
||||||
|
|
||||||
|
// Simple Grayscale
|
||||||
//grayscale
|
//FragColor = texture(screenTexure, TexCoords);
|
||||||
/*
|
//float average = (FragColor.r + FragColor.g + FragColor.b) / 3.0;
|
||||||
FragColor = texture(screenTexure, TexCoords);
|
//FragColor = vec4(average, average, average, 1.0);
|
||||||
float average = (FragColor.r + FragColor.g + FragColor.b) / 3.0;
|
|
||||||
FragColor = vec4(average, average, average, 1.0);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// physically accurate grayscale
|
// physically accurate grayscale
|
||||||
/* FragColor = texture(screenTexure, TexCoords);
|
//FragColor = texture(screenTexure, TexCoords);
|
||||||
float average = 0.2126 * FragColor.r + 0.7152 * FragColor.g + 0.0722 * FragColor.b;
|
//float average = 0.2126 * FragColor.r + 0.7152 * FragColor.g + 0.0722 * FragColor.b;
|
||||||
FragColor = vec4(average,average,average, 1.0);*/
|
//FragColor = vec4(average,average,average, 1.0);*/
|
||||||
|
|
||||||
vec2 offset[9] = vec2[] (
|
vec2 offset[9] = vec2[] (
|
||||||
vec2(-offset, offset), // top-left
|
vec2(-offset, offset), // top-left
|
||||||
vec2(0.0f, offset), // top-center
|
vec2(0.0f, offset), // top-center
|
||||||
vec2(offset, offset), // top-right
|
vec2(offset, offset), // top-right
|
||||||
vec2(-offset, 0.0f), // center-left
|
vec2(-offset, 0.0f), // center-left
|
||||||
vec2(0.0f, 0.0f), // center-center
|
vec2(0.0f, 0.0f), // center-center
|
||||||
vec2(offset, 0.0f), // center-right
|
vec2(offset, 0.0f), // center-right
|
||||||
vec2(-offset, -offset), // bottom-left
|
vec2(-offset, -offset), // bottom-left
|
||||||
vec2(0.0f, -offset), // bottom-center
|
vec2(0.0f, -offset), // bottom-center
|
||||||
vec2(offset, -offset) // bottom-right
|
vec2(offset, -offset) // bottom-right
|
||||||
);
|
);
|
||||||
|
|
||||||
// sharpen
|
// sharpen
|
||||||
/*float kernel[9] = float[](
|
float sharpen_kernel[9] = float[](
|
||||||
-1, -1, -1,
|
-1, -1, -1,
|
||||||
-1, 9, -1,
|
-1, 9, -1,
|
||||||
-1, -1, -1
|
-1, -1, -1
|
||||||
);*/
|
);
|
||||||
|
|
||||||
// blur
|
// blur
|
||||||
/* float kernel[9] = float[](
|
float blur_kernel[9] = float[](
|
||||||
1.0 /16, 2.0 /16, 1.0 /16,
|
1.0 /16, 2.0 /16, 1.0 /16,
|
||||||
2.0 /16, 4.0 /16, 2.0 /16,
|
2.0 /16, 4.0 /16, 2.0 /16,
|
||||||
1.0 /16, 2.0 /16, 1.0 /16
|
1.0 /16, 2.0 /16, 1.0 /16
|
||||||
);*/
|
);
|
||||||
|
|
||||||
// Edge-detection
|
// Edge-detection
|
||||||
/* float kernel[9] = float[] (
|
float edgeDetection_kernel[9] = float[] (
|
||||||
1, 1, 1,
|
1, 1, 1,
|
||||||
1, -8, 1,
|
1, -8, 1,
|
||||||
1, 1, 1
|
1, 1, 1
|
||||||
);
|
);
|
||||||
|
|
||||||
vec3 sampleTex[9];
|
//vec3 sampleTex[9];
|
||||||
for (int i= 0; i < 9; i++) {
|
//for (int i= 0; i < 9; i++) {
|
||||||
sampleTex[i] = vec3(texture(screenTexure, TexCoords.st + offset[i]));
|
// sampleTex[i] = vec3(texture(screenTexure, TexCoords.st + offset[i]));
|
||||||
}
|
//}
|
||||||
|
|
||||||
vec3 col = vec3(0.0);
|
|
||||||
for (int i = 0; i < 9; i++) {
|
|
||||||
col += sampleTex[i] * kernel[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
FragColor = vec4(col, 1.0);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
//vec3 col = vec3(0.0);
|
||||||
|
//for (int i = 0; i < 9; i++) {
|
||||||
|
// col += sampleTex[i] * kernel[i];
|
||||||
|
//}
|
||||||
|
|
||||||
|
//FragColor = vec4(col, 1.0);
|
||||||
|
|
||||||
}
|
}
|
@ -2,7 +2,6 @@
|
|||||||
layout (location = 0) in vec2 aPos;
|
layout (location = 0) in vec2 aPos;
|
||||||
layout (location = 1) in vec2 aTexCoords;
|
layout (location = 1) in vec2 aTexCoords;
|
||||||
|
|
||||||
|
|
||||||
out vec2 TexCoords;
|
out vec2 TexCoords;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
@ -60,4 +60,3 @@ project "LearnOpenGL"
|
|||||||
filter "configurations:Release"
|
filter "configurations:Release"
|
||||||
defines{"NDEBUG"}
|
defines{"NDEBUG"}
|
||||||
optimize "On"
|
optimize "On"
|
||||||
|
|
||||||
|
9
src/Primitives/Material.h
Normal file
9
src/Primitives/Material.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
glm::vec3 ambient;
|
||||||
|
glm::vec3 diffuse;
|
||||||
|
glm::vec3 specular;
|
||||||
|
float shininess;
|
||||||
|
};
|
14
src/Primitives/Scene.h
Normal file
14
src/Primitives/Scene.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include "../model.h"
|
||||||
|
#include "camera.h"
|
||||||
|
|
||||||
|
class Scene {
|
||||||
|
public:
|
||||||
|
|
||||||
|
Camera cameras;
|
||||||
|
std::vector <Model> entities;
|
||||||
|
// std::vector<Material> materials;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
@ -1,7 +1,7 @@
|
|||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
|
|
||||||
Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|
||||||
{
|
void Shader::Load(const char* vertexPath, const char* fragmentPath) {
|
||||||
// retrieve the vertex / fragment source code from filepath
|
// retrieve the vertex / fragment source code from filepath
|
||||||
std::string vertexCode;
|
std::string vertexCode;
|
||||||
std::string fragmentCode;
|
std::string fragmentCode;
|
||||||
@ -11,15 +11,15 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|||||||
vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
|
||||||
try{
|
try {
|
||||||
|
|
||||||
std::cout << "Opening VertexShader.. " << vertextPath << std::endl;
|
std::cout << "Opening VertexShader.. " << vertexPath << std::endl;
|
||||||
vShaderFile.open(vertextPath);
|
vShaderFile.open(vertexPath);
|
||||||
|
|
||||||
std::cout << "Opening FragmentShader.. " << fragmentPath << std::endl;
|
std::cout << "Opening FragmentShader.. " << fragmentPath << std::endl;
|
||||||
fShaderFile.open(fragmentPath);
|
fShaderFile.open(fragmentPath);
|
||||||
|
|
||||||
std::stringstream vShaderStream,fShaderStream;
|
std::stringstream vShaderStream, fShaderStream;
|
||||||
|
|
||||||
vShaderStream << vShaderFile.rdbuf();
|
vShaderStream << vShaderFile.rdbuf();
|
||||||
fShaderStream << fShaderFile.rdbuf();
|
fShaderStream << fShaderFile.rdbuf();
|
||||||
@ -31,11 +31,11 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|||||||
|
|
||||||
vShaderFile.close();
|
vShaderFile.close();
|
||||||
fShaderFile.close();
|
fShaderFile.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(std::ifstream::failure e){
|
catch (std::ifstream::failure e) {
|
||||||
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
|
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
|
||||||
std::cout << e.what() << "| IO error code: " << e.code() << std::endl ;
|
std::cout << e.what() << "| IO error code: " << e.code() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* vShaderCode = vertexCode.c_str();
|
const char* vShaderCode = vertexCode.c_str();
|
||||||
@ -53,8 +53,8 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|||||||
glCompileShader(vertex);
|
glCompileShader(vertex);
|
||||||
|
|
||||||
// print any compile errors if there are any
|
// print any compile errors if there are any
|
||||||
glGetShaderiv(vertex,GL_COMPILE_STATUS, &success);
|
glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);
|
||||||
if(!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
|
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
|
||||||
std::cout << "ERROR::SHADER:::VERTEX::COMPILATION_FAILED" << std::endl << infoLog << std::endl;
|
std::cout << "ERROR::SHADER:::VERTEX::COMPILATION_FAILED" << std::endl << infoLog << std::endl;
|
||||||
@ -67,7 +67,7 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|||||||
glCompileShader(fragment);
|
glCompileShader(fragment);
|
||||||
|
|
||||||
glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);
|
glGetShaderiv(fragment, GL_COMPILE_STATUS, &success);
|
||||||
if(!success){
|
if (!success) {
|
||||||
glGetShaderInfoLog(fragment, 512, NULL, infoLog);
|
glGetShaderInfoLog(fragment, 512, NULL, infoLog);
|
||||||
std::cout << "ERROR::SHADER:::VERTEX::COMPILATION_FAILED" << std::endl << infoLog << std::endl;
|
std::cout << "ERROR::SHADER:::VERTEX::COMPILATION_FAILED" << std::endl << infoLog << std::endl;
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|||||||
glLinkProgram(ID);
|
glLinkProgram(ID);
|
||||||
|
|
||||||
glGetProgramiv(ID, GL_LINK_STATUS, &success);
|
glGetProgramiv(ID, GL_LINK_STATUS, &success);
|
||||||
if(!success){
|
if (!success) {
|
||||||
glGetProgramInfoLog(ID, 512, NULL, infoLog);
|
glGetProgramInfoLog(ID, 512, NULL, infoLog);
|
||||||
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED" << std::endl << infoLog << std::endl;
|
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED" << std::endl << infoLog << std::endl;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,6 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|||||||
glDeleteShader(vertex);
|
glDeleteShader(vertex);
|
||||||
glDeleteShader(fragment);
|
glDeleteShader(fragment);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::use(){
|
void Shader::use(){
|
||||||
|
@ -13,8 +13,8 @@ class Shader
|
|||||||
unsigned int ID;// Program ID
|
unsigned int ID;// Program ID
|
||||||
|
|
||||||
// Read and build the shader upon construction
|
// Read and build the shader upon construction
|
||||||
Shader(const char* vertexPath, const char* fragmentPath);
|
Shader() = default;
|
||||||
|
void Load(const char* vertexPath, const char* fragmentPath);
|
||||||
// Activate the shader
|
// Activate the shader
|
||||||
void use();
|
void use();
|
||||||
|
|
||||||
|
@ -1,84 +0,0 @@
|
|||||||
#include "OutlinePass.h"
|
|
||||||
#include "Renderer.h"
|
|
||||||
#include "../../CheckErrors.h"
|
|
||||||
|
|
||||||
OutlinePass::OutlinePass(Model& sceneObject, glm::mat4& model, glm::mat4& projection, Camera& camera)
|
|
||||||
: RenderPass("Renderpass - Outline", "../Shaders/shader.vs", "../Shaders/outlineshader.fs" ) , m_model(sceneObject), camera(camera), projection(projection), model(model)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void OutlinePass::Create() {
|
|
||||||
// Framebuffer outline effect
|
|
||||||
std::cout << "Create Framebuffer" << std::endl;
|
|
||||||
|
|
||||||
m_outlineFrameBuffer = new FrameBuffer();
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
m_outlineFrameBuffer->Bind();
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
// Create a texture attachment (colour attachment)
|
|
||||||
std::cout << "Create Texture" << std::endl;
|
|
||||||
m_colourTexture = CreateTexture(800, 600);
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
// attach texture to the frame buffer as a colour attachment
|
|
||||||
m_outlineFrameBuffer->Attach(*m_colourTexture);
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
// Add depth buffer attachment
|
|
||||||
std::cout << "Create RenderBuffer" << std::endl;
|
|
||||||
m_outlineRenderBuffer = new RenderBuffer();
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
m_outlineRenderBuffer->Bind();
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
m_outlineRenderBuffer->UseDepthAndStencil();
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
m_outlineRenderBuffer->Unbind();
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
// attach depth buffer to our framebuffer
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_outlineRenderBuffer->id);
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
m_outlineFrameBuffer->Unbind();
|
|
||||||
glCheckError();
|
|
||||||
|
|
||||||
std::cout << "Success!" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
OutlinePass::~OutlinePass(){
|
|
||||||
delete m_colourTexture;
|
|
||||||
delete m_outlineRenderBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OutlinePass::Render()
|
|
||||||
{
|
|
||||||
std::cout << "Start outline render" << std::endl;
|
|
||||||
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
|
||||||
glStencilMask(0x00);
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
m_shader.use();
|
|
||||||
m_shader.setMat4("model", model);
|
|
||||||
m_shader.setMat4("view", camera.GetViewMatrix());
|
|
||||||
m_shader.setMat4("projection", projection);
|
|
||||||
m_shader.setVec3("outlineColor", glm::vec3(0.28, 0.10, 0.26));
|
|
||||||
|
|
||||||
model = glm::scale(model, glm::vec3(1.05f,1.05f, 1.05f));
|
|
||||||
m_shader.setMat4("model", model);
|
|
||||||
|
|
||||||
std::cout << "Drawing model" << std::endl;
|
|
||||||
m_model.Draw(m_shader);
|
|
||||||
|
|
||||||
|
|
||||||
glStencilFunc(GL_ALWAYS, 1, 0xff);
|
|
||||||
glStencilMask(0xFF);
|
|
||||||
|
|
||||||
std::cout << "Finished outline render" << std::endl;
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include "RenderPass.h"
|
|
||||||
#include "FrameBuffer.h"
|
|
||||||
#include "RenderBuffer.h"
|
|
||||||
#include "../model.h"
|
|
||||||
#include "../Primitives/texture.h"
|
|
||||||
#include "../Primitives/camera.h"
|
|
||||||
|
|
||||||
class OutlinePass : RenderPass {
|
|
||||||
|
|
||||||
public:
|
|
||||||
void Render() override;
|
|
||||||
|
|
||||||
OutlinePass (Model& sceneObject, glm::mat4& model , glm::mat4& projection, Camera& camera) ;
|
|
||||||
void Create();
|
|
||||||
~OutlinePass();
|
|
||||||
|
|
||||||
private:
|
|
||||||
FrameBuffer* m_outlineFrameBuffer;
|
|
||||||
RenderBuffer* m_outlineRenderBuffer;
|
|
||||||
Texture* m_colourTexture;
|
|
||||||
|
|
||||||
glm::mat4 model;
|
|
||||||
glm::mat4 projection;
|
|
||||||
|
|
||||||
Model& m_model;
|
|
||||||
Camera& camera;
|
|
||||||
|
|
||||||
};
|
|
@ -1,7 +1,7 @@
|
|||||||
#include "RenderBuffer.h"
|
#include "RenderBuffer.h"
|
||||||
|
|
||||||
void RenderBuffer::UseDepthAndStencil (){
|
void RenderBuffer::UseDepthAndStencil (int width, int height){
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600); /// NOTE: should be part of creating but kept seperate for now!
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); /// NOTE: should be part of creating but kept seperate for now!
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderBuffer::Bind()
|
void RenderBuffer::Bind()
|
||||||
|
@ -10,7 +10,7 @@ public:
|
|||||||
void Bind();
|
void Bind();
|
||||||
void Unbind();
|
void Unbind();
|
||||||
|
|
||||||
void UseDepthAndStencil();
|
void UseDepthAndStencil(int width, int height);
|
||||||
|
|
||||||
RenderBuffer();
|
RenderBuffer();
|
||||||
~RenderBuffer();
|
~RenderBuffer();
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include "../Primitives/shader.h"
|
|
||||||
|
|
||||||
class RenderPass {
|
|
||||||
public :
|
|
||||||
virtual void Render() = 0;
|
|
||||||
|
|
||||||
RenderPass(const std::string& name,const std::string& VertexShaderFile, const std::string& FragmentShaderFile) : m_shader(VertexShaderFile.c_str(), FragmentShaderFile.c_str())
|
|
||||||
{
|
|
||||||
std::cout << "Created " << name << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
~RenderPass(){}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Shader m_shader;
|
|
||||||
|
|
||||||
};
|
|
@ -9,60 +9,131 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include "../Primitives/Scene.h"
|
||||||
void Renderer::Setup()
|
void Renderer::Setup()
|
||||||
{
|
{
|
||||||
|
shader.Load("../Shaders/Framebuffers.vs", "../Shaders/Framebuffers.fs");
|
||||||
|
|
||||||
|
// Create ScreenVAO
|
||||||
|
glGenVertexArrays(1, &ScreenVAO);
|
||||||
|
glBindVertexArray(ScreenVAO);
|
||||||
|
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, ScreenVertices.size() * sizeof(float), &ScreenVertices[0], GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
// Enable features
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_STENCIL_TEST);
|
||||||
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||||
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
|
||||||
|
}
|
||||||
|
void Renderer::resize(int width, int height ) {
|
||||||
|
framebuffer = FrameBuffer();
|
||||||
|
|
||||||
framebuffer.Bind();
|
framebuffer.Bind();
|
||||||
|
|
||||||
|
ColourBuffer = CreateTexture(width, height);
|
||||||
ColourBuffer = CreateTexture(800,600);
|
|
||||||
|
|
||||||
|
|
||||||
framebuffer.Attach(*ColourBuffer);
|
framebuffer.Attach(*ColourBuffer);
|
||||||
|
|
||||||
|
renderbufferObject = RenderBuffer();
|
||||||
|
|
||||||
renderbufferObject.Bind();
|
renderbufferObject.Bind();
|
||||||
|
|
||||||
renderbufferObject.UseDepthAndStencil();
|
renderbufferObject.UseDepthAndStencil(width, height);
|
||||||
|
|
||||||
renderbufferObject.Unbind();
|
|
||||||
|
|
||||||
|
|
||||||
framebuffer.Attach(renderbufferObject);
|
framebuffer.Attach(renderbufferObject);
|
||||||
|
|
||||||
if(framebuffer.IsComplete() == false ){
|
if (framebuffer.IsComplete() == false) {
|
||||||
std::cout << "ERROR::FRAMEBUFFER::Framebuffer is not complete! " << std::endl;
|
std::cout << "ERROR::FRAMEBUFFER::Framebuffer is not complete! " << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderbufferObject.Unbind();
|
||||||
|
|
||||||
framebuffer.Unbind();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Render( )
|
|
||||||
|
void Renderer::Render(Scene& scene)
|
||||||
{
|
{
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
||||||
|
glm::mat4 projection = glm::perspective(glm::radians(scene.cameras.Zoom), (float)800 / (float)600, 0.1f, 100.0f);
|
||||||
|
auto view = scene.cameras.GetViewMatrix();
|
||||||
|
auto model = glm::mat4(1.0f);
|
||||||
|
|
||||||
// Recalculate the Camera's view matrix
|
|
||||||
view = camera.GetViewMatrix();
|
|
||||||
// Reset the model matrix to an identity matrix
|
|
||||||
model = glm::mat4(1.0f);
|
|
||||||
|
|
||||||
framebuffer.Bind();
|
|
||||||
|
|
||||||
// 1. Skybox pass
|
// 1. Skybox pass
|
||||||
skyboxpass.Render();
|
/*
|
||||||
|
Shader cubemap;
|
||||||
|
cubemap.Load("../Shaders/skybox.vs", "../Shaders/Cubemap.fs");
|
||||||
|
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
|
cubemap.use();
|
||||||
|
|
||||||
|
cubemap.setMat4("projection", projection);
|
||||||
|
auto centeredView = glm::mat4(glm::mat3(scene.cameras.GetViewMatrix()));
|
||||||
|
cubemap.setMat4("view", centeredView);
|
||||||
|
|
||||||
|
skybox.Bind();
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
|
||||||
|
skybox.Unbind();
|
||||||
|
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// 2. Scene pass
|
// 2. Scene pass
|
||||||
scenepass.Render();
|
Shader blinnPhong;
|
||||||
|
blinnPhong.Load("../Shaders/shader.vs", "../Shaders/shader.fs");
|
||||||
|
|
||||||
|
blinnPhong.use();
|
||||||
|
blinnPhong.setVec3("cameraPos", scene.cameras.Position);
|
||||||
|
|
||||||
|
/*
|
||||||
|
glActiveTexture(GL_TEXTURE11);
|
||||||
|
m_skybox.Bind(); // Segmentation Fault HERE!!
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
blinnPhong.setInt("skybox", 11);
|
||||||
|
|
||||||
|
blinnPhong.setMat4("model", model);
|
||||||
|
blinnPhong.setMat4("view", view);
|
||||||
|
blinnPhong.setMat4("projection", projection);
|
||||||
|
|
||||||
|
for (auto entity : scene.entities) {
|
||||||
|
entity.Draw(blinnPhong);
|
||||||
|
}
|
||||||
|
|
||||||
|
// m_skybox.Unbind();
|
||||||
|
|
||||||
// 3. outline pass
|
// 3. outline pass
|
||||||
|
//Shader OutlineShader;
|
||||||
outlinepass.Render();
|
//OutlineShader.Load("../Shaders/shader.vs", "../Shaders/outlineshader.fs");
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
*/
|
||||||
|
|
||||||
// 4. draw result to screen
|
// 4. draw result to screen
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
/*glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
@ -70,8 +141,8 @@ void Renderer::Render( )
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
||||||
m_shader.use();
|
shader.use();
|
||||||
m_shader.setInt("screenTexture",0);
|
shader.setInt("screenTexture",0);
|
||||||
glBindVertexArray(ScreenVAO);
|
glBindVertexArray(ScreenVAO);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, ColourBuffer->id);
|
glBindTexture(GL_TEXTURE_2D, ColourBuffer->id);
|
||||||
@ -83,57 +154,20 @@ void Renderer::Render( )
|
|||||||
glStencilMask(0xFF);
|
glStencilMask(0xFF);
|
||||||
glStencilFunc(GL_ALWAYS, 1, 0xFF);
|
glStencilFunc(GL_ALWAYS, 1, 0xFF);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::Renderer(Camera& camera, Model& scene) :
|
void Renderer::Shutdown() {
|
||||||
camera(camera),
|
|
||||||
renderbufferObject(),
|
|
||||||
framebuffer(),
|
|
||||||
skybox(),
|
|
||||||
skyboxpass(skybox, camera, projection),
|
|
||||||
scenepass(skybox, scene,camera,projection, model),
|
|
||||||
outlinepass(scene, model, projection, camera),
|
|
||||||
m_shader("../Shaders/Framebuffers.vs", "../Shaders/Framebuffers.fs")
|
|
||||||
{
|
|
||||||
|
|
||||||
|
framebuffer.Unbind();
|
||||||
|
}
|
||||||
|
|
||||||
outlinepass.Create();
|
Renderer::Renderer() {
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> faces = {
|
|
||||||
"../Textures/skybox/right.jpg",
|
|
||||||
"../Textures/skybox/left.jpg",
|
|
||||||
"../Textures/skybox/top.jpg",
|
|
||||||
"../Textures/skybox/bottom.jpg",
|
|
||||||
"../Textures/skybox/front.jpg",
|
|
||||||
"../Textures/skybox/back.jpg"
|
|
||||||
};
|
|
||||||
skybox.loadCubeTextures(faces);
|
|
||||||
|
|
||||||
|
|
||||||
// auto outlinepass = OutlinePass(scene , model, projection, camera);
|
// auto outlinepass = OutlinePass(scene , model, projection, camera);
|
||||||
// Create ScreenVAO
|
|
||||||
glGenVertexArrays(1, &ScreenVAO);
|
|
||||||
glBindVertexArray(ScreenVAO);
|
|
||||||
|
|
||||||
glGenBuffers(1, &VBO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, ScreenVertices.size() * sizeof(float), &ScreenVertices[0], GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0,2, GL_FLOAT,GL_FALSE, 4 * sizeof(float),(void*) 0 );
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(1,2,GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2*sizeof(float)));
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
// Enable features
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_STENCIL_TEST);
|
|
||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
|
||||||
glEnable(GL_MULTISAMPLE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,39 +5,26 @@
|
|||||||
#include "../Primitives/shader.h"
|
#include "../Primitives/shader.h"
|
||||||
#include "FrameBuffer.h"
|
#include "FrameBuffer.h"
|
||||||
#include "RenderBuffer.h"
|
#include "RenderBuffer.h"
|
||||||
#include "ScenePass.h"
|
#include "../Primitives/Scene.h"
|
||||||
#include "OutlinePass.h"
|
|
||||||
#include "SkyboxPass.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Render();
|
Renderer();
|
||||||
void Setup();
|
|
||||||
|
|
||||||
Renderer(Camera& camera,Model& scene);
|
|
||||||
~Renderer();
|
~Renderer();
|
||||||
|
void Setup();
|
||||||
|
void resize(int width, int height);
|
||||||
private:
|
void Render(Scene& scene);
|
||||||
ScenePass scenepass;
|
void Shutdown();
|
||||||
SkyboxPass skyboxpass;
|
|
||||||
OutlinePass outlinepass;
|
|
||||||
|
|
||||||
Camera& camera;
|
|
||||||
|
private:
|
||||||
GLuint ScreenVAO, VBO;
|
GLuint ScreenVAO, VBO;
|
||||||
FrameBuffer framebuffer;
|
FrameBuffer framebuffer;
|
||||||
RenderBuffer renderbufferObject;
|
RenderBuffer renderbufferObject;
|
||||||
Texture* ColourBuffer;
|
Texture* ColourBuffer;
|
||||||
Skybox skybox;
|
Shader shader;
|
||||||
|
|
||||||
Shader m_shader;
|
|
||||||
|
|
||||||
glm::mat4 model = glm::mat4(1.0f);
|
|
||||||
glm::mat4 view;
|
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(camera.Zoom), (float)800 / (float)600, 0.1f, 100.0f);
|
|
||||||
|
|
||||||
glm::vec3 lightpos = glm::vec3(-0.2f, -1.0f, -0.3f);
|
glm::vec3 lightpos = glm::vec3(-0.2f, -1.0f, -0.3f);
|
||||||
|
|
||||||
std::vector<float> ScreenVertices = {
|
std::vector<float> ScreenVertices = {
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
#include "ScenePass.h"
|
|
||||||
|
|
||||||
void ScenePass::Render()
|
|
||||||
{
|
|
||||||
m_shader.use();
|
|
||||||
m_shader.setVec3("cameraPos", camera.Position);
|
|
||||||
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE11);
|
|
||||||
m_skybox.Bind(); // Segmentation Fault HERE!!
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
m_shader.setInt("skybox",11);
|
|
||||||
|
|
||||||
|
|
||||||
m_shader.setMat4("model", model);
|
|
||||||
m_shader.setMat4("view", camera.GetViewMatrix());
|
|
||||||
m_shader.setMat4("projection", projection);
|
|
||||||
|
|
||||||
|
|
||||||
m_scene.Draw(m_shader);
|
|
||||||
|
|
||||||
|
|
||||||
m_skybox.Unbind();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScenePass::SetSkybox(Skybox& skybox)
|
|
||||||
{
|
|
||||||
m_skybox = skybox;
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "RenderPass.h"
|
|
||||||
#include "../Primitives/Skybox.h"
|
|
||||||
#include "../Primitives/shader.h"
|
|
||||||
#include "../Primitives/camera.h"
|
|
||||||
#include "../model.h"
|
|
||||||
|
|
||||||
class ScenePass : public RenderPass {
|
|
||||||
|
|
||||||
public:
|
|
||||||
void Render() override;
|
|
||||||
|
|
||||||
ScenePass(Skybox& skybox, Model& scene, Camera& camera, glm::mat4 projection , glm::mat4 model)
|
|
||||||
: RenderPass("RenderPass - Scene", "../Shaders/shader.vs", "../Shaders/shader.fs" ),
|
|
||||||
m_scene(scene), camera(camera), projection(projection), model(model), m_skybox(skybox)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
~ScenePass() = default;
|
|
||||||
|
|
||||||
void SetSkybox(Skybox& skybox);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Skybox& m_skybox;
|
|
||||||
Model& m_scene;
|
|
||||||
Camera& camera;
|
|
||||||
|
|
||||||
glm::mat4 projection;
|
|
||||||
glm::mat4 model;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
@ -1,32 +0,0 @@
|
|||||||
#include "SkyboxPass.h"
|
|
||||||
SkyboxPass::SkyboxPass(Skybox& skybox, Camera& camera, glm::mat4& projection) : RenderPass("Render Pass - Skybox", "../Shaders/skybox.vs", "../Shaders/Cubemap.fs"),
|
|
||||||
skybox(skybox),
|
|
||||||
camera(camera),
|
|
||||||
projection(projection)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SkyboxPass::Render()
|
|
||||||
{
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
|
|
||||||
m_shader.use();
|
|
||||||
|
|
||||||
m_shader.setMat4("projection", projection);
|
|
||||||
glm::mat4 centeredView = glm::mat4(glm::mat3(camera.GetViewMatrix()));
|
|
||||||
m_shader.setMat4("view", centeredView);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
skybox.Bind();
|
|
||||||
|
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
|
||||||
|
|
||||||
skybox.Unbind();
|
|
||||||
|
|
||||||
glDepthMask(GL_TRUE);
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "RenderPass.h"
|
|
||||||
#include "../Primitives/Skybox.h"
|
|
||||||
#include "../Primitives/shader.h"
|
|
||||||
#include "../Primitives/camera.h"
|
|
||||||
|
|
||||||
class SkyboxPass : public RenderPass {
|
|
||||||
public:
|
|
||||||
void Render() override;
|
|
||||||
|
|
||||||
SkyboxPass( Skybox& skybox, Camera& camera, glm::mat4& projection);
|
|
||||||
~SkyboxPass() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Skybox& skybox;
|
|
||||||
Camera& camera;
|
|
||||||
glm::mat4& projection;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
29
src/main.cpp
29
src/main.cpp
@ -14,14 +14,14 @@
|
|||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "Primitives/Scene.h"
|
||||||
|
|
||||||
|
|
||||||
void processInput( GLFWwindow* window);
|
void processInput( GLFWwindow* window);
|
||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
||||||
|
const int WIDTH = 800, HEIGHT = 600;
|
||||||
float deltaTime = 0.0f; ; // Time between current frame and last frame
|
float deltaTime = 0.0f; ; // Time between current frame and last frame
|
||||||
float lastFrame = 0.0f; // Time of last frame
|
float lastFrame = 0.0f; // Time of last frame
|
||||||
bool firstMouse = true;
|
bool firstMouse = true;
|
||||||
@ -35,7 +35,7 @@ public:
|
|||||||
void Run () override
|
void Run () override
|
||||||
{
|
{
|
||||||
// Create a window
|
// Create a window
|
||||||
Window window(800,600, "LearnOpenGL");
|
Window window(WIDTH,HEIGHT, "LearnOpenGL");
|
||||||
|
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
@ -48,10 +48,27 @@ public:
|
|||||||
ImGui_ImplOpenGL3_Init("#version 460");
|
ImGui_ImplOpenGL3_Init("#version 460");
|
||||||
|
|
||||||
stbi_set_flip_vertically_on_load(true);
|
stbi_set_flip_vertically_on_load(true);
|
||||||
|
|
||||||
Model backpack("../Models/backpack.obj");
|
Model backpack("../Models/backpack.obj");
|
||||||
|
|
||||||
Renderer renderer = Renderer(camera, backpack);
|
Scene scene;
|
||||||
|
scene.entities.push_back(backpack);
|
||||||
|
|
||||||
|
scene.cameras = camera;
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> faces = {
|
||||||
|
"../Textures/skybox/right.jpg",
|
||||||
|
"../Textures/skybox/left.jpg",
|
||||||
|
"../Textures/skybox/top.jpg",
|
||||||
|
"../Textures/skybox/bottom.jpg",
|
||||||
|
"../Textures/skybox/front.jpg",
|
||||||
|
"../Textures/skybox/back.jpg"
|
||||||
|
};
|
||||||
|
Skybox skybox = Skybox();
|
||||||
|
skybox.loadCubeTextures(faces);
|
||||||
|
|
||||||
|
Renderer renderer = Renderer();
|
||||||
|
renderer.resize(WIDTH, HEIGHT);
|
||||||
renderer.Setup();
|
renderer.Setup();
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +82,7 @@ public:
|
|||||||
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
processInput(window.ptr());
|
processInput(window.ptr());
|
||||||
renderer.Render();
|
renderer.Render(scene);
|
||||||
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
Loading…
Reference in New Issue
Block a user