Skip to content

Commit

Permalink
Gloom: Added LightRender and create a depth-only FBO
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent fd6bbf2 commit dd857c6
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 20 deletions.
3 changes: 3 additions & 0 deletions doomsday/tests/test_gloom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ set (SOURCES
gloom/render/gbuffer.cpp
gloom/render/gbuffer.h
gloom/render/icamera.h
gloom/render/light.cpp
gloom/render/light.h
gloom/render/lightrender.cpp
gloom/render/lightrender.h
gloom/render/mapbuild.cpp
gloom/render/mapbuild.h
gloom/render/maprender.cpp
Expand Down
5 changes: 0 additions & 5 deletions doomsday/tests/test_gloom/gloom/render/entityrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@
#include "gloom/world/entitymap.h"
#include "gloom/render/render.h"

#include <de/AtlasTexture>

namespace gloom {

class ICamera;
class Map;

class EntityRender : public Render
{
public:
Expand Down
57 changes: 57 additions & 0 deletions doomsday/tests/test_gloom/gloom/render/light.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/** @file light.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/light.h"

#include <de/GLFramebuffer>

using namespace de;

namespace gloom {

DENG2_PIMPL(Light)
{
Vec3d origin;
Vec3f dir;
Vec3f intensity;
GLTexture shadowMap;
GLFramebuffer framebuf;

Impl(Public *i) : Base(i)
{
shadowMap.setAutoGenMips(false);
shadowMap.setFilter(gl::Linear, gl::Linear, gl::MipNone);
shadowMap.setUndefinedContent(
GLTexture::Size(1024, 1024),
GLPixelFormat(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT));

framebuf.configure(GLFramebuffer::Depth, shadowMap);
}
};

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

Mat4f Light::lightMatrix() const
{
return Mat4f::ortho(-10, 10, -10, 10, 1, 10) *
Mat4f::lookAt(d->origin + d->dir, d->origin, Vec3f(0, 1, 0));
}

} // namespace gloom
21 changes: 17 additions & 4 deletions doomsday/tests/test_gloom/gloom/render/light.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
#ifndef GLOOM_RENDER_LIGHT_H
#define GLOOM_RENDER_LIGHT_H

#include <de/GLTexture>
#include <de/Matrix>
#include <de/Vector>

#include "gloom/world/entity.h"

namespace gloom {

/**
Expand All @@ -32,12 +36,21 @@ class Light
enum Type { Omni, Linear, Spot };

Light();
virtual ~Light();

Type type() const;
void setEntity(const Entity *entity);
void setType(Type type);

const Entity *entity() const;

Type type() const;
de::Vec3f origin() const; // from entity
de::Vec3f direction() const;
de::Vec3f intensity() const;
float fovY() const;
float aspectRatio() const;

virtual de::Vec3f lightDirection() const = 0;
virtual de::Vec3f lightColor() const = 0;
de::GLTexture &shadowMap();
de::Mat4f lightMatrix() const;

private:
DENG2_PRIVATE(d)
Expand Down
69 changes: 69 additions & 0 deletions doomsday/tests/test_gloom/gloom/render/lightrender.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/** @file lightrender.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/lightrender.h"
#include "gloom/render/light.h"

namespace gloom {

DENG2_PIMPL(LightRender)
{
std::unique_ptr<Light> skyLight;
QHash<ID, std::shared_ptr<Light>> lights;

Impl(Public *i) : Base(i)
{}

void glInit()
{
skyLight.reset(new Light);
}

void glDeinit()
{
skyLight.reset();
}
};

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

void LightRender::glInit(const Context &context)
{
Render::glInit(context);
d->glInit();
}

void LightRender::glDeinit()
{
d->glDeinit();
Render::glDeinit();
}

void LightRender::render()
{

}

void LightRender::createLights()
{

}

} // namespace gloom
46 changes: 46 additions & 0 deletions doomsday/tests/test_gloom/gloom/render/lightrender.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** @file lightrender.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_LIGHTRENDER_H
#define GLOOM_LIGHTRENDER_H

#include "gloom/render/render.h"

namespace gloom {

/**
* Renders light source shadow maps and the deferred shading pass.
*/
class LightRender : public Render
{
public:
LightRender();

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

void createLights();

private:
DENG2_PRIVATE(d)
};

} // namespace gloom

#endif // GLOOM_LIGHTRENDER_H
21 changes: 13 additions & 8 deletions doomsday/tests/test_gloom/gloom/render/maprender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "gloom/render/mapbuild.h"
#include "gloom/render/databuffer.h"
#include "gloom/render/entityrender.h"
#include "gloom/render/lightrender.h"
#include "gloom/render/icamera.h"

#include <de/Drawable>
Expand All @@ -41,20 +42,20 @@ DENG2_PIMPL(MapRender)
Vec4f uvRect;
Vec4f texelSize;
};
DataBuffer<Metrics> textureMetrics{"uTextureMetrics", Image::RGBA_32f, 2, 1};

DataBuffer<float> planes{"uPlanes", Image::R_32f};

struct TexOffsetData {
Vec2f offset;
Vec2f speed;
};
DataBuffer<TexOffsetData> texOffsets{"uTexOffsets", Image::RGBA_32f};

GLUniform uTexelsPerMeter {"uTexelsPerMeter", GLUniform::Float};
DataBuffer<Metrics> textureMetrics{"uTextureMetrics", Image::RGBA_32f, 2, 1};
DataBuffer<float> planes {"uPlanes", Image::R_32f};
DataBuffer<TexOffsetData> texOffsets {"uTexOffsets", Image::RGBA_32f};

GLUniform uTexelsPerMeter{"uTexelsPerMeter", GLUniform::Float};
Drawable drawable;

EntityRender ents;
LightRender lights;

Impl(Public *i) : Base(i)
{}
Expand Down Expand Up @@ -125,7 +126,8 @@ DENG2_PIMPL(MapRender)

void glInit()
{
ents.glInit(self().context());
ents .glInit(self().context());
lights.glInit(self().context());

uTexelsPerMeter = 200;

Expand All @@ -139,11 +141,13 @@ DENG2_PIMPL(MapRender)

buildMap();
ents.createEntities();
lights.createLights();
}

void glDeinit()
{
ents.glDeinit();
ents .glDeinit();
lights.glDeinit();

for (const Id &texId : loadedTextures)
{
Expand Down Expand Up @@ -177,6 +181,7 @@ void MapRender::rebuild()
{
d->buildMap();
d->ents.createEntities();
d->lights.createLights();
}

void MapRender::advanceTime(TimeSpan)
Expand Down
13 changes: 12 additions & 1 deletion doomsday/tests/test_gloom/gloom/world/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ namespace gloom {
class Entity
{
public:
enum Type { None = 0, Tree1, Tree2, Tree3 };
enum Type {
None = 0,

// Special entity types:
Light = 1,
Spotlight = 2,

// World entities:
Tree1 = 1000,
Tree2,
Tree3,
};

public:
Entity();
Expand Down
3 changes: 1 addition & 2 deletions doomsday/tests/test_gloom/gloom/world/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct Plane
de::Vec3d point;
de::Vec3f normal;

bool isPointAbove(const de::Vec3d &pos) const;
bool isPointAbove(const de::Vec3d &pos) const;
de::Vec3d projectPoint(const Point &pos) const;
};

Expand All @@ -68,7 +68,6 @@ struct Sector
IDList walls; // unordered
IDList volumes; // must be ascending and share planes; bottom plane of first volume is the
// sector floor, top plane of last volume is the sector ceiling

void replaceLine(ID oldId, ID newId);
};

Expand Down

0 comments on commit dd857c6

Please sign in to comment.