/* =============== CG_LightVertex Lights a particular vertex =============== */ static void CG_LightVertex( vec3_t point, byte alpha, byte *rgba ) { int i; vec3_t alight, dlight, lightdir; trap_R_LightForPoint( point, alight, dlight, lightdir ); for( i = 0; i <= 2; i++ ) rgba[ i ] = (int)alight[ i ]; rgba[ 3 ] = alpha; }
/* =============== CG_StartShadowCaster Helper function to add a inverse dynamic light to create shadows for the following models. =============== */ void CG_StartShadowCaster( vec3_t origin, vec3_t mins, vec3_t maxs ) { vec3_t ambientLight, directedLight, lightDir; vec3_t lightPos; trace_t tr; vec3_t traceMins = { -3.0f, -3.0f, -3.0f }; vec3_t traceMaxs = { 3.0f, 3.0f, 3.0f }; float maxLightDist = Distance( maxs, mins ); // find a point to place the light source by tracing in the // average light direction trap_R_LightForPoint( origin, ambientLight, directedLight, lightDir ); VectorMA( origin, 3.0f * maxLightDist, lightDir, lightPos ); CG_Trace( &tr, origin, traceMins, traceMaxs, lightPos, 0, MASK_OPAQUE, 0 ); if( !tr.startsolid ) { VectorCopy( tr.endpos, lightPos ); } trap_R_AddLightToScene( lightPos, 2.0f * Distance( lightPos, origin ), 3.0f, directedLight[0], directedLight[1], directedLight[2], 0, REF_RESTRICT_DLIGHT | REF_INVERSE_DLIGHT ); }