Some groundwork for cubemaps.
This commit is contained in:
+1
-1
Submodule assets updated: 1e7adc749e...ba8e04f12b
@@ -0,0 +1,26 @@
|
||||
#ifndef CubeMapPass_h__
|
||||
#define CubeMapPass_h__
|
||||
|
||||
#include "IRenderer.h"
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
class CubeMapPass
|
||||
{
|
||||
public:
|
||||
CubeMapPass(IRenderer* renderer);
|
||||
~CubeMapPass() { }
|
||||
|
||||
void LoadTextures();
|
||||
void FillCubeMap(glm::vec3 originPosition);
|
||||
void GenerateCubeMapTexture();
|
||||
|
||||
//GLuint CubeMapTexture() const { return m_CubeMapTexture; }
|
||||
GLuint m_CubeMapTexture;
|
||||
|
||||
private:
|
||||
IRenderer* m_Renderer;
|
||||
|
||||
std::vector<Texture*> m_CubeMapTestTextures;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "IRenderer.h"
|
||||
#include "DrawFinalPassState.h"
|
||||
#include "LightCullingPass.h"
|
||||
#include "CubeMapPass.h"
|
||||
#include "FrameBuffer.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "Util/UnorderedMapVec2.h"
|
||||
@@ -13,7 +14,7 @@
|
||||
class DrawFinalPass
|
||||
{
|
||||
public:
|
||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass);
|
||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass);
|
||||
~DrawFinalPass() { }
|
||||
void InitializeTextures();
|
||||
void InitializeFrameBuffers();
|
||||
@@ -62,12 +63,14 @@ private:
|
||||
GLuint m_SceneTextureLowRes;
|
||||
GLuint m_DepthBuffer;
|
||||
GLuint m_DepthBufferLowRes;
|
||||
GLuint m_CubeMapTexture;
|
||||
|
||||
//maqke this component based i guess?
|
||||
GLuint m_ShieldPixelRate = 16;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
const LightCullingPass* m_LightCullingPass;
|
||||
const CubeMapPass* m_CubeMapPass;
|
||||
|
||||
ShaderProgram* m_ForwardPlusProgram;
|
||||
ShaderProgram* m_ExplosionEffectProgram;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "DrawBloomPass.h"
|
||||
#include "DrawColorCorrectionPass.h"
|
||||
#include "SSAOPass.h"
|
||||
#include "CubeMapPass.h"
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "ImGuiRenderPass.h"
|
||||
#include "Camera.h"
|
||||
@@ -74,6 +75,7 @@ private:
|
||||
DrawBloomPass* m_DrawBloomPass;
|
||||
DrawColorCorrectionPass* m_DrawColorCorrectionPass;
|
||||
SSAOPass* m_SSAOPass;
|
||||
CubeMapPass* m_CubeMapPass;
|
||||
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
void Bind(GLenum textureUnit = GL_TEXTURE0);
|
||||
|
||||
GLuint m_Texture = 0;
|
||||
unsigned char* Data = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ layout (binding = 1) uniform sampler2D DiffuseTexture;
|
||||
layout (binding = 2) uniform sampler2D NormalMapTexture;
|
||||
layout (binding = 3) uniform sampler2D SpecularMapTexture;
|
||||
layout (binding = 4) uniform sampler2D GlowMapTexture;
|
||||
layout (binding = 5) uniform samplerCube CubeMap;
|
||||
|
||||
#define TILE_SIZE 16
|
||||
|
||||
@@ -132,7 +133,9 @@ void main()
|
||||
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
|
||||
normal = normalize(normal);
|
||||
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
|
||||
vec4 viewVec = normalize(-position);
|
||||
vec4 viewVec = normalize(-position);
|
||||
vec3 R = reflect(-viewVec.xyz, normal.xyz);
|
||||
vec4 reflectionColor = texture(CubeMap, R);
|
||||
|
||||
vec2 tilePos;
|
||||
tilePos.x = int(gl_FragCoord.x/TILE_SIZE);
|
||||
@@ -171,7 +174,8 @@ void main()
|
||||
if(pos <= FillPercentage) {
|
||||
color_result += FillColor;
|
||||
}
|
||||
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
|
||||
//sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
|
||||
sceneColor = vec4(reflectionColor.xyz, 1);
|
||||
color_result += glowTexel*GlowIntensity;
|
||||
|
||||
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), clamp(color_result.a, 0, 1));
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "Rendering/CubeMapPass.h"
|
||||
|
||||
CubeMapPass::CubeMapPass(IRenderer* renderer)
|
||||
:m_Renderer(renderer)
|
||||
{
|
||||
LoadTextures();
|
||||
GenerateCubeMapTexture();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
void CubeMapPass::LoadTextures()
|
||||
{
|
||||
for (int i = 0; i < 6; i++){
|
||||
std::string str;
|
||||
str = "Textures/Test/CubeMap/CubeMapTest0" + std::to_string(i) + ".png";
|
||||
Texture* img = ResourceManager::Load<Texture>(str);
|
||||
m_CubeMapTestTextures.push_back(img);
|
||||
}
|
||||
}
|
||||
|
||||
void CubeMapPass::GenerateCubeMapTexture()
|
||||
{
|
||||
glGenTextures(1, &m_CubeMapTexture);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapTexture);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA32F, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_CubeMapTestTextures[i]->Data);
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
GLERROR("Generate Cubemap");
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ void DrawBloomPass::InitializeBuffers()
|
||||
|
||||
void DrawBloomPass::ClearBuffer()
|
||||
{
|
||||
GLERROR("PRE");
|
||||
m_GaussianFrameBuffer_horiz.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -60,6 +61,7 @@ void DrawBloomPass::ClearBuffer()
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_GaussianFrameBuffer_vert.Unbind();
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
void DrawBloomPass::Draw(GLuint texture)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "Rendering/DrawFinalPass.h"
|
||||
|
||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass)
|
||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass)
|
||||
: m_Renderer(renderer)
|
||||
, m_LightCullingPass(lightCullingPass)
|
||||
, m_CubeMapPass(cubeMapPass)
|
||||
{
|
||||
//TODO: Make sure that uniforms are not sent into shader if not needed.
|
||||
m_Renderer = renderer;
|
||||
m_LightCullingPass = lightCullingPass;
|
||||
m_ShieldPixelRate = 8;
|
||||
InitializeTextures();
|
||||
InitializeShaderPrograms();
|
||||
@@ -261,20 +262,35 @@ void DrawFinalPass::Draw(RenderScene& scene, GLuint SSAOTexture)
|
||||
|
||||
void DrawFinalPass::ClearBuffer()
|
||||
{
|
||||
GLERROR("PRE");
|
||||
m_FinalPassFrameBufferLowRes.Bind();
|
||||
GLERROR("Bind LowRes");
|
||||
|
||||
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_ShieldPixelRate, m_Renderer->GetViewportSize().Height/m_ShieldPixelRate);
|
||||
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
GLERROR("ViewPort,Scissor LowRes");
|
||||
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
GLERROR("1");
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
GLERROR("2");
|
||||
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
GLERROR("3");
|
||||
|
||||
m_FinalPassFrameBufferLowRes.Unbind();
|
||||
|
||||
GLERROR("prebind HighRes");
|
||||
m_FinalPassFrameBuffer.Bind();
|
||||
GLERROR("Bind HighRes");
|
||||
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
GLERROR("ViewPort,Scissor LowRes");
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_FinalPassFrameBuffer.Unbind();
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
|
||||
@@ -358,12 +374,15 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
case RawModel::MaterialType::SingleTextures:
|
||||
{
|
||||
if (explosionEffectJob->Model->IsSkinned()) {
|
||||
|
||||
m_ExplosionEffectSkinnedProgram->Bind();
|
||||
GLERROR("Bind ExplosionEffectSkinned program");
|
||||
//bind uniforms
|
||||
BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene);
|
||||
//bind textures
|
||||
BindExplosionTextures(explosionSkinnedHandle, explosionEffectJob);
|
||||
glActiveTexture(GL_TEXTURE5);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture);
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (explosionEffectJob->AnimationOffset.animation != nullptr) {
|
||||
frameBones = explosionEffectJob->Skeleton->GetFrameBones(explosionEffectJob->Animations, explosionEffectJob->AnimationOffset);
|
||||
@@ -378,6 +397,8 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
BindExplosionUniforms(explosionHandle, explosionEffectJob, scene);
|
||||
//bind textures
|
||||
BindExplosionTextures(explosionHandle, explosionEffectJob);
|
||||
glActiveTexture(GL_TEXTURE5);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -436,6 +457,8 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
BindModelUniforms(forwardSkinnedHandle, modelJob, scene);
|
||||
//bind textures
|
||||
BindModelTextures(forwardSkinnedHandle, modelJob);
|
||||
glActiveTexture(GL_TEXTURE5);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture);
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (modelJob->AnimationOffset.animation != nullptr) {
|
||||
frameBones = modelJob->Skeleton->GetFrameBones(modelJob->Animations, modelJob->AnimationOffset);
|
||||
@@ -451,6 +474,8 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
BindModelUniforms(forwardHandle, modelJob, scene);
|
||||
//bind textures
|
||||
BindModelTextures(forwardHandle, modelJob);
|
||||
glActiveTexture(GL_TEXTURE5);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, m_CubeMapPass->m_CubeMapTexture);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -809,6 +834,8 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<Model
|
||||
|
||||
void DrawFinalPass::BindExplosionTextures(GLuint shaderHandle, std::shared_ptr<ExplosionEffectJob>& job)
|
||||
{
|
||||
|
||||
|
||||
switch (job->Type) {
|
||||
case RawModel::MaterialType::SingleTextures:
|
||||
case RawModel::MaterialType::Basic:
|
||||
|
||||
@@ -64,6 +64,7 @@ void PickingPass::InitializeShaderPrograms()
|
||||
|
||||
void PickingPass::Draw(RenderScene& scene)
|
||||
{
|
||||
GLERROR("PRE");
|
||||
PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle());
|
||||
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
@@ -367,6 +368,7 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
|
||||
void PickingPass::ClearPicking()
|
||||
{
|
||||
GLERROR("PRE");
|
||||
m_PickingColorsToEntity.clear();
|
||||
m_EntityColors.clear();
|
||||
m_ColorCounter[0] = 0;
|
||||
@@ -376,6 +378,7 @@ void PickingPass::ClearPicking()
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_PickingBuffer.Unbind();
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
PickingPassState::PickingPassState(GLuint frameBuffer)
|
||||
{
|
||||
GLERROR("---2");
|
||||
GLERROR("PRE");
|
||||
BindFramebuffer(frameBuffer);
|
||||
GLERROR("---3");
|
||||
GLERROR("Bind Framebuffer");
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
Disable(GL_BLEND);
|
||||
@@ -13,6 +13,7 @@ PickingPassState::PickingPassState(GLuint frameBuffer)
|
||||
glm::vec4 clearColor = glm::vec4(0.f);
|
||||
//ClearColor(clearColor);
|
||||
//Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
PickingPassState::~PickingPassState()
|
||||
|
||||
@@ -30,6 +30,7 @@ void Renderer::glfwFrameBufferCallback(GLFWwindow* window, int width, int height
|
||||
currentRenderer->m_LightCullingPass->OnWindowResize();
|
||||
currentRenderer->m_PickingPass->OnWindowResize();
|
||||
currentRenderer->m_DrawBloomPass->OnWindowResize();
|
||||
//TODO: CubeMapPass->OnWindowResize //If needed
|
||||
}
|
||||
|
||||
void Renderer::InitializeWindow()
|
||||
@@ -88,9 +89,6 @@ void Renderer::InitializeShaders()
|
||||
//m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ExplosionEffect.frag.glsl")));
|
||||
//m_ExplosionEffectProgram->Compile();
|
||||
//m_ExplosionEffectProgram->Link();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Renderer::InputUpdate(double dt)
|
||||
@@ -108,6 +106,7 @@ void Renderer::Update(double dt)
|
||||
|
||||
void Renderer::Draw(RenderFrame& frame)
|
||||
{
|
||||
GLERROR("PRE");
|
||||
ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0SceneLowRes\0BloomLowRes\0Gaussian\0Picking\0Ambient Occlusion");
|
||||
|
||||
ImGui::SliderFloat("SSAO sample radius", &m_SSAO_Radius, 0.01f, 5.0f);
|
||||
@@ -117,6 +116,7 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
ImGui::SliderInt("SSAO Number of Samples", &m_SSAO_NumOfSamples, 2, 100);
|
||||
ImGui::SliderInt("SSAO Number of Turns", &m_SSAO_NumOfTurns, 0, 50);
|
||||
m_SSAOPass->Setting(m_SSAO_Radius, m_SSAO_Bias, m_SSAO_Contrast, m_SSAO_IntensityScale, m_SSAO_NumOfSamples, m_SSAO_NumOfTurns);
|
||||
GLERROR("SSAO Settings");
|
||||
//clear buffer 0
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -127,6 +127,7 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
m_DrawFinalPass->ClearBuffer();
|
||||
m_DrawBloomPass->ClearBuffer();
|
||||
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
|
||||
GLERROR("ClearBuffers");
|
||||
for (auto scene : frame.RenderScenes) {
|
||||
PerformanceTimer::StartTimer("Renderer-Depth");
|
||||
m_PickingPass->Draw(*scene);
|
||||
@@ -239,9 +240,10 @@ void Renderer::InitializeRenderPasses()
|
||||
{
|
||||
m_PickingPass = new PickingPass(this, m_EventBroker);
|
||||
m_LightCullingPass = new LightCullingPass(this);
|
||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass);
|
||||
m_CubeMapPass = new CubeMapPass(this);
|
||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass);
|
||||
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
|
||||
m_DrawBloomPass = new DrawBloomPass(this);
|
||||
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
|
||||
m_SSAOPass = new SSAOPass(this);
|
||||
m_SSAOPass = new SSAOPass(this);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ Texture::Texture(std::string path)
|
||||
|
||||
this->Width = img->Width;
|
||||
this->Height = img->Height;
|
||||
this->Data = img->Data;
|
||||
|
||||
GLint format;
|
||||
switch (img->Format) {
|
||||
@@ -28,6 +29,7 @@ Texture::Texture(std::string path)
|
||||
format = GL_RGBA;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Construct the OpenGL texture
|
||||
glGenTextures(1, &m_Texture);
|
||||
|
||||
Reference in New Issue
Block a user