(GLQuake) Software Quake MDL Lighting

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

(GLQuake) Software Quake MDL Lighting

Post by mh »

Here's another step along the path to making GLQuake look as Quake was originally intended; this time we're going to fix MDL lighting so that it's consistent with software Quake. All that's changing here is the lightting algorithm used; I haven't done anything with overbrights, interpolation or anything else.

The code assumes a completely unmodified GLQuake baseline, and all code changes come from the software Quake source. You should be able to compare this with GLQuake's original, quickly and easily identify the changes made, and port them to any other engine based on that.

Code: Select all

void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum)
{
	float 	l;
	int		i, j;
	trivertx_t	*verts;
	int		*order;
	float	*normal;
	int		count;
	float baselight = ambientlight * (1.0f / 200.0f);
	float temp;
	float alias_forward[3], alias_right[3], alias_up[3];
	float r_plightvec[3], lightvec[3] = {-1, 0, 0};

	currententity->angles[0] = -currententity->angles[0];	// stupid quake bug
	AngleVectors (currententity->angles, alias_forward, alias_right, alias_up);
	currententity->angles[0] = -currententity->angles[0];	// stupid quake bug

	// rotate the lighting vector into the model's frame of reference
	r_plightvec[0] = DotProduct (lightvec, alias_forward);
	r_plightvec[1] = -DotProduct (lightvec, alias_right);
	r_plightvec[2] = DotProduct (lightvec, alias_up);

	lastposenum = posenum;

	verts = (trivertx_t *)((byte *)paliashdr + paliashdr->posedata);
	verts += posenum * paliashdr->poseverts;
	order = (int *)((byte *)paliashdr + paliashdr->commands);

	while (1)
	{
		// get the vertex count and primitive type
		count = *order++;
		if (!count)
			break;		// done
		if (count < 0)
		{
			count = -count;
			glBegin (GL_TRIANGLE_FAN);
		}
		else
			glBegin (GL_TRIANGLE_STRIP);

		do
		{
			// texture coordinates come from the draw list
			glTexCoord2f (((float *)order)[0], ((float *)order)[1]);
			order += 2;

			// normals and vertexes come from the frame list
			temp = baselight;
			l = DotProduct (r_avertexnormals[verts->lightnormalindex], r_plightvec);

			if (l < 0)
				temp -= shadelight * l;

			glColor3f (temp, temp, temp);

			glVertex3f (verts->v[0], verts->v[1], verts->v[2]);
			verts++;
		} while (--count);

		glEnd ();
	}
}
That's all. :D

The key differences are that MDLs now look a LOT more coherent, like they fit into the world better, that angle quantization is totally gone, and that shading changes as you look up and down as well as right and left.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
leileilol
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Post by leileilol »

Hot damn! Time to put this stuff into Quake2. This is one of the things I wanted to do in my 'software' ref_gl :D I hated the choppy table-based lighting.
i should not be here
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

Hmmmmm ...
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Post Reply