mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
optimize ssao pass
This commit is contained in:
parent
25cee0284f
commit
2f87bbf608
5 changed files with 39 additions and 24 deletions
|
|
@ -10,6 +10,10 @@ static debug::Logger logger("gl-gbuffer");
|
|||
|
||||
// TODO: REFACTOR
|
||||
|
||||
uint GBuffer::getSSAODownsample() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
void GBuffer::createColorBuffer() {
|
||||
if (colorBuffer == 0)
|
||||
glGenTextures(1, &colorBuffer);
|
||||
|
|
@ -117,15 +121,17 @@ void GBuffer::createDepthBuffer() {
|
|||
}
|
||||
|
||||
void GBuffer::createSSAOBuffer() {
|
||||
if (ssaoBuffer == 0)
|
||||
if (ssaoBuffer == 0) {
|
||||
glGenTextures(1, &ssaoBuffer);
|
||||
}
|
||||
uint ssaoDownsample = getSSAODownsample();
|
||||
glBindTexture(GL_TEXTURE_2D, ssaoBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_R16F,
|
||||
width,
|
||||
height,
|
||||
width / ssaoDownsample,
|
||||
height / ssaoDownsample,
|
||||
0,
|
||||
GL_RED,
|
||||
GL_FLOAT,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ public:
|
|||
uint getHeight() const;
|
||||
|
||||
std::unique_ptr<ImageData> toImage() const;
|
||||
|
||||
uint getSSAODownsample() const;
|
||||
private:
|
||||
uint width;
|
||||
uint height;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ PostProcessing::PostProcessing(size_t effectSlotsCount)
|
|||
quadMesh = std::make_unique<Mesh<PostProcessingVertex>>(meshData, 6);
|
||||
|
||||
std::vector<glm::vec3> ssaoNoise;
|
||||
for (unsigned int i = 0; i < 16; i++)
|
||||
int res = 4;
|
||||
for (unsigned int i = 0; i < res*res; i++)
|
||||
{
|
||||
glm::vec3 noise(
|
||||
(rand() / static_cast<float>(RAND_MAX)) * 2.0 - 1.0,
|
||||
|
|
@ -41,7 +42,7 @@ PostProcessing::PostProcessing(size_t effectSlotsCount)
|
|||
}
|
||||
glGenTextures(1, &noiseTexture);
|
||||
glBindTexture(GL_TEXTURE_2D, noiseTexture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, 4, 4, 0, GL_RGB, GL_FLOAT, ssaoNoise.data());
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, res, res, 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);
|
||||
|
|
@ -89,7 +90,8 @@ void PostProcessing::configureEffect(
|
|||
PostEffect& effect,
|
||||
Shader& shader,
|
||||
float timer,
|
||||
const Camera& camera
|
||||
const Camera& camera,
|
||||
unsigned int downsample
|
||||
) {
|
||||
const auto& viewport = context.getViewport();
|
||||
shader.uniform1i("u_screen", TARGET_COLOR);
|
||||
|
|
@ -101,7 +103,7 @@ void PostProcessing::configureEffect(
|
|||
}
|
||||
shader.uniform1i("u_noise", TARGET_SSAO); // used in SSAO pass
|
||||
shader.uniform1i("u_ssao", TARGET_SSAO);
|
||||
shader.uniform2i("u_screenSize", viewport);
|
||||
shader.uniform2i("u_screenSize", viewport / downsample);
|
||||
shader.uniform3f("u_cameraPos", camera.position);
|
||||
shader.uniform1f("u_timer", timer);
|
||||
shader.uniformMatrix("u_projection", camera.getProjection());
|
||||
|
|
@ -128,15 +130,14 @@ void PostProcessing::renderDeferredShading(
|
|||
|
||||
auto& ssaoEffect = assets.require<PostEffect>("ssao");
|
||||
auto& shader = ssaoEffect.use();
|
||||
configureEffect(
|
||||
context,
|
||||
ssaoEffect,
|
||||
shader,
|
||||
timer,
|
||||
camera
|
||||
);
|
||||
uint ssaoDownscale = gbuffer->getSSAODownsample();
|
||||
configureEffect(context, ssaoEffect, shader, timer, camera, ssaoDownscale);
|
||||
gbuffer->bindSSAO();
|
||||
quadMesh->draw();
|
||||
{
|
||||
auto ssaoContext = context.sub();
|
||||
ssaoContext.setViewport(context.getViewport() / ssaoDownscale);
|
||||
quadMesh->draw();
|
||||
}
|
||||
gbuffer->unbind();
|
||||
|
||||
{
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ private:
|
|||
PostEffect& effect,
|
||||
Shader& shader,
|
||||
float timer,
|
||||
const Camera& camera
|
||||
const Camera& camera,
|
||||
unsigned downsample = 1U
|
||||
);
|
||||
|
||||
void refreshFbos(uint width, uint height);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue