Skip to content

Commit

Permalink
MaterialSnapshot: Do not integrate the global glowFactor when taking …
Browse files Browse the repository at this point in the history
…a material snapshot

The global glowFactor multiplier should not be integrated into the
snapshot as this would mean the snapshot state is invalidated when
this value changes.

Instead the global factor should be applied to the interpolated
glow strength value of the snapshot by users of this class.
  • Loading branch information
danij-deng committed Jan 16, 2013
1 parent 5240ee9 commit 1e8499b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions doomsday/engine/include/map/r_world.h
Expand Up @@ -202,6 +202,7 @@ void R_UpdateMapSurfacesOnMaterialChange(material_t* material);
/// @return @c true= @a plane is non-glowing (i.e. not glowing or a sky).
boolean R_IsGlowingPlane(const Plane* plane);

/// @return Current glow strength for the plane.
float R_GlowStrength(const Plane* pln);

lineowner_t* R_GetVtxLineOwner(const Vertex* vtx, const LineDef* line);
Expand Down
17 changes: 5 additions & 12 deletions doomsday/engine/src/map/r_world.cpp
Expand Up @@ -1420,21 +1420,12 @@ void R_ClearSectorFlags()

boolean R_IsGlowingPlane(Plane const *pln)
{
#ifdef __CLIENT__
/// @todo We should not need to prepare to determine this.
material_t *mat = pln->surface.material;
if(mat)
{
MaterialSnapshot const &ms =
App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec());

if(!Material_IsDrawable(mat) || ms.glowStrength() > 0) return true;
if(!Material_IsDrawable(mat) || Material_HasGlow(mat)) return true;
}
return Surface_IsSkyMasked(&pln->surface);
#else
DENG_UNUSED(pln);
return false;
#endif
}

float R_GlowStrength(Plane const *pln)
Expand All @@ -1445,11 +1436,13 @@ float R_GlowStrength(Plane const *pln)
{
if(Material_IsDrawable(mat) && !Surface_IsSkyMasked(&pln->surface))
{
/// @todo We should not need to prepare to determine this.
MaterialSnapshot const &ms =
App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec());

return ms.glowStrength();
float glowStrength = ms.glowStrength();
if(glowFactor > .0001f)
glowStrength *= glowFactor; // Global scale factor.
return glowStrength;
}
}
#else
Expand Down
6 changes: 5 additions & 1 deletion doomsday/engine/src/render/lumobj.cpp
Expand Up @@ -976,7 +976,11 @@ static boolean createGlowLightForSurface(Surface *suf, void * /*parameters*/)

V3f_Copy(LUM_PLANE(lum)->normal, pln->PS_normal);
V3f_Copy(LUM_PLANE(lum)->color, avgColorAmplified->color.rgb);
LUM_PLANE(lum)->intensity = ms.glowStrength();

float glowStrength = ms.glowStrength();
if(glowFactor > .0001f)
glowStrength *= glowFactor; // Global scale factor.
LUM_PLANE(lum)->intensity = glowStrength;
LUM_PLANE(lum)->tex = GL_PrepareLSTexture(LST_GRADIENT);
lum->maxDistance = 0;
lum->decorSource = 0;
Expand Down
5 changes: 1 addition & 4 deletions doomsday/engine/src/render/rend_fakeradio.cpp
Expand Up @@ -1316,10 +1316,7 @@ static void processEdgeShadow(BspLeaf const *bspLeaf, LineDef const *lineDef,

// Glowing surfaces or missing textures shouldn't have shadows.
if((suf->inFlags & SUIF_NO_RADIO) || !suf->material || Surface_IsSkyMasked(suf)) return;

MaterialSnapshot const &ms =
App_Materials()->prepare(*pln->PS_material, Rend_MapSurfaceMaterialSpec(), true);
if(ms.glowStrength() > 0) return;
if(Material_HasGlow(pln->PS_material)) return;

// Determine the openness of the lineDef. If this edge is edgeOpen,
// there won't be a shadow at all. Open neighbours cause some
Expand Down
17 changes: 13 additions & 4 deletions doomsday/engine/src/render/rend_main.cpp
Expand Up @@ -1260,6 +1260,8 @@ static boolean doRenderHEdge(HEdge* hedge, const pvec3f_t normal,
params.surfaceColor = color;
params.wall.surfaceColor2 = color2;
params.glowing = ms.glowStrength();
if(glowFactor > .0001f)
params.glowing *= glowFactor; // Global scale factor.
params.blendMode = blendMode;
params.texOffset = texOffset;
params.texScale = texScale;
Expand Down Expand Up @@ -1470,6 +1472,9 @@ static void renderPlane(BspLeaf* bspLeaf, planetype_t type, coord_t height,
params.glowing = ms.glowStrength();
}

if(glowFactor > .0001f)
params.glowing *= glowFactor; // Global scale factor.

// Dynamic lights?
if(addDLights && params.glowing < 1 && !(!useDynLights && !useWallGlow))
{
Expand Down Expand Up @@ -1690,24 +1695,28 @@ static boolean rendHEdgeSection(HEdge* hedge, SideDefSection section,
if(surface->inFlags & SUIF_NO_RADIO)
flags &= ~RHF_ADD_RADIO;

float glowStrength = ms.glowStrength();
if(glowFactor > .0001f)
glowStrength *= glowFactor; // Global scale factor.

// Dynamic Lights?
if((flags & RHF_ADD_DYNLIGHTS) &&
ms.glowStrength() < 1 && !(!useDynLights && !useWallGlow))
glowStrength < 1 && !(!useDynLights && !useWallGlow))
{
lightListIdx = LO_ProjectToSurface(((section == SS_MIDDLE && isTwoSided)? PLF_SORT_LUMINOSITY_DESC : 0), currentBspLeaf, 1,
texTL, texBR, HEDGE_SIDEDEF(hedge)->SW_middletangent, HEDGE_SIDEDEF(hedge)->SW_middlebitangent, HEDGE_SIDEDEF(hedge)->SW_middlenormal);
}

// Dynamic shadows?
if((flags & RHF_ADD_DYNSHADOWS) &&
ms.glowStrength() < 1 && Rend_MobjShadowsEnabled())
glowStrength < 1 && Rend_MobjShadowsEnabled())
{
// Glowing planes inversely diminish shadow strength.
shadowListIdx = R_ProjectShadowsToSurface(currentBspLeaf, 1 - ms.glowStrength(), texTL, texBR,
shadowListIdx = R_ProjectShadowsToSurface(currentBspLeaf, 1 - glowStrength, texTL, texBR,
HEDGE_SIDEDEF(hedge)->SW_middletangent, HEDGE_SIDEDEF(hedge)->SW_middlebitangent, HEDGE_SIDEDEF(hedge)->SW_middlenormal);
}

if(ms.glowStrength() > 0)
if(glowStrength > 0)
flags &= ~RHF_ADD_RADIO;

selectSurfaceColors(&color, &color2, HEDGE_SIDEDEF(hedge), section);
Expand Down
5 changes: 1 addition & 4 deletions doomsday/engine/src/resource/materialsnapshot.cpp
Expand Up @@ -24,7 +24,7 @@
# include "de_defs.h"
#endif

#include "render/rend_main.h" // glowFactor, TODO: get rid of this
#include "render/rend_main.h" // detailFactor, detailScale, TODO: get rid of this
#ifdef __CLIENT__
# include "gl/gl_texmanager.h"
# include "gl/sys_opengl.h"
Expand Down Expand Up @@ -362,9 +362,6 @@ void MaterialSnapshot::Instance::takeSnapshot()
stored.glowStrength = LERP(lsCur->glowStrength, lsNext->glowStrength, l.inter);
}

if(glowFactor > .0001f)
stored.glowStrength *= glowFactor; // Global scale factor.

if(MC_MAPSURFACE == spec.context && prepTextures[MTU_REFLECTION])
{
stored.reflectionMinColor = Vector3f(Material_ShinyMinColor(mat));
Expand Down

0 comments on commit 1e8499b

Please sign in to comment.