Tutorial *13*

In this tutorial I'm going to show you how to eliminate shadows on certain objects, i.e. hyper/blaster lasers, grenades, rockets and most importantly, explosions.

Firstly we have to define a rendering flag to use to determine whether an object should cast a shadow. Open up q_shared.h (in the game project), go to the bottom of all the other render flags (RF_MINLIGHT, RF_VIEWERMODEL etc.) and paste this:-



#define RF_NOSHADOW			8192	// Aaron - RF_NOSHADOW

Now we have to implement the flag where GL_DrawAliasShadow is called, and this is in gl_mesh.c (in the ref_gl project) at the bottom (in R_DrawAliasModel.) change the if statement that determines whether shadows should be drawn from:-



if (gl_shadows->value && !(currententity->flags & (RF_TRANSLUCENT | RF_WEAPONMODEL)))

to:



// Aaron - RF_NOSHADOW

if (gl_shadows->value && !(currententity->flags & (RF_TRANSLUCENT | RF_WEAPONMODEL|RF_NOSHADOW)))

This now checks whether any of the entities have the RF_NOSHADOW flag, and if they do it doesn't draw a shadow for that entity.

Now we have to enable the flag for the entities that we don't want a shadow cast from, so back to the game project, go to the fire_blaster function in g_weapon.c, go to the bottom of all the fields set for the bolt (blaster laser) entity and add this:-



bolt->s.renderfx = RF_NOSHADOW; 	// Aaron - RF_NOSHADOW

If you compile now and set gl_shadows to 1, you'll notice that all the models cast a shadow except for the blaster laser and hyper blaster lasers (because it uses the same function). But we're not finished yet. Next go to fire_grenade, and again at the bottom of all the fields add:-



grenade->s.renderfx = RF_NOSHADOW; 	// Aaron - RF_NOSHADOW

Then for rockets, in fire_rocket, at the bottom of the fields add:



rocket->s.renderfx = RF_NOSHADOW; 	// Aaron - RF_NOSHADOW

That's it for all the server side entities, now we have to do the client entities. So, now go to cl_tent.c (where all the temporary entities are setup) and find these bunch of cases:



case TE_EXPLOSION2:

case TE_GRENADE_EXPLOSION:

case TE_GRENADE_EXPLOSION_WATER:

in CL_ParseTEnt. and change:-



ex->ent.flags = RF_FULLBRIGHT;

to:



ex->ent.flags = RF_FULLBRIGHT | RF_NOSHADOW; 	// Aaron - RF_NOSHADOW

and then do the same for:



case TE_PLASMA_EXPLOSION:

case TE_EXPLOSION1:

case TE_EXPLOSION1_BIG:

case TE_ROCKET_EXPLOSION:

case TE_ROCKET_EXPLOSION_WATER:

case TE_EXPLOSION1_NP:

and



case TE_PLAIN_EXPLOSION:

This prevents a shadow from being drawn on any of the explosions (the BFG explosion doesn't need to be set, as it is a sprite and therefore GL_DrawAliasShadow is not being used!) Compile the ref_gl, game and quake2 projects. startup quake2, type gl_shadows 1, and notice that there are no shadows on lasers, grenades, rockets and explosions.. hooray! If you haven't already implemented MrG's shadow tut.. then do it now (especially for those spinning gib shadows, yuk!)

That's it, if you have any questions.. or if there's any problems with the tut, email me at: aaronpaulreeves@yahoo.co.uk



 
Not logged in
Sign up
Login:
Passwd: