DISCLAIMER
This isn't the best way to fix it. I'm well aware of that. I am however showing this way so that it can be used as a baseline for doing it right. Also, it involves much fewer code modifications so it's easier to demonstrate what's needed without needing an overhaul of other parts of the engine first. It's expected that any serious implementation will do it better (e.g. by generalizing R_PushDlights and by properly calculating the inverse matrix in software).
So, add this to your dlight_t struct:
Code: Select all
vec3_t transformed;
Code: Select all
// calculate dynamic lighting for bmodel if it's not an instanced model
if (clmodel->firstmodelsurface != 0 && !gl_flashblend.value)
{
float matrix[16];
// get the inverse transform for moving the light back to the same space as the model
glPushMatrix ();
glLoadIdentity ();
glRotatef (-e->angles[2], 1, 0, 0);
glRotatef (-e->angles[0], 0, 1, 0);
glRotatef (-e->angles[1], 0, 0, 1);
glTranslatef (-e->origin[0], -e->origin[1], -e->origin[2]);
glGetFloatv (GL_MODELVIEW_MATRIX, matrix);
glPopMatrix ();
for (k = 0; k < MAX_DLIGHTS; k++)
{
if ((cl_dlights[k].die < cl.time) || (!cl_dlights[k].radius))
continue;
// move the light back to the same space as the model
cl_dlights[k].transformed[0] = cl_dlights[k].origin[0] * matrix[0] + cl_dlights[k].origin[1] * matrix[4] + cl_dlights[k].origin[2] * matrix[8] + matrix[12];
cl_dlights[k].transformed[1] = cl_dlights[k].origin[0] * matrix[1] + cl_dlights[k].origin[1] * matrix[5] + cl_dlights[k].origin[2] * matrix[9] + matrix[13];
cl_dlights[k].transformed[2] = cl_dlights[k].origin[0] * matrix[2] + cl_dlights[k].origin[1] * matrix[6] + cl_dlights[k].origin[2] * matrix[10] + matrix[14];
// light the model
R_MarkLights (&cl_dlights[k], 1 << k, clmodel->nodes + clmodel->hulls[0].firstclipnode);
}
}
Code: Select all
VectorCopy (l->origin, l->transformed);
Code: Select all
dist = DotProduct (light->transformed, splitplane->normal) - splitplane->dist;
Code: Select all
dist = DotProduct (cl_dlights[lnum].transformed, surf->plane->normal) -
surf->plane->dist;
Code: Select all
impact[i] = cl_dlights[lnum].transformed[i] -
surf->plane->normal[i]*dist;