Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// Computes ambient lighting along a specified ray.
//-----------------------------------------------------------------------------
void CalcRayAmbientLighting(
	const Vector &vStart,
	const Vector &vEnd,
	Vector color[MAX_LIGHTSTYLES],
	Vector &colorSum )
{
	Ray_t ray;
	ray.Init( vStart, vEnd, vec3_origin, vec3_origin );

	directlight_t *pSkyLight = FindAmbientSkyLight();

	colorSum.Init();

	CLightSurface surfEnum;
	if (!surfEnum.FindIntersection( ray ))
		return;

	// This is the faster path; it looks slightly different though
	if (surfEnum.m_pSurface->dispinfo == -1)
	{
		ComputeLightmapColorFromAverage( surfEnum.m_pSurface, pSkyLight, color, colorSum );
	}
	else
	{
		ComputeLightmapColorDisplacement( surfEnum.m_pSurface, pSkyLight, surfEnum.m_LuxelCoord, color, colorSum );
	}
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Computes ambient lighting along a specified ray.  
// Ray represents a cone, tanTheta is the tan of the inner cone angle
//-----------------------------------------------------------------------------
void CalcRayAmbientLighting( int iThread, const Vector &vStart, const Vector &vEnd, float tanTheta, Vector color[MAX_LIGHTSTYLES] )
{
	Ray_t ray;
	ray.Init( vStart, vEnd, vec3_origin, vec3_origin );

	directlight_t *pSkyLight = FindAmbientSkyLight();

	CLightSurface surfEnum(iThread);
	if (!surfEnum.FindIntersection( ray ))
		return;

	// compute the approximate radius of a circle centered around the intersection point
	float dist = ray.m_Delta.Length() * tanTheta * surfEnum.m_HitFrac;

	// until 20" we use the point sample, then blend in the average until we're covering 40"
	// This is attempting to model the ray as a cone - in the ideal case we'd simply sample all
	// luxels in the intersection of the cone with the surface.  Since we don't have surface 
	// neighbor information computed we'll just approximate that sampling with a blend between
	// a point sample and the face average.
	// This yields results that are similar in that aliasing is reduced at distance while 
	// point samples provide accuracy for intersections with near geometry
	float scaleAvg = RemapValClamped( dist, 20, 40, 0.0f, 1.0f );

	if ( !surfEnum.m_bHasLuxel )
	{
		// don't have luxel UV, so just use average sample
		scaleAvg = 1.0;
	}
	float scaleSample = 1.0f - scaleAvg;

	if (scaleAvg != 0)
	{
		ComputeLightmapColorFromAverage( surfEnum.m_pSurface, pSkyLight, scaleAvg, color );
	}
	if (scaleSample != 0)
	{
		ComputeLightmapColorPointSample( surfEnum.m_pSurface, pSkyLight, surfEnum.m_LuxelCoord, scaleSample, color );
	}
}