Skip to content

Commit

Permalink
Fixed|Map Renderer|Client: Light decorations disappear instantly at d…
Browse files Browse the repository at this point in the history
…istance; cleanup
  • Loading branch information
danij-deng committed Sep 8, 2013
1 parent 7887500 commit 26cd616
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 49 deletions.
5 changes: 0 additions & 5 deletions doomsday/client/include/render/rend_main.h
Expand Up @@ -104,11 +104,6 @@ void Rend_ModelViewMatrix(bool useAngles = true);

#define Rend_PointDist2D(c) (fabs((vOrigin[VZ]-(c)[VY])*viewsidex - (vOrigin[VX]-(c)[VX])*viewsidey))

/**
* Approximated! The Z axis aspect ratio is corrected.
*/
double Rend_PointDist3D(de::Vector3d const &point);

/**
* The DOOM lighting model applies a light level delta to everything when
* e.g. the player shoots.
Expand Down
10 changes: 6 additions & 4 deletions doomsday/client/src/render/lumobj.cpp
Expand Up @@ -196,10 +196,12 @@ Lumobj &Lumobj::setLightmap(LightmapSemantic semantic, Texture *newTexture)

float Lumobj::attenuation(double distance) const
{
if(distance <= 0) return 1;
if(distance > d->maxDistance) return 0;
if(distance > .67 * d->maxDistance)
return (d->maxDistance - distance) / (.33 * d->maxDistance);
if(distance > 0 && d->maxDistance > 0)
{
if(distance > d->maxDistance) return 0;
if(distance > .67 * d->maxDistance)
return (d->maxDistance - distance) / (.33 * d->maxDistance);
}
return 1;
}

Expand Down
9 changes: 3 additions & 6 deletions doomsday/client/src/render/projector.cpp
Expand Up @@ -292,12 +292,9 @@ static void projectLumobj(Lumobj &lum, project_params_t &parm)

// Calculate the final surface light attribution factor.
float luma = 1.5f - 1.5f * distToLum / lum.radius();

// Fade out as distance from viewer increases?
if(lum.maxDistance() > 0)
{
luma *= lum.attenuation(R_ViewerLumobjDistance(lum.indexInMap()));
}

// Fade out as distance from viewer increases.
luma *= lum.attenuation(R_ViewerLumobjDistance(lum.indexInMap()));

// Would this be seen?
if(luma * parm.blendFactor < OMNILIGHT_SURFACE_LUMINOSITY_ATTRIBUTION_MIN)
Expand Down
6 changes: 1 addition & 5 deletions doomsday/client/src/render/r_things.cpp
Expand Up @@ -449,7 +449,7 @@ void R_ProjectSprite(mobj_t *mo)

vissprite_t *vis = R_NewVisSprite(VSPR_FLARE);

vis->distance = distFromEye;
vis->distance = distFromEye;

// Determine the exact center of the flare.
vis->origin = moPos + visOff;
Expand Down Expand Up @@ -492,10 +492,6 @@ void R_ProjectSprite(mobj_t *mo)
{
vis->data.flare.tex = GL_PrepareFlaremap(flaremapResourceUri);
}
else
{
vis->data.flare.flags |= RFF_NO_PRIMARY;
}
}
}
}
36 changes: 17 additions & 19 deletions doomsday/client/src/render/rend_decor.cpp
Expand Up @@ -184,11 +184,11 @@ static uint generateDecorLights(MaterialSnapshot::Decoration const &decor,
float const offT = t / sufDimensions.y;
Vector3d offset(offS, axis == VZ? offT : offS, axis == VZ? offS : offT);

Vector3d origin = topLeft + delta * offset;
Vector3d origin = topLeft + delta * offset;
BspLeaf &bspLeaf = suf.map().bspLeafAt(origin);
if(containingSector)
{
// The point must be inside the correct sector.
BspLeaf const &bspLeaf = containingSector->map().bspLeafAt(origin);
if(bspLeaf.sectorPtr() != containingSector
|| !bspLeaf.polyContains(origin))
continue;
Expand All @@ -197,7 +197,7 @@ static uint generateDecorLights(MaterialSnapshot::Decoration const &decor,
if(Surface::DecorSource *source = suf.newDecoration())
{
source->origin = origin;
source->bspLeaf = &suf.map().bspLeafAt(origin);
source->bspLeaf = &bspLeaf;
source->decor = &decor;

plotted += 1;
Expand Down Expand Up @@ -257,13 +257,18 @@ static void plotSourcesForPlane(Plane &pln)
Sector &sector = pln.sector();
AABoxd const &sectorAABox = sector.aaBox();

Vector3d v1(sectorAABox.minX, pln.isSectorFloor()? sectorAABox.maxY : sectorAABox.minY, pln.visHeight());
Vector3d v2(sectorAABox.maxX, pln.isSectorFloor()? sectorAABox.minY : sectorAABox.maxY, pln.visHeight());
Vector3d topLeft(sectorAABox.minX,
pln.isSectorFloor()? sectorAABox.maxY : sectorAABox.minY,
pln.visHeight());

Vector3d bottomRight(sectorAABox.maxX,
pln.isSectorFloor()? sectorAABox.minY : sectorAABox.maxY,
pln.visHeight());

Vector2f offset(-fmod(sectorAABox.minX, 64) - surface.visMaterialOrigin().x,
-fmod(sectorAABox.minY, 64) - surface.visMaterialOrigin().y);

updateSurfaceDecorations(surface, offset, v1, v2, &sector);
updateSurfaceDecorations(surface, offset, topLeft, bottomRight, &sector);
}

static void plotSourcesForWallSection(LineSide &side, int section)
Expand Down Expand Up @@ -407,8 +412,8 @@ static void projectSource(Decoration const &src)
if(!lum) return; // Huh?

// Is the point in range?
double distance = Rend_PointDist3D(lum->origin());
if(R_ViewerLumobjDistance(lum->indexInMap()) > lum->maxDistance())
double distance = R_ViewerLumobjDistance(lum->indexInMap());
if(distance > lum->maxDistance())
return;

// Does it pass the sector light limitation?
Expand All @@ -429,8 +434,9 @@ static void projectSource(Decoration const &src)
vis->origin = lum->origin();
vis->distance = distance;

vis->data.flare.lumIdx = lum->indexInMap();
vis->data.flare.isDecoration = true;
vis->data.flare.tex = decor->flareTex;
vis->data.flare.lumIdx = lum->indexInMap();

// Color is taken from the associated lumobj.
V3f_Set(vis->data.flare.color, lum->color().x, lum->color().y, lum->color().z);
Expand All @@ -440,18 +446,10 @@ static void projectSource(Decoration const &src)
else
vis->data.flare.size = 0;

if(decor->flareTex != 0)
{
vis->data.flare.tex = decor->flareTex;
}
else
{ // Primary halo disabled.
vis->data.flare.flags |= RFF_NO_PRIMARY;
vis->data.flare.tex = 0;
}
// Fade out as distance from viewer increases.
vis->data.flare.mul = lum->attenuation(distance);

// Halo brightness drops as the angle gets too big.
vis->data.flare.mul = 1;
if(decor->elevation < 2 && decorLightFadeAngle > 0) // Close the surface?
{
Vector3d const eye(vOrigin[VX], vOrigin[VZ], vOrigin[VY]);
Expand Down
7 changes: 0 additions & 7 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -319,13 +319,6 @@ static inline bool isNullLeaf(BspLeaf const *leaf)
return !leaf || !leaf->hasWorldVolume();
}

double Rend_PointDist3D(Vector3d const &point)
{
return M_ApproxDistance3(vOrigin[VX] - point.x,
vOrigin[VZ] - point.y,
1.2 * (vOrigin[VY] - point.z));
}

void Rend_Init()
{
C_Init();
Expand Down
7 changes: 4 additions & 3 deletions doomsday/client/src/render/sprite.cpp
Expand Up @@ -749,7 +749,8 @@ static bool generateHaloForVisSprite(vissprite_t const *spr, bool primary = fals
{
float occlusionFactor;

if(primary && (spr->data.flare.flags & RFF_NO_PRIMARY)) return false;
if(primary && (spr->data.flare.flags & RFF_NO_PRIMARY))
return false;

if(spr->data.flare.isDecoration)
{
Expand All @@ -775,7 +776,7 @@ static bool generateHaloForVisSprite(vissprite_t const *spr, bool primary = fals
(spr->data.flare.flags & RFF_NO_TURN) != 0);
}

void Rend_DrawMasked(void)
void Rend_DrawMasked()
{
if(devNoSprites) return;

Expand Down Expand Up @@ -808,7 +809,7 @@ void Rend_DrawMasked(void)
break;

case VSPR_FLARE:
if(generateHaloForVisSprite(spr, true) && !primaryHaloDrawn)
if(generateHaloForVisSprite(spr, true))
{
primaryHaloDrawn = true;
}
Expand Down

0 comments on commit 26cd616

Please sign in to comment.