Skip to content

Commit

Permalink
Renderer: Lumobjs and vector lights include a possible source mobj
Browse files Browse the repository at this point in the history
When rendering lights, it is something useful to know which mobj
(if any) is responsible for casting the light.

Not a long-term solution, but sufficient for now.
  • Loading branch information
skyjake committed Apr 2, 2016
1 parent 47fb73a commit c87b69a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions doomsday/apps/client/include/render/lumobj.h
Expand Up @@ -103,6 +103,15 @@ class Lumobj : public world::MapObject
*/
void setSource(Source const *newSource);

/**
* Sets the mobj that is responsible for casting this light.
*
* @param mo Thing.
*/
void setSourceMobj(struct mobj_s const *mo);

struct mobj_s const *sourceMobj() const;

/**
* Returns the light color/intensity of the lumobj.
*
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/client/include/render/vectorlightdata.h
Expand Up @@ -35,6 +35,7 @@ struct VectorLightData
de::dfloat lightSide;
de::dfloat darkSide; ///< Factors for world light.
bool affectedByAmbient;
struct mobj_s const *sourceMobj; ///< Originating mobj, or nullptr.
};

#endif // CLIENT_RENDER_VECTORLIGHTDATA_H
12 changes: 12 additions & 0 deletions doomsday/apps/client/src/render/lumobj.cpp
Expand Up @@ -42,6 +42,7 @@ dfloat Lumobj::Source::occlusion(Vector3d const & /*eye*/) const
DENG2_PIMPL_NOREF(Lumobj)
{
Source const *source = nullptr; ///< Source of the lumobj (if any, not owned).
mobj_t const *sourceMobj = nullptr; ///< Mobj associated with the lumobj (if any).
ddouble maxDistance = 0; ///< Used when rendering to limit the number drawn lumobjs.
Vector3f color = Vector3f(1, 1, 1); ///< Light color/intensity.
ddouble radius = 256; ///< Radius in map space units.
Expand All @@ -59,6 +60,7 @@ DENG2_PIMPL_NOREF(Lumobj)
Instance(Instance const &other)
: de::IPrivate()
, source (other.source)
, sourceMobj (other.sourceMobj)
, maxDistance(other.maxDistance)
, color (other.color)
, radius (other.radius)
Expand Down Expand Up @@ -87,6 +89,16 @@ void Lumobj::setSource(Source const *newSource)
d->source = newSource;
}

void Lumobj::setSourceMobj(mobj_t const *mo)
{
d->sourceMobj = mo;
}

mobj_t const *Lumobj::sourceMobj() const
{
return d->sourceMobj;
}

Vector3f const &Lumobj::color() const
{
return d->color;
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -2344,6 +2344,7 @@ static bool lightWithWorldLight(Vector3d const & /*point*/, Vector3f const &ambi
vlight.darkSide = .8f;
vlight.offset = .3f;
}
vlight.sourceMobj = nullptr;
return true;
}

Expand All @@ -2370,6 +2371,7 @@ static bool lightWithLumobj(Vector3d const &point, Lumobj const &lum, VectorLigh
vlight.lightSide = 1;
vlight.darkSide = 0;
vlight.offset = 0;
vlight.sourceMobj = lum.sourceMobj();
return true;
}

Expand Down Expand Up @@ -2406,6 +2408,7 @@ static bool lightWithPlaneGlow(Vector3d const &point, SectorCluster const &clust
vlight.lightSide = 1;
vlight.darkSide = 0;
vlight.offset = 0.3f;
vlight.sourceMobj = nullptr;
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion doomsday/apps/client/src/world/p_mobj.cpp
Expand Up @@ -501,6 +501,8 @@ void Mobj_GenerateLumobjs(mobj_t *mo)
std::unique_ptr<Lumobj> lum(Rend_MakeLumobj(sprite.def()));
if(!lum) return;

lum->setSourceMobj(mo);

// A light definition may override the (auto-calculated) defaults.
if(ded_light_t *def = lightDefByMobjState(mo->state))
{
Expand Down Expand Up @@ -616,7 +618,7 @@ dfloat Mobj_ShadowStrength(mobj_t const &mob)
ambientLightLevel = cluster.lightSourceIntensity();
}
Rend_ApplyLightAdaptation(ambientLightLevel);

// Sprites have their own shadow strength factor.
dfloat strength = .65f; ///< Default.
if(!::useModels || !Mobj_ModelDef(mob))
Expand Down

0 comments on commit c87b69a

Please sign in to comment.