engine/EngineVideoLights.c
/*	Updated alternative to the above.
	Gets the closest static/dynamic light source, but also checks the lightmap
	sample. If the lightmap sample comes back as dark, then we assume
	there shouldn't be an actual light source.
*/
Updated alternative to the above.
Gets the closest static/dynamic light source, but also checks the lightmap
sample. If the lightmap sample comes back as dark, then we assume
there shouldn't be an actual light source.
Updated alternative to the above . Gets the closest static / dynamic light source but also checks the lightmap sample . If the lightmap sample comes back as dark then we assume there shouldn ' t be an actual light source .
DynamicLight_t *Light_GetDynamic(MathVector3f_t vPoint, bool bCheap)
{
	int				i;
	bool			bStaticLights = true;
	float			fLightAmount;
	DynamicLight_t	*dlClosestLight = NULL;
	MathVector3f_t	vLightColour;
	if (!bCheap)
	{
		Math_MVToVector(Light_GetSample(vPoint), vLightColour);
		fLightAmount = (vLightColour[0] + vLightColour[1] + vLightColour[2]) / 200.0f;
		if (fLightAmount < 0.2f)
			bStaticLights = false;
	}
	for(i = 0; i < MAX_DLIGHTS; i++)
	{
		if (!bStaticLights && !cl_dlights[i].lightmap)
			continue;
		if ((cl_dlights[i].die >= cl.time) || (!cl_dlights[i].lightmap && cl_dlights[i].radius))
		{
			float	fDistance[2];
			vec3_t	vDistance;
			Math_VectorSubtract(vPoint,cl_dlights[i].origin,vDistance);
			fDistance[0] = cl_dlights[i].radius-Math_Length(vDistance);
			if(fDistance[0] > 0)
			{
				if(!dlClosestLight)
					dlClosestLight = &cl_dlights[i];
				else
				{
					Math_VectorSubtract(dlClosestLight->origin,cl_dlights[i].origin,vDistance);
					fDistance[1] = (cl_dlights[i].radius-Math_Length(vDistance));
					if(fDistance[1] < fDistance[0])
						dlClosestLight = &cl_dlights[i];
				}
			}
		}
	}
	return dlClosestLight;
}
DynamicLight_t * Light_GetDynamic ( MathVector3f_t vPoint , bool bCheap ) { int i ; bool bStaticLights = true ; float fLightAmount ; DynamicLight_t * dlClosestLight = NULL ; MathVector3f_t vLightColour ; if ( ! bCheap ) { Math_MVToVector ( Light_GetSample ( vPoint ) , vLightColour ) ; fLightAmount = ( vLightColour [ 0 ] + vLightColour [ 1 ] + vLightColour [ 2 ] ) / 200.0f ; if ( fLightAmount < 0.2f ) bStaticLights = false ; } for ( i = 0 ; i < MAX_DLIGHTS ; i ++ ) { if ( ! bStaticLights && ! cl_dlights [ i ] . lightmap ) continue ; if ( ( cl_dlights [ i ] . die >= cl . time ) || ( ! cl_dlights [ i ] . lightmap && cl_dlights [ i ] . radius ) ) { float fDistance [ 2 ] ; vec3_t vDistance ; Math_VectorSubtract ( vPoint , cl_dlights [ i ] . origin , vDistance ) ; fDistance [ 0 ] = cl_dlights [ i ] . radius - Math_Length ( vDistance ) ; if ( fDistance [ 0 ] > 0 ) { if ( ! dlClosestLight ) dlClosestLight = & cl_dlights [ i ] ; else { Math_VectorSubtract ( dlClosestLight -> origin , cl_dlights [ i ] . origin , vDistance ) ; fDistance [ 1 ] = ( cl_dlights [ i ] . radius - Math_Length ( vDistance ) ) ; if ( fDistance [ 1 ] < fDistance [ 0 ] ) dlClosestLight = & cl_dlights [ i ] ; } } } } return dlClosestLight ; }
Updated alternative to the above.
Updated alternative to the above .
// If cheap, then don't bother with the lightmap checks. // [30/10/2013] Check that we're actually being effected by a lightsource before anything else ~hogsy // [24/2/2014] If we're not being effected by the lightmap then ignore static light sources ~hogsy