mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 22:11:51 +00:00
fix noiseTexture deleting
This commit is contained in:
parent
68a01e3648
commit
89bedf9595
2 changed files with 40 additions and 29 deletions
|
|
@ -1,4 +1,7 @@
|
||||||
#include "PostProcessing.hpp"
|
#include "PostProcessing.hpp"
|
||||||
|
|
||||||
|
#include <GL/glew.h>
|
||||||
|
|
||||||
#include "Mesh.hpp"
|
#include "Mesh.hpp"
|
||||||
#include "Shader.hpp"
|
#include "Shader.hpp"
|
||||||
#include "GBuffer.hpp"
|
#include "GBuffer.hpp"
|
||||||
|
|
@ -10,15 +13,37 @@
|
||||||
#include "window/Camera.hpp"
|
#include "window/Camera.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <random>
|
|
||||||
|
|
||||||
// TODO: REFACTOR WHOLE RENDER ENGINE
|
// TODO: REFACTOR WHOLE RENDER ENGINE
|
||||||
|
|
||||||
using namespace advanced_pipeline;
|
using namespace advanced_pipeline;
|
||||||
|
|
||||||
|
static uint create_noise_texture() {
|
||||||
|
std::vector<glm::vec3> ssaoNoise;
|
||||||
|
for (unsigned int i = 0; i < 16; i++) {
|
||||||
|
glm::vec3 noise(
|
||||||
|
(rand() / static_cast<float>(RAND_MAX)) * 2.0 - 1.0,
|
||||||
|
(rand() / static_cast<float>(RAND_MAX)) * 2.0 - 1.0,
|
||||||
|
0.0f
|
||||||
|
);
|
||||||
|
ssaoNoise.push_back(noise);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint noiseTexture;
|
||||||
|
glGenTextures(1, &noiseTexture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, noiseTexture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 4, 4, 0, GL_RGB, GL_FLOAT, ssaoNoise.data());
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
return noiseTexture;
|
||||||
|
}
|
||||||
|
|
||||||
PostProcessing::PostProcessing(size_t effectSlotsCount)
|
PostProcessing::PostProcessing(size_t effectSlotsCount)
|
||||||
: effectSlots(effectSlotsCount) {
|
: effectSlots(effectSlotsCount) {
|
||||||
// Fullscreen quad mesh bulding
|
// Fullscreen quad mesh building
|
||||||
PostProcessingVertex meshData[] {
|
PostProcessingVertex meshData[] {
|
||||||
{{-1.0f, -1.0f}},
|
{{-1.0f, -1.0f}},
|
||||||
{{-1.0f, 1.0f}},
|
{{-1.0f, 1.0f}},
|
||||||
|
|
@ -29,27 +54,12 @@ PostProcessing::PostProcessing(size_t effectSlotsCount)
|
||||||
};
|
};
|
||||||
|
|
||||||
quadMesh = std::make_unique<Mesh<PostProcessingVertex>>(meshData, 6);
|
quadMesh = std::make_unique<Mesh<PostProcessingVertex>>(meshData, 6);
|
||||||
|
noiseTexture = create_noise_texture();
|
||||||
std::vector<glm::vec3> ssaoNoise;
|
|
||||||
for (unsigned int i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
glm::vec3 noise(
|
|
||||||
(rand() / static_cast<float>(RAND_MAX)) * 2.0 - 1.0,
|
|
||||||
(rand() / static_cast<float>(RAND_MAX)) * 2.0 - 1.0,
|
|
||||||
0.0f);
|
|
||||||
ssaoNoise.push_back(noise);
|
|
||||||
}
|
|
||||||
glGenTextures(1, &noiseTexture);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, noiseTexture);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 4, 4, 0, GL_RGB, GL_FLOAT, ssaoNoise.data());
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PostProcessing::~PostProcessing() = default;
|
PostProcessing::~PostProcessing() {
|
||||||
|
glDeleteTextures(1, &noiseTexture);
|
||||||
|
}
|
||||||
|
|
||||||
void PostProcessing::use(DrawContext& context, bool gbufferPipeline) {
|
void PostProcessing::use(DrawContext& context, bool gbufferPipeline) {
|
||||||
const auto& vp = context.getViewport();
|
const auto& vp = context.getViewport();
|
||||||
|
|
@ -105,8 +115,9 @@ void PostProcessing::configureEffect(
|
||||||
shader.uniform3f("u_cameraPos", camera.position);
|
shader.uniform3f("u_cameraPos", camera.position);
|
||||||
shader.uniform1f("u_timer", timer);
|
shader.uniform1f("u_timer", timer);
|
||||||
shader.uniformMatrix("u_projection", camera.getProjection());
|
shader.uniformMatrix("u_projection", camera.getProjection());
|
||||||
shader.uniformMatrix("u_view", camera.getView());
|
const auto view = camera.getView();
|
||||||
shader.uniformMatrix("u_inverseView", glm::inverse(camera.getView()));
|
shader.uniformMatrix("u_view", view);
|
||||||
|
shader.uniformMatrix("u_inverseView", glm::inverse(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostProcessing::renderDeferredShading(
|
void PostProcessing::renderDeferredShading(
|
||||||
|
|
@ -153,12 +164,12 @@ void PostProcessing::renderDeferredShading(
|
||||||
|
|
||||||
gbuffer->bindBuffers();
|
gbuffer->bindBuffers();
|
||||||
|
|
||||||
auto& effect = assets.require<PostEffect>("deferred_lighting");
|
auto& lightingEffect = assets.require<PostEffect>("deferred_lighting");
|
||||||
auto& shader = effect.use();
|
auto& lightingShader = lightingEffect.use();
|
||||||
configureEffect(
|
configureEffect(
|
||||||
context,
|
context,
|
||||||
effect,
|
lightingEffect,
|
||||||
shader,
|
lightingShader,
|
||||||
timer,
|
timer,
|
||||||
camera
|
camera
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -78,5 +78,5 @@ private:
|
||||||
std::unique_ptr<Mesh<PostProcessingVertex>> quadMesh;
|
std::unique_ptr<Mesh<PostProcessingVertex>> quadMesh;
|
||||||
std::vector<std::shared_ptr<PostEffect>> effectSlots;
|
std::vector<std::shared_ptr<PostEffect>> effectSlots;
|
||||||
std::unique_ptr<GBuffer> gbuffer;
|
std::unique_ptr<GBuffer> gbuffer;
|
||||||
uint noiseTexture;
|
uint noiseTexture = 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue