Skip to content

Commit

Permalink
Renderer|FX: Added a basic set of lens flare textures
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 23, 2013
1 parent 07f95ae commit 78142e7
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 11 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions doomsday/client/data/renderer.pack/images.dei
Expand Up @@ -2,7 +2,12 @@
#
# These images are used as key assets in 2D and 3D rendering.

# Lens flare images.
group fx.lensflares {
# Lens flare images.

image burst { path = "graphics/flares/h-burst.png" }
image circle { path = "graphics/flares/circle.png" }
image exponent { path = "graphics/flares/exponent.png" }
image halo { path = "graphics/flares/halo.png" }
image ring { path = "graphics/flares/ring.png" }
image star { path = "graphics/flares/star.png" }
}
4 changes: 3 additions & 1 deletion doomsday/client/data/renderer.pack/shaders/lensflares.fsh
Expand Up @@ -2,7 +2,9 @@ uniform sampler2D uTex;
varying highp vec2 vUV;

void main(void) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
highp vec4 tex = texture2D(uTex, vUV);
gl_FragColor = tex;

/*
highp vec4 original = texture2D(uTex, vUV);
highp float intens =
Expand Down
82 changes: 74 additions & 8 deletions doomsday/client/src/render/fx/lensflares.cpp
Expand Up @@ -21,9 +21,11 @@
#include "render/viewports.h"
#include "render/rend_main.h"
#include "gl/gl_main.h"
#include "clientapp.h"

#include <de/concurrency.h>
#include <de/Drawable>
#include <de/RowAtlasAllocator>
#include <de/Shared>
#include <de/Log>

Expand All @@ -39,11 +41,38 @@ namespace fx {
struct FlareData
{
AtlasTexture atlas;
enum FlareId {
Burst,
Circle,
Exponent,
Halo,
Ring,
Star,
MAX_FLARES
};
enum Corner {
TopLeft,
TopRight,
BottomRight,
BottomLeft
};
Id flare[MAX_FLARES];

FlareData()
: atlas(Atlas::BackingStore, Atlas::Size(1024, 1536))
{
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

/// @todo Use KdTreeAtlasAllocator
atlas.setAllocator(new RowAtlasAllocator);

flare[Exponent] = atlas.alloc(flareImage("exponent"));
flare[Star] = atlas.alloc(flareImage("star"));
flare[Halo] = atlas.alloc(flareImage("halo"));
flare[Circle] = atlas.alloc(flareImage("circle"));
flare[Ring] = atlas.alloc(flareImage("ring"));
flare[Burst] = atlas.alloc(flareImage("burst"));
}

~FlareData()
Expand All @@ -53,6 +82,36 @@ struct FlareData

LOG_DEBUG("Releasing shared data");
}

static Image const &flareImage(String const &name)
{
return ClientApp::renderSystem().images().image("fx.lensflares." + name);
}

Rectanglef uvRect(FlareId id) const
{
return atlas.imageRectf(flare[id]);
}

Vector2f flareCorner(FlareId id, Corner corner) const
{
Vector2f p;
switch(corner)
{
case TopLeft: p = Vector2f(-1, -1); break;
case TopRight: p = Vector2f( 1, -1); break;
case BottomRight: p = Vector2f( 1, 1); break;
case BottomLeft: p = Vector2f(-1, 1); break;
}

if(id == Burst)
{
// Non-square.
p *= Vector2f(2, .5f);
}

return p;
}
};

DENG2_PIMPL(LensFlares)
Expand Down Expand Up @@ -102,13 +161,15 @@ DENG2_PIMPL(LensFlares)
Drawable drawable;
GLUniform uMvpMatrix;
GLUniform uViewUnit;
GLUniform uAtlas;

Instance(Public *i)
: Base(i)
, res(0)
, buffer(0)
, uMvpMatrix("uMvpMatrix", GLUniform::Mat4)
, uViewUnit ("uViewUnit", GLUniform::Vec2)
, uAtlas ("uTex", GLUniform::Sampler2D)
{}

~Instance()
Expand All @@ -126,7 +187,9 @@ DENG2_PIMPL(LensFlares)
buffer = new VBuf;
drawable.addBuffer(buffer);
self.shaders().build(drawable.program(), "fx.lensflares")
<< uMvpMatrix << uViewUnit;
<< uMvpMatrix << uViewUnit << uAtlas;

uAtlas = res->atlas;
}

void glDeinit()
Expand Down Expand Up @@ -173,28 +236,29 @@ DENG2_PIMPL(LensFlares)
/// @todo If so, it might be time to purge it from the PVS.
if(pvl->seenFrame != thisFrame) continue;

float radius = .1f;
Rectanglef uvRect;
float radius = .5f;
FlareData::FlareId id = FlareData::Burst;
Rectanglef uvRect = res->uvRect(id);

int const firstIdx = verts.size();

vtx.pos = pvl->light->lightSourceOrigin().xzy();
vtx.rgba = Vector4f(pvl->light->lightSourceColorf(), 1.f);

vtx.texCoord[0] = uvRect.topLeft;
vtx.texCoord[1] = Vector2f(-1, -1) * radius;
vtx.texCoord[1] = res->flareCorner(id, FlareData::TopLeft) * radius;
verts << vtx;

vtx.texCoord[0] = uvRect.topRight();
vtx.texCoord[1] = Vector2f(1, -1) * radius;
vtx.texCoord[1] = res->flareCorner(id, FlareData::TopRight) * radius;
verts << vtx;

vtx.texCoord[0] = uvRect.bottomRight;
vtx.texCoord[1] = Vector2f(1, 1) * radius;
vtx.texCoord[1] = res->flareCorner(id, FlareData::BottomRight) * radius;
verts << vtx;

vtx.texCoord[0] = uvRect.bottomLeft();
vtx.texCoord[1] = Vector2f(-1, 1) * radius;
vtx.texCoord[1] = res->flareCorner(id, FlareData::BottomLeft) * radius;
verts << vtx;

// Make two triangles.
Expand Down Expand Up @@ -253,7 +317,9 @@ void LensFlares::draw()

GLState::push()
.setCull(gl::None)
.setDepthTest(false);
.setDepthTest(false)
.setBlend(true)
.setBlendFunc(gl::SrcAlpha, gl::One);

d->drawable.draw();

Expand Down

0 comments on commit 78142e7

Please sign in to comment.