Skip to content

Commit

Permalink
Fixed various issues in the conversion from lumobj to vlight for the …
Browse files Browse the repository at this point in the history
…purposes of sprite and model lighting.

TODO: The debug display I added to draw the light vectors affecting a given sprite indicate that there are a few remaining problems further up chain, mostly to do with vertical offsets (affecting light vectors don't point in the direction of the origin).
  • Loading branch information
danij committed Oct 10, 2008
1 parent 20e3c91 commit 1c58076
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/r_things.c
Expand Up @@ -1464,10 +1464,10 @@ boolean visSpriteLightIterator(const lumobj_t* lum, float xyDist, void* data)

// Calculate the normalized direction vector, pointing out of
// the light origin.
vlight->vector[VX] = (params->pos[VX] - lum->pos[VX]) / dist;
vlight->vector[VY] = (params->pos[VY] - lum->pos[VY]) / dist;
vlight->vector[VZ] = (params->pos[VZ] - lum->pos[VZ] +
LUM_OMNI(lum)->zOff) / dist;
vlight->vector[VX] = (lum->pos[VX] - params->pos[VX]) / dist;
vlight->vector[VY] = (lum->pos[VY] - params->pos[VY]) / dist;
vlight->vector[VZ] = (lum->pos[VZ] + LUM_OMNI(lum)->zOff -
params->pos[VZ]) / dist;

vlight->color[CR] = LUM_OMNI(lum)->color[CR] * intensity;
vlight->color[CG] = LUM_OMNI(lum)->color[CG] * intensity;
Expand All @@ -1489,7 +1489,7 @@ boolean visSpriteLightIterator(const lumobj_t* lum, float xyDist, void* data)
*/
vlight->vector[VX] = LUM_PLANE(lum)->normal[VX];
vlight->vector[VY] = LUM_PLANE(lum)->normal[VY];
vlight->vector[VZ] = LUM_PLANE(lum)->normal[VZ];
vlight->vector[VZ] = -LUM_PLANE(lum)->normal[VZ];

vlight->color[CR] = LUM_PLANE(lum)->color[CR] * intensity;
vlight->color[CG] = LUM_PLANE(lum)->color[CG] * intensity;
Expand Down Expand Up @@ -1571,7 +1571,7 @@ uint R_CollectAffectingLights(const collectaffectinglights_params_t* params)
&vars, visSpriteLightIterator);
}

return vLightListIdx;
return vLightListIdx + 1;
}

/**
Expand Down
44 changes: 44 additions & 0 deletions doomsday/engine/portable/src/rend_sprite.c
Expand Up @@ -855,6 +855,26 @@ void Rend_DrawMasked(void)
}
}

#if _DEBUG
boolean drawVLightVector(const vlight_t* light, void* context)
{
float scale = 100;

DGL_Begin(DGL_LINES);
{
DGL_Color4f(light->color[CR], light->color[CG], light->color[CB], 1);
DGL_Vertex3f(scale * light->vector[VX],
scale * light->vector[VZ],
scale * light->vector[VY]);
DGL_Color4f(0, 0, 0, 1);
DGL_Vertex3f(0, 0, 0);
}
DGL_End();

return true; // Continue iteration.
}
#endif

void Rend_RenderSprite(const rendspriteparams_t* params)
{
int i;
Expand Down Expand Up @@ -936,6 +956,30 @@ DGL_Enable(DGL_TEXTURING);
spriteLight + 1, params->ambientColor);
}

/*#if _DEBUG
if(params->vLightListIdx)
{ // Draw the vlight vectors, for debug.
DGL_Disable(DGL_TEXTURING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();
DGL_Translatef(params->center[VX], params->center[VZ],
params->center[VY]);
VL_ListIterator(params->vLightListIdx, NULL, drawVLightVector);
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
DGL_Enable(DGL_TEXTURING);
}
#endif*/

// Do we need to do some aligning?
if(params->viewAligned || alwaysAlign >= 2)
{
Expand Down

0 comments on commit 1c58076

Please sign in to comment.