From 26cd616051cc6dd8c53943e77e3ee6ed8acdd834 Mon Sep 17 00:00:00 2001 From: danij Date: Sun, 8 Sep 2013 07:25:20 +0100 Subject: [PATCH] Fixed|Map Renderer|Client: Light decorations disappear instantly at distance; cleanup --- doomsday/client/include/render/rend_main.h | 5 --- doomsday/client/src/render/lumobj.cpp | 10 +++--- doomsday/client/src/render/projector.cpp | 9 ++---- doomsday/client/src/render/r_things.cpp | 6 +--- doomsday/client/src/render/rend_decor.cpp | 36 ++++++++++------------ doomsday/client/src/render/rend_main.cpp | 7 ----- doomsday/client/src/render/sprite.cpp | 7 +++-- 7 files changed, 31 insertions(+), 49 deletions(-) diff --git a/doomsday/client/include/render/rend_main.h b/doomsday/client/include/render/rend_main.h index d154b4f023..ccd2e9935a 100644 --- a/doomsday/client/include/render/rend_main.h +++ b/doomsday/client/include/render/rend_main.h @@ -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. diff --git a/doomsday/client/src/render/lumobj.cpp b/doomsday/client/src/render/lumobj.cpp index 0a0bb2841a..ca6a831b1e 100644 --- a/doomsday/client/src/render/lumobj.cpp +++ b/doomsday/client/src/render/lumobj.cpp @@ -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; } diff --git a/doomsday/client/src/render/projector.cpp b/doomsday/client/src/render/projector.cpp index c85d73301f..7672447a10 100644 --- a/doomsday/client/src/render/projector.cpp +++ b/doomsday/client/src/render/projector.cpp @@ -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) diff --git a/doomsday/client/src/render/r_things.cpp b/doomsday/client/src/render/r_things.cpp index 96ee724da0..a41fa50fe0 100644 --- a/doomsday/client/src/render/r_things.cpp +++ b/doomsday/client/src/render/r_things.cpp @@ -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; @@ -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; - } } } } diff --git a/doomsday/client/src/render/rend_decor.cpp b/doomsday/client/src/render/rend_decor.cpp index dc56d4be51..d51f1084b1 100644 --- a/doomsday/client/src/render/rend_decor.cpp +++ b/doomsday/client/src/render/rend_decor.cpp @@ -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; @@ -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; @@ -257,13 +257,18 @@ static void plotSourcesForPlane(Plane &pln) Sector §or = pln.sector(); AABoxd const §orAABox = 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, §or); + updateSurfaceDecorations(surface, offset, topLeft, bottomRight, §or); } static void plotSourcesForWallSection(LineSide &side, int section) @@ -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? @@ -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); @@ -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]); diff --git a/doomsday/client/src/render/rend_main.cpp b/doomsday/client/src/render/rend_main.cpp index f53eb9b41a..59fbf9767f 100644 --- a/doomsday/client/src/render/rend_main.cpp +++ b/doomsday/client/src/render/rend_main.cpp @@ -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(); diff --git a/doomsday/client/src/render/sprite.cpp b/doomsday/client/src/render/sprite.cpp index b291e2e76d..d803bd8541 100644 --- a/doomsday/client/src/render/sprite.cpp +++ b/doomsday/client/src/render/sprite.cpp @@ -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) { @@ -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; @@ -808,7 +809,7 @@ void Rend_DrawMasked(void) break; case VSPR_FLARE: - if(generateHaloForVisSprite(spr, true) && !primaryHaloDrawn) + if(generateHaloForVisSprite(spr, true)) { primaryHaloDrawn = true; }