Tutorial *93*
Glow Effects
As I played GLQuake there were some things that I wasn't happy with (hard to believe I know).

One of these was the fact that the weapon effects were a little dull by modern game standards.

I saw on a board somewhere that I was not alone, and so decided to do something about it.


I'd already assimilated the 'Glowing Torch' code from UnOfficial Quake, and so realised that with a few adjustments I could add some new effects:-

Glowing Quad's and Pentegrams
Glowing Rocket Tail-Fires
Glowing Lightning

Well this code does just that.

Open gl_rmain.c

In R_DrawAliasModel

Just above the line


	if (r_shadows.value)

add :-


	// hacked in from UNOFFICAL GLQUAKE code

	// muff@yakko.globalnet.co.uk

	// added lightning glow code  -  20 Mar 2000

	// added rocket tailglow code -  20 Mar 2000

	// updated to be pastable - 5 May 2000

	if ( (!strncmp (clmodel->name, "progs/flame.mdl",11)) ||

		 (!strncmp (clmodel->name, "progs/bolt",10)) ||

		 (!strcmp (clmodel->name, "progs/missile.mdl")) ||

		 (!strcmp (clmodel->name, "progs/quaddama.mdl")) ||

		 (!strcmp (clmodel->name, "progs/invulner.mdl")) ||

		 (!strcmp (clmodel->name, "progs/laser.mdl"))

		 )

	{

		// Draw torch flares. KH

		// NOTE: It would be better if we batched these up.

		//       All those state changes are not nice. KH



		// This relies on unchanged game code!

		const int TORCH_STYLE = 1; // Flicker.



		vec3_t	lightorigin;	// Origin of torch.

		vec3_t	v;				// Vector to torch.

		float	radius;			// Radius of torch flare.

		float	distance;		// Vector distance to torch.

		float	intensity;		// Intensity of torch flare.



		// NOTE: I don't think this is centered on the model.

		VectorCopy(currententity->origin, lightorigin);



		//set radius based on what model we are doing here

		if( (!strncmp (clmodel->name, "progs/flame.mdl",11))  ||

		    (!strcmp (clmodel->name, "progs/missile.mdl")) )

		 radius = 20.0f;

		else if( (!strncmp (clmodel->name, "progs/bolt",10)) ||

		 (!strcmp (clmodel->name, "progs/laser.mdl")) )

		 radius = 30.0f;

		else if( (!strcmp (clmodel->name, "progs/quaddama.mdl")) ||

				 (!strcmp (clmodel->name, "progs/invulner.mdl"))

			   )

		 radius = 50.0f;



		VectorSubtract(lightorigin, r_origin, v);



		// See if view is outside the light.

		distance = Length(v);

		if (distance > radius) {

			glDepthMask (0);

			glDisable (GL_TEXTURE_2D);

			glShadeModel (GL_SMOOTH);

			glEnable (GL_BLEND);

			glBlendFunc (GL_ONE, GL_ONE);



			// Translate the glow to coincide with the flame. KH

			// or be at the tail of the missile - muff

			glPushMatrix();

			if (!strncmp (clmodel->name, "progs/flame.mdl",11))

			 glTranslatef(0.0f, 0.0f, 8.0f);

			else if (!strcmp (clmodel->name, "progs/missile.mdl"))

			{

				glTranslatef(cos( e->angles[1]/180*M_PI)*(-20.0f), sin( e->angles[1]/180*M_PI)*(-20.0f), sin( e->angles[0]/180*M_PI)*(-20.0f));

			}

		    else if( (!strcmp (clmodel->name, "progs/quaddama.mdl")) ||

				 (!strcmp (clmodel->name, "progs/invulner.mdl"))

			   )

			 glTranslatef(0.0f, 0.0f, 20.0f);

			else if(!strcmp (clmodel->name, "progs/invulner.mdl"))

			 glTranslatef(0.0f, 0.0f, 0.0f);







			glBegin(GL_TRIANGLE_FAN);





			// Invert (fades as you approach) - if we are a torch

			if (!strncmp (clmodel->name, "progs/flame.mdl",11))

			{

				// Diminish torch flare inversely with distance.

			    intensity = (1024.0f - distance) / 1024.0f;

				intensity = (1.0f - intensity);

			}

			// or fix settings if lightning or missile

			else if( (!strncmp (clmodel->name, "progs/bolt",10)) ||

					 (!strcmp (clmodel->name, "progs/laser.mdl")) )

				intensity = 0.2f;

			else if (!strcmp (clmodel->name, "progs/missile.mdl"))

				intensity = 0.5f;

		    else if( (!strcmp (clmodel->name, "progs/quaddama.mdl")) ||

				 (!strcmp (clmodel->name, "progs/invulner.mdl")) )

			    intensity = 0.3f;



			// Clamp, but don't let the flare disappear.

			if (intensity > 1.0f) intensity = 1.0f;

			if (intensity < 0.0f) intensity = 0.0f;



			// Now modulate with flicker.

			i = (int)(cl.time*10);

			if (!cl_lightstyle[TORCH_STYLE].length) {

				j = 256;

			} else {

				j = i % cl_lightstyle[TORCH_STYLE].length;

				j = cl_lightstyle[TORCH_STYLE].map[j] - 'a';

				j = j*22;

			}

			intensity *= ((float)j / 255.0f);



			// Set yellow intensity

#if 0

			// Testing

			glColor3f(0.8f, 0.4f, 0.1f);

#else

			// set the colour of the glow - muff

			if ((!strncmp (clmodel->name, "progs/flame.mdl",11))  || (!strcmp (clmodel->name, "progs/missile.mdl"))  )

			 glColor3f(0.8f*intensity, 0.4f*intensity, 0.1f);

			else if	(!strncmp (clmodel->name, "progs/bolt",10))

			 glColor3f(0.2f*intensity, 0.2f*intensity, 0.8f*intensity);

		    else if (!strcmp (clmodel->name, "progs/quaddama.mdl"))

			 glColor3f(0.1f*intensity, 0.1f*intensity, 0.8f*intensity);

			else if (!strcmp (clmodel->name, "progs/invulner.mdl"))

			 glColor3f(0.8f*intensity, 0.1f*intensity, 0.1f*intensity);

			else if (!strcmp (clmodel->name, "progs/laser.mdl"))

			 glColor3f(0.8f*intensity, 0.4f*intensity, 0.1f*intensity);



#endif

			for (i=0 ; i<3 ; i++)

				v[i] = lightorigin[i] - vpn[i]*radius;

			glVertex3fv(v);

			glColor3f(0.0f, 0.0f, 0.0f);

			for (i=16; i>=0; i--) {

				float a = i/16.0f * M_PI*2;

				for (j=0; j<3; j++)

					v[j] =	lightorigin[j] +

							vright[j]*cos(a)*radius +

							vup[j]*sin(a)*radius;

				glVertex3fv(v);

			}

			glEnd();



			// Restore previous matrix! KH

			glPopMatrix();



			glColor3f (1,1,1);

			glDisable (GL_BLEND);

			glEnable (GL_TEXTURE_2D);

			glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

			glDepthMask (1);

		}

	}



Compile and run. Now various glows have been added, and everything looks even prettier, especially in Deathmatch

If you have any problems, let me know.

As I've already said above, and commented in the code this is entirely based on the Unofficial Quake code, so respect to them.

Muff



 
Sign up
Login:
Passwd:
[Remember Me]