Skip to content

Commit

Permalink
Refactor|Map Renderer|Client: Generate a light decoration flare (sour…
Browse files Browse the repository at this point in the history
…ce) directly from Lumobj

Moved more light properties into Lumobj. Also, a source can now be
attributed which provides occlusion information when generating a
flare source.

Produced LightDecoration from Decoration.

Todo for later: mobj_t should implement Lumobj::ISource.
  • Loading branch information
danij-deng committed Sep 12, 2013
1 parent c1fa5ac commit fd9e8eb
Show file tree
Hide file tree
Showing 13 changed files with 391 additions and 214 deletions.
3 changes: 3 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -136,6 +136,7 @@ DENG_CONVENIENCE_HEADERS += \
include/HueCircle \
include/HueCircleVisual \
include/IHPlane \
include/LightDecoration \
include/Line \
include/MapElement \
include/MapObject \
Expand Down Expand Up @@ -285,6 +286,7 @@ DENG_HEADERS += \
include/render/blockmapvisual.h \
include/render/decoration.h \
include/render/huecirclevisual.h \
include/render/lightdecoration.h \
include/render/lightgrid.h \
include/render/lumobj.h \
include/render/materialcontext.h \
Expand Down Expand Up @@ -633,6 +635,7 @@ SOURCES += \
src/render/blockmapvisual.cpp \
src/render/decoration.cpp \
src/render/huecirclevisual.cpp \
src/render/lightdecoration.cpp \
src/render/lightgrid.cpp \
src/render/lumobj.cpp \
src/render/projector.cpp \
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/LightDecoration
@@ -0,0 +1 @@
#include "render/lightdecoration.h"
32 changes: 2 additions & 30 deletions doomsday/client/include/render/decoration.h
Expand Up @@ -26,7 +26,6 @@

#include "MaterialSnapshot"

class Lumobj;
class Surface;

/// No decorations are visible beyond this.
Expand All @@ -50,21 +49,9 @@ class Decoration
*/
Decoration(de::MaterialSnapshotDecoration &source,
de::Vector3d const &origin = de::Vector3d());
virtual ~Decoration();

/**
* To be called to register the commands and variables of this module.
*/
static void consoleRegister();

/**
* Returns the current angle fade factor (user configurable).
*/
static float angleFadeFactor();

/**
* Returns the current brightness scale factor (user configurable).
*/
static float brightFactor();
DENG2_AS_IS_METHODS()

/**
* Returns the source of the decoration.
Expand Down Expand Up @@ -111,21 +98,6 @@ class Decoration
*/
BspLeaf &bspLeafAtOrigin() const;

/**
* Generates a lumobj for the decoration. A map surface must be attributed.
*
* @see setSurface(), hasSurface()
*/
void generateLumobj();

/**
* Generates a VSPR_FLARE vissprite for the decoration. A map surface must
* be attributed.
*
* @see setSurface(), hasSurface()
*/
void generateFlare();

private:
DENG2_PRIVATE(d)
};
Expand Down
79 changes: 79 additions & 0 deletions doomsday/client/include/render/lightdecoration.h
@@ -0,0 +1,79 @@
/** @file lightdecoration.h World surface light decoration.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 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 General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef DENG_CLIENT_RENDER_LIGHTDECORATION_H
#define DENG_CLIENT_RENDER_LIGHTDECORATION_H

#include "Decoration"
#include "render/lumobj.h"

class LightDecoration : public Decoration, public Lumobj::Source
{
public:
/**
* Construct a new light decoration.
*
* @param source Source of the decoration (a material).
* @param origin Origin of the decoration in map space.
*/
LightDecoration(de::MaterialSnapshotDecoration &source,
de::Vector3d const &origin = de::Vector3d());

/**
* To be called to register the commands and variables of this module.
*/
static void consoleRegister();

/**
* Returns the current angle fade factor (user configurable).
*/
static float angleFadeFactor();

/**
* Returns the current brightness scale factor (user configurable).
*/
static float brightFactor();

/**
* R
*/
de::Vector3d const &origin() const;

/**
* Calculates an occlusion factor for the light source. Determined by the
* relative position of the @a eye (the viewer) and the decoration.
*
* @param eye Position of the eye in map space.
*
* @return Occlusion factor in the range [0..1], where @c 0 is fully
* occluded and @c 1 is fully visible.
*/
float occlusion(de::Vector3d const &eye) const;

/**
* Generates a new lumobj for the light decoration. A map surface must be
* attributed to the decoration.
*
* @see Decoration::setSurface(), Decoration::hasSurface()
*/
Lumobj *generateLumobj();
};

#endif // DENG_CLIENT_RENDER_LIGHTDECORATION_H
67 changes: 62 additions & 5 deletions doomsday/client/include/render/lumobj.h
Expand Up @@ -42,19 +42,37 @@ class Lumobj : public de::MapObject
Up
};

/**
* Base for any class wishing to act as the source of the luminous object.
*/
class Source
{
public:
virtual ~Source() {}

/**
* Calculate an occlusion factor for the light. The implementation should
* return a value in the range [0..1], where @c 0 is fully occluded and
* @c 1 is fully visible.
*
* In the default implementation assumes the source is always visible.
*
* @param eye Position of the eye in map space.
*/
float occlusion(de::Vector3d const &eye) const;
};

public:
/**
* Construct a new luminous object.
*
* @param origin Origin in map space.
* @param radius Radius in map space units.
* @param color Color/intensity.
* @param maxDistance Maximum distance at which to be drawn (default: no-max).
*/
Lumobj(de::Vector3d const &origin = de::Vector3d(),
double radius = 256,
de::Vector3f const &color = de::Vector3f(1, 1, 1),
double maxDistance = 0);
de::Vector3f const &color = de::Vector3f(1, 1, 1));

/// Construct a new luminious object by copying @a other.
Lumobj(Lumobj const &other);
Expand All @@ -74,6 +92,13 @@ class Lumobj : public de::MapObject
*/
static int radiusMax();

/**
* Change the attributed source of the lumobj.
*
* @param newSource New source to attribute. Use @c 0 to clear.
*/
void setSource(Source *newSource);

/**
* Translate the origin of the lumobj in map space.
*
Expand Down Expand Up @@ -190,14 +215,46 @@ class Lumobj : public de::MapObject
*/
Lumobj &setLightmap(LightmapSemantic semantic, de::Texture *newTexture);

/**
* Returns the current flare size of the lumobj.
*/
float flareSize() const;

/**
* Change the flare size of the lumobj.
*
* @param newFlareSize New flare size factor.
*/
Lumobj &setFlareSize(float newFlareSize);

/**
* Returns the current flare texture of the lumobj.
*/
DGLuint flareTexture() const;

/**
* Change the flare texture of the lumobj.
*
* @param newTexture New flare texture.
*/
Lumobj &setFlareTexture(DGLuint newTexture);

/**
* Calculate a distance attentuation factor for the lumobj.
*
* @param distance Distance between the lumobj and the viewer.
* @param distFromEye Distance between the lumobj and the viewer.
*
* @return Attentuation factor [0..1].
*/
float attenuation(double distance) const;
float attenuation(double distFromEye) const;

/**
* Generates a VSPR_FLARE vissprite for the lumobj.
*
* @param eye Position of the viewer in map space.
* @param distFromEye Distance between the lumobj and the viewer.
*/
void generateFlare(de::Vector3d const &eye, double distFromEye);

private:
DENG2_PRIVATE(d)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/resource/materialsnapshot.h
Expand Up @@ -57,7 +57,7 @@ class MaterialSnapshot
float elevation; // Distance from the surface.
de::Vector3f color; // Light color.
float radius; // Dynamic light radius (-1 = no light).
float haloRadius; // Halo radius (zero = no halo).
float flareSize; // Halo radius (zero = no halo).
float lightLevels[2]; // Fade by sector lightlevel.

Texture *tex, *ceilTex, *floorTex;
Expand Down

0 comments on commit fd9e8eb

Please sign in to comment.