Skip to content

Commit

Permalink
Refactor: Relocated various renderer domain functions from r_world to…
Browse files Browse the repository at this point in the history
… rend_main
  • Loading branch information
danij-deng committed May 8, 2013
1 parent c6a9341 commit 5c5a59a
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 116 deletions.
15 changes: 0 additions & 15 deletions doomsday/client/include/map/r_world.h
Expand Up @@ -47,28 +47,13 @@ LineOwner *R_GetVtxLineOwner(Vertex const *vtx, Line const *line);

void R_UpdateSector(Sector &sector, bool forceUpdate = false);

/**
* Sector light color may be affected by the sky light color.
*/
de::Vector3f const &R_GetSectorLightColor(Sector const &sector);

/**
* @return @c > 0 if @a lightlevel passes the min max limit condition.
*/
float R_CheckSectorLight(float lightlevel, float min, float max);

#ifdef __CLIENT__

float R_DistAttenuateLightLevel(float distToViewer, float lightLevel);

/**
* The DOOM lighting model applies a light level delta to everything when
* e.g. the player shoots.
*
* @return Calculated delta.
*/
float R_ExtraLightDelta();

void R_UpdateMissingMaterialsForLinesOfSector(Sector const &sec);

#endif // __CLIENT__
Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/include/render/r_main.h
Expand Up @@ -65,8 +65,6 @@ DENG_EXTERN_C float frameTimePos; // 0...1: fractional part for sharp ga
DENG_EXTERN_C int loadInStartupMode;
DENG_EXTERN_C int validCount;
DENG_EXTERN_C int frameCount;
DENG_EXTERN_C int extraLight;
DENG_EXTERN_C float extraLightDelta;
DENG_EXTERN_C int rendInfoTris;

DENG_EXTERN_C byte precacheMapMaterials, precacheSprites, precacheSkins;
Expand Down
25 changes: 25 additions & 0 deletions doomsday/client/include/render/rend_main.h
Expand Up @@ -52,6 +52,8 @@ DENG_EXTERN_C int rAmbient;
DENG_EXTERN_C float rendLightDistanceAttenuation;
DENG_EXTERN_C int rendLightAttenuateFixedColormap;
DENG_EXTERN_C float lightModRange[255];
DENG_EXTERN_C int extraLight;
DENG_EXTERN_C float extraLightDelta;

DENG_EXTERN_C int devRendSkyMode;
DENG_EXTERN_C int gameDrawHUD;
Expand Down Expand Up @@ -102,6 +104,24 @@ void Rend_ApplyLightAdaptation(float *lightValue);
/// Same as Rend_ApplyLightAdaptation except the delta is returned.
float Rend_LightAdaptationDelta(float lightvalue);

/**
* The DOOM lighting model applies distance attenuation to sector light
* levels.
*
* @param distToViewer Distance from the viewer to this object.
* @param lightLevel Sector lightLevel at this object's origin.
* @return The specified lightLevel plus any attentuation.
*/
float Rend_AttenuateLightLevel(float distToViewer, float lightLevel);

/**
* The DOOM lighting model applies a light level delta to everything when
* e.g. the player shoots.
*
* @return Calculated delta.
*/
float Rend_ExtraLightDelta();

/**
* Updates the lightModRange which is used to applify sector light to help
* compensate for the differences between the OpenGL lighting equation,
Expand All @@ -114,6 +134,11 @@ void Rend_CalcLightModRange();

void R_DrawLightRange();

/**
* Sector light color may be affected by the sky light color.
*/
de::Vector3f const &Rend_SectorLightColor(Sector const &sector);

de::MaterialVariantSpec const &Rend_MapSurfaceMaterialSpec();

texturevariantspecification_t &Rend_MapSurfaceShinyTextureSpec();
Expand Down
79 changes: 1 addition & 78 deletions doomsday/client/src/map/r_world.cpp
Expand Up @@ -907,86 +907,9 @@ void R_UpdateSector(Sector &sector, bool forceUpdate)
#endif
}

#ifdef __CLIENT__

/**
* The DOOM lighting model applies distance attenuation to sector light
* levels.
*
* @param distToViewer Distance from the viewer to this object.
* @param lightLevel Sector lightLevel at this object's origin.
* @return The specified lightLevel plus any attentuation.
*/
float R_DistAttenuateLightLevel(float distToViewer, float lightLevel)
{
if(distToViewer > 0 && rendLightDistanceAttenuation > 0)
{
float real = lightLevel -
(distToViewer - 32) / rendLightDistanceAttenuation *
(1 - lightLevel);

float minimum = lightLevel * lightLevel + (lightLevel - .63f) * .5f;
if(real < minimum)
real = minimum; // Clamp it.

return real;
}

return lightLevel;
}

float R_ExtraLightDelta()
{
return extraLightDelta;
}

#endif // __CLIENT__

float R_CheckSectorLight(float lightlevel, float min, float max)
{
// Has a limit been set?
if(min == max) return 1;
return MINMAX_OF(0, (lightlevel - min) / (float) (max - min), 1);
return de::clamp(0.f, (lightlevel - min) / float(max - min), 1.f);
}

#ifdef __CLIENT__

Vector3f const &R_GetSectorLightColor(Sector const &sector)
{
static Vector3f skyLightColor;
static Vector3f oldSkyAmbientColor(-1.f, -1.f, -1.f);
static float oldRendSkyLight = -1;

if(rendSkyLight > .001f && sector.hasSkyMaskedPlane())
{
ColorRawf const *ambientColor = Sky_AmbientColor();

if(rendSkyLight != oldRendSkyLight ||
!INRANGE_OF(ambientColor->red, oldSkyAmbientColor.x, .001f) ||
!INRANGE_OF(ambientColor->green, oldSkyAmbientColor.y, .001f) ||
!INRANGE_OF(ambientColor->blue, oldSkyAmbientColor.z, .001f))
{
skyLightColor = Vector3f(ambientColor->rgb);
R_AmplifyColor(skyLightColor);

// Apply the intensity factor cvar.
for(int i = 0; i < 3; ++i)
{
skyLightColor[i] = skyLightColor[i] + (1 - rendSkyLight) * (1.f - skyLightColor[i]);
}

// When the sky light color changes we must update the lightgrid.
LG_MarkAllForUpdate();
oldSkyAmbientColor = Vector3f(ambientColor->rgb);
}

oldRendSkyLight = rendSkyLight;
return skyLightColor;
}

// A non-skylight sector (i.e., everything else!)
// Return the sector's ambient light color.
return sector.lightColor();
}

#endif // __CLIENT__
2 changes: 1 addition & 1 deletion doomsday/client/src/render/r_lgrid.cpp
Expand Up @@ -811,7 +811,7 @@ BEGIN_PROF( PROF_GRID_UPDATE );

// Determine the color of the ambient light in this sector.
sector = block->sector;
Vector3f const &color = R_GetSectorLightColor(*sector);
Vector3f const &color = Rend_SectorLightColor(*sector);
height = (int) (sector->ceiling().height() - sector->floor().height());

bool isSkyFloor = sector->ceilingSurface().hasSkyMaskedMaterial();
Expand Down
8 changes: 3 additions & 5 deletions doomsday/client/src/render/r_main.cpp
Expand Up @@ -60,9 +60,6 @@ int rendInfoTris = 0;
// Precalculated math tables.
fixed_t *fineCosine = &finesine[FINEANGLES / 4];

int extraLight; // Bumped light from gun blasts.
float extraLightDelta;

float frameTimePos; // 0...1: fractional part for sharp game tics.

int loadInStartupMode = false;
Expand Down Expand Up @@ -1033,13 +1030,14 @@ void R_SetupFrame(player_t *player)
if(player->extraLightCounter == 0)
player->extraLight = player->targetExtraLight;
}
extraLight = player->extraLight;
extraLightDelta = extraLight / 16.0f;

// Why?
validCount++;

#ifdef __CLIENT__
extraLight = player->extraLight;
extraLightDelta = extraLight / 16.0f;

if(!freezeRLs)
#endif
{
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/render/r_things.cpp
Expand Up @@ -925,7 +925,7 @@ void getLightingParams(coord_t x, coord_t y, coord_t z, BspLeaf *bspLeaf,
{
Sector &sec = bspLeaf->sector();
float lightLevel = sec.lightLevel();
Vector3f const &secColor = R_GetSectorLightColor(sec);
Vector3f const &secColor = Rend_SectorLightColor(sec);

/* if(spr->type == VSPR_DECORATION)
{
Expand All @@ -934,10 +934,10 @@ void getLightingParams(coord_t x, coord_t y, coord_t z, BspLeaf *bspLeaf,
} */

// Apply distance attenuation.
lightLevel = R_DistAttenuateLightLevel(distance, lightLevel);
lightLevel = Rend_AttenuateLightLevel(distance, lightLevel);

// Add extra light.
lightLevel += R_ExtraLightDelta();
lightLevel += Rend_ExtraLightDelta();

Rend_ApplyLightAdaptation(&lightLevel);

Expand Down
74 changes: 69 additions & 5 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -135,6 +135,9 @@ byte devLightModRange = 0;
float rendLightDistanceAttenuation = 1024;
int rendLightAttenuateFixedColormap = 1;

int extraLight; // Bumped light from gun blasts.
float extraLightDelta;

byte devMobjVLights = 0; // @c 1= Draw mobj vertex lighting vector.
int devMobjBBox = 0; // 1 = Draw mobj bounding boxes (for debug)
int devPolyobjBBox = 0; // 1 = Draw polyobj bounding boxes (for debug)
Expand Down Expand Up @@ -350,14 +353,75 @@ void Rend_ApplyTorchLight(float color[3], float distance)
}
}

float Rend_AttenuateLightLevel(float distToViewer, float lightLevel)
{
if(distToViewer > 0 && rendLightDistanceAttenuation > 0)
{
float real = lightLevel -
(distToViewer - 32) / rendLightDistanceAttenuation *
(1 - lightLevel);

float minimum = lightLevel * lightLevel + (lightLevel - .63f) * .5f;
if(real < minimum)
real = minimum; // Clamp it.

return real;
}

return lightLevel;
}

float Rend_ExtraLightDelta()
{
return extraLightDelta;
}

Vector3f const &Rend_SectorLightColor(Sector const &sector)
{
static Vector3f skyLightColor;
static Vector3f oldSkyAmbientColor(-1.f, -1.f, -1.f);
static float oldRendSkyLight = -1;

if(rendSkyLight > .001f && sector.hasSkyMaskedPlane())
{
ColorRawf const *ambientColor = Sky_AmbientColor();

if(rendSkyLight != oldRendSkyLight ||
!INRANGE_OF(ambientColor->red, oldSkyAmbientColor.x, .001f) ||
!INRANGE_OF(ambientColor->green, oldSkyAmbientColor.y, .001f) ||
!INRANGE_OF(ambientColor->blue, oldSkyAmbientColor.z, .001f))
{
skyLightColor = Vector3f(ambientColor->rgb);
R_AmplifyColor(skyLightColor);

// Apply the intensity factor cvar.
for(int i = 0; i < 3; ++i)
{
skyLightColor[i] = skyLightColor[i] + (1 - rendSkyLight) * (1.f - skyLightColor[i]);
}

// When the sky light color changes we must update the lightgrid.
LG_MarkAllForUpdate();
oldSkyAmbientColor = Vector3f(ambientColor->rgb);
}

oldRendSkyLight = rendSkyLight;
return skyLightColor;
}

// A non-skylight sector (i.e., everything else!)
// Return the sector's ambient light color.
return sector.lightColor();
}

static void lightVertex(ColorRawf &color, rvertex_t const &vtx, float lightLevel,
Vector3f const &ambientColor)
{
float const dist = Rend_PointDist2D(vtx.pos);
float lightVal = R_DistAttenuateLightLevel(dist, lightLevel);
float lightVal = Rend_AttenuateLightLevel(dist, lightLevel);

// Add extra light.
lightVal += R_ExtraLightDelta();
lightVal += Rend_ExtraLightDelta();

Rend_ApplyLightAdaptation(&lightVal);

Expand Down Expand Up @@ -1523,7 +1587,7 @@ static bool writeWallSection(SectionEdge const &leftEdge, SectionEdge const &rig
if(isTwoSidedMiddle && side.sectorPtr() != currentBspLeaf->sectorPtr())
{
// Temporarily modify the draw state.
currentSectorLightColor = R_GetSectorLightColor(side.sector());
currentSectorLightColor = Rend_SectorLightColor(side.sector());
currentSectorLightLevel = side.sector().lightLevel();
}

Expand Down Expand Up @@ -1596,7 +1660,7 @@ static bool writeWallSection(SectionEdge const &leftEdge, SectionEdge const &rig
if(isTwoSidedMiddle && side.sectorPtr() != currentBspLeaf->sectorPtr())
{
// Undo temporary draw state changes.
currentSectorLightColor = R_GetSectorLightColor(currentBspLeaf->sector());
currentSectorLightColor = Rend_SectorLightColor(currentBspLeaf->sector());
currentSectorLightLevel = currentBspLeaf->sector().lightLevel();
}

Expand Down Expand Up @@ -2759,7 +2823,7 @@ static void makeCurrent(BspLeaf *bspLeaf)
// Update draw state.
if(sectorChanged)
{
currentSectorLightColor = R_GetSectorLightColor(bspLeaf->sector());
currentSectorLightColor = Rend_SectorLightColor(bspLeaf->sector());
currentSectorLightLevel = bspLeaf->sector().lightLevel();
}
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/render/rend_particle.cpp
Expand Up @@ -465,13 +465,13 @@ static void setupModelParamsForParticle(rendmodelparams_t* params,
else
{
float lightLevel = pt->sector->lightLevel();
Vector3f const &secColor = R_GetSectorLightColor(*pt->sector);
Vector3f const &secColor = Rend_SectorLightColor(*pt->sector);

// Apply distance attenuation.
lightLevel = R_DistAttenuateLightLevel(params->distance, lightLevel);
lightLevel = Rend_AttenuateLightLevel(params->distance, lightLevel);

// Add extra light.
lightLevel += R_ExtraLightDelta();
lightLevel += Rend_ExtraLightDelta();

Rend_ApplyLightAdaptation(&lightLevel);

Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/sprite.cpp
Expand Up @@ -337,13 +337,13 @@ static void setupPSpriteParams(rendpspriteparams_t *params, vispsprite_t *spr)
else
{
Sector &sector = spr->data.sprite.bspLeaf->sector();
Vector3f const &secColor = R_GetSectorLightColor(sector);
Vector3f const &secColor = Rend_SectorLightColor(sector);

// No need for distance attentuation.
float lightLevel = sector.lightLevel();

// Add extra light plus bonus.
lightLevel += R_ExtraLightDelta();
lightLevel += Rend_ExtraLightDelta();
lightLevel *= pspLightLevelMultiplier;

Rend_ApplyLightAdaptation(&lightLevel);
Expand Down Expand Up @@ -726,15 +726,15 @@ static void setupModelParamsForVisPSprite(rendmodelparams_t *params, vispsprite_
else
{
Sector &sector = spr->data.model.bspLeaf->sector();
Vector3f const &secColor = R_GetSectorLightColor(sector);
Vector3f const &secColor = Rend_SectorLightColor(sector);

// Diminished light (with compression).
float lightLevel = sector.lightLevel();

// No need for distance attentuation.

// Add extra light.
lightLevel += R_ExtraLightDelta();
lightLevel += Rend_ExtraLightDelta();

// The last step is to compress the resultant light value by
// the global lighting function.
Expand Down

0 comments on commit 5c5a59a

Please sign in to comment.