protected bool CalculateForPointLight( Plane plane, Vector3[] vertices, out Vector2[] texCoors, out ColorEx[] colors )
{
texCoors = new Vector2[ vertices.Length ];
colors = new ColorEx[ vertices.Length ];
Vector3 lightPos, faceLightPos;
lightPos = this.DerivedPosition;
float dist = plane.GetDistance( lightPos );
if ( Utility.Abs( dist ) < range )
{
// light is visible
//light pos on face
faceLightPos = lightPos - plane.Normal * dist;
Vector3 verAxis = plane.Normal.Perpendicular();
Vector3 horAxis = verAxis.Cross( plane.Normal );
Plane verPlane = new Plane( verAxis, faceLightPos );
Plane horPlane = new Plane( horAxis, faceLightPos );
float lightRadiusSqr = range * range;
float relRadiusSqr = lightRadiusSqr - dist * dist;
float relRadius = Utility.Sqrt( relRadiusSqr );
float scale = 0.5f / relRadius;
float brightness = relRadiusSqr / lightRadiusSqr;
ColorEx lightCol = new ColorEx( brightness * textureColor.a,
textureColor.r, textureColor.g, textureColor.b );
for ( int i = 0; i < vertices.Length; i++ )
{
texCoors[ i ].x = horPlane.GetDistance( vertices[ i ] ) * scale + 0.5f;
texCoors[ i ].y = verPlane.GetDistance( vertices[ i ] ) * scale + 0.5f;
colors[ i ] = lightCol;
}
return true;
}
return false;
}