Skip to content

Commit

Permalink
Gloom: Added ScreenQuad and SSAO
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent b85b7e2 commit 07ef7ec
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 33 deletions.
4 changes: 4 additions & 0 deletions doomsday/tests/test_gloom/CMakeLists.txt
Expand Up @@ -50,8 +50,12 @@ set (SOURCES
gloom/render/maprender.h
gloom/render/render.cpp
gloom/render/render.h
gloom/render/screenquad.cpp
gloom/render/screenquad.h
gloom/render/skybox.cpp
gloom/render/skybox.h
gloom/render/ssao.cpp
gloom/render/ssao.h
gloom/render/view.cpp
gloom/render/view.h
gloom/world/entity.cpp
Expand Down
14 changes: 8 additions & 6 deletions doomsday/tests/test_gloom/gloom/gloomworld.cpp
Expand Up @@ -23,6 +23,7 @@
#include "gloom/render/gbuffer.h"
#include "gloom/render/maprender.h"
#include "gloom/render/skybox.h"
#include "gloom/render/ssao.h"
#include "gloom/world/entitymap.h"
#include "gloom/world/environment.h"
#include "gloom/world/map.h"
Expand Down Expand Up @@ -52,6 +53,7 @@ DENG2_PIMPL(GloomWorld), public Asset, public ILight
Map map;
QHash<ID, double> initialPlaneY;
MapRender mapRender;
SSAO ssao;

float visibleDistance;
double currentTime = 0.0;
Expand Down Expand Up @@ -98,12 +100,12 @@ DENG2_PIMPL(GloomWorld), public Asset, public ILight

DENG2_ASSERT(localUser);

gbuffer.glInit(renderContext);

sky.setSize(visibleDistance);
sky.glInit(renderContext);

gbuffer .glInit(renderContext);
sky .glInit(renderContext);
mapRender.glInit(renderContext);
ssao .glInit(renderContext);

// Vector3f const fogColor{.83f, .89f, 1.f};
// uFog = Vector4f(fogColor, visibleDistance);
Expand All @@ -116,6 +118,7 @@ DENG2_PIMPL(GloomWorld), public Asset, public ILight
{
setState(NotReady);

ssao .glDeinit();
mapRender.glDeinit();
sky .glDeinit();
gbuffer .glDeinit();
Expand Down Expand Up @@ -149,9 +152,7 @@ DENG2_PIMPL(GloomWorld), public Asset, public ILight
}

void userWarped(const User &)
{

}
{}

void update(const TimeSpan &elapsed)
{
Expand Down Expand Up @@ -241,6 +242,7 @@ void GloomWorld::render(ICamera const &camera)

GLState::pop();

d->ssao.render();
d->gbuffer.render();
}

Expand Down
35 changes: 8 additions & 27 deletions doomsday/tests/test_gloom/gloom/render/gbuffer.cpp
Expand Up @@ -17,6 +17,7 @@
*/

#include "gloom/render/gbuffer.h"
#include "gloom/render/screenquad.h"

#include <de/Drawable>
#include <de/GLTextureFramebuffer>
Expand All @@ -28,14 +29,11 @@ using namespace de;

namespace gloom {

static const int BUF_ID = 1;

DENG2_PIMPL(GBuffer)
{
ScreenQuad quad;
GLTextureFramebuffer frame{
QList<Image::Format>({Image::RGBA_16f /* albedo */, Image::RGBA_8888 /* normals */})};
Drawable drawable;
GLState state;
GLUniform uMvpMatrix {"uMvpMatrix", GLUniform::Mat4};
GLUniform uGBufferAlbedo {"uGBufferAlbedo", GLUniform::Sampler2D};
GLUniform uGBufferNormal {"uGBufferNormal", GLUniform::Sampler2D};
Expand All @@ -44,11 +42,6 @@ DENG2_PIMPL(GBuffer)

Impl(Public *i) : Base(i)
{
state.setBlend(false);
state.setCull(gl::None);
state.setDepthTest(false);
state.setDepthWrite(false);

uDebugMode = 0;
}

Expand All @@ -65,26 +58,18 @@ GBuffer::GBuffer()
void GBuffer::glInit(const Context &context)
{
Render::glInit(context);
d->frame.glInit();

using VBuf = GLBufferT<Vertex2Tex>;

auto *vbuf = new VBuf;
vbuf->setVertices(gl::TriangleStrip,
VBuf::Builder().makeQuad(Rectanglef(0, 0, 1, 1), Rectanglef(0, 1, 1, -1)),
gl::Static);
d->drawable.addBuffer(BUF_ID, vbuf);

context.shaders->build(d->drawable.program(), "gloom.finalize")
d->quad.glInit(context);
context.shaders->build(d->quad.program(), "gloom.finalize")
<< d->uMvpMatrix
<< context.view.uInverseProjMatrix
<< d->uGBufferAlbedo << d->uGBufferNormal << d->uGBufferDepth
<< d->uDebugMode;
d->frame.glInit();
}

void GBuffer::glDeinit()
{
d->drawable.clear();
d->quad.glDeinit();
d->frame.glDeinit();
Render::glDeinit();
}
Expand All @@ -103,22 +88,18 @@ void GBuffer::render()
{
d->uMvpMatrix = Matrix4f::ortho(0, 1, 0, 1);

d->state.setViewport(GLState::current().viewport())
.setTarget (GLState::current().target());

d->drawable.setState(BUF_ID, d->state);

d->uGBufferAlbedo = d->frame.attachedTexture(GLFramebuffer::Color0);
d->uGBufferNormal = d->frame.attachedTexture(GLFramebuffer::Color1);
d->uGBufferDepth = d->frame.attachedTexture(GLFramebuffer::DepthStencil);

d->drawable.draw();
d->quad.render();
}

void gloom::GBuffer::setDebugMode(int debugMode)
{
LOG_AS("GBuffer");
LOG_MSG("Changing debug mode: %i") << debugMode;

d->uDebugMode = debugMode;
}

Expand Down
87 changes: 87 additions & 0 deletions doomsday/tests/test_gloom/gloom/render/screenquad.cpp
@@ -0,0 +1,87 @@
/** @file screenquad.cpp
*
* @authors Copyright (c) 2018 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "gloom/render/screenquad.h"

using namespace de;

namespace gloom {

static const int BUF_ID = 1;

DENG2_PIMPL_NOREF(ScreenQuad)
{
Drawable drawable;
GLState state;

Impl()
{
state.setBlend(false);
state.setCull(gl::None);
state.setDepthTest(false);
state.setDepthWrite(false);
}
};

ScreenQuad::ScreenQuad()
: d(new Impl)
{}

void ScreenQuad::glInit(const Context &context)
{
Render::glInit(context);

using VBuf = GLBufferT<Vertex2Tex>;

auto *vbuf = new VBuf;
vbuf->setVertices(gl::TriangleStrip,
VBuf::Builder().makeQuad(Rectanglef(0, 0, 1, 1), Rectanglef(0, 1, 1, -1)),
gl::Static);
d->drawable.addBuffer(BUF_ID, vbuf);
d->drawable.setState(BUF_ID, d->state);
}

void ScreenQuad::glDeinit()
{
d->drawable.clear();
Render::glDeinit();
}

void ScreenQuad::render()
{
d->state.setViewport(GLState::current().viewport())
.setTarget (GLState::current().target());
d->drawable.draw();
}

Drawable &ScreenQuad::drawable()
{
return d->drawable;
}

GLProgram &ScreenQuad::program()
{
return d->drawable.program();
}

GLState &ScreenQuad::state()
{
return d->state;
}

} // namespace gloom
47 changes: 47 additions & 0 deletions doomsday/tests/test_gloom/gloom/render/screenquad.h
@@ -0,0 +1,47 @@
/** @file screenquad.h
*
* @authors Copyright (c) 2018 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef GLOOM_SCREENQUAD_H
#define GLOOM_SCREENQUAD_H

#include "gloom/render/render.h"

#include <de/Drawable>

namespace gloom {

class ScreenQuad : public Render
{
public:
ScreenQuad();

void glInit(const Context &) override;
void glDeinit() override;
void render() override;

de::Drawable & drawable();
de::GLProgram &program();
de::GLState & state();

private:
DENG2_PRIVATE(d)
};

} // namespace gloom

#endif // GLOOM_SCREENQUAD_H
48 changes: 48 additions & 0 deletions doomsday/tests/test_gloom/gloom/render/ssao.cpp
@@ -0,0 +1,48 @@
/** @file ssao.cpp
*
* @authors Copyright (c) 2018 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "gloom/render/ssao.h"

namespace gloom {

DENG2_PIMPL(SSAO)
{
Impl(Public *i) : Base(i)
{}
};

SSAO::SSAO()
: d(new Impl(this))
{}

void SSAO::glInit(const Context &context)
{
Render::glInit(context);
}

void SSAO::glDeinit()
{
Render::glDeinit();
}

void SSAO::render()
{

}

} // namespace gloom
41 changes: 41 additions & 0 deletions doomsday/tests/test_gloom/gloom/render/ssao.h
@@ -0,0 +1,41 @@
/** @file ssao.h
*
* @authors Copyright (c) 2018 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef GLOOM_SSAO_H
#define GLOOM_SSAO_H

#include "gloom/render/render.h"

namespace gloom {

class SSAO : public Render
{
public:
SSAO();

void glInit(const Context &) override;
void glDeinit() override;
void render() override;

private:
DENG2_PRIVATE(d)
};

} // namespace gloom

#endif // GLOOM_SSAO_H
Expand Up @@ -4,6 +4,7 @@
layout (pixel_center_integer) in vec4 gl_FragCoord;

uniform mat4 uInverseProjMatrix;

uniform sampler2D uGBufferAlbedo;
uniform sampler2D uGBufferNormal;
uniform sampler2D uGBufferDepth;
Expand Down

0 comments on commit 07ef7ec

Please sign in to comment.