via.
bool World : : buildLightmapForPoly ( const Polygon3D *
poly )
String lightmapName ( getLightmapNameForPoly ( poly ) ) ;
(*sysLog) << "Building lightmap " << lightmapName << logEndl;
if ( poly -> getMapping () == NULL || poly -> getTexture () == NULL ) return true;
if ( poly -> testFlag ( PF_PORTAL ) || poly -> testFlag ( PF_MIRROR ) ) return true;
int texwidth = poly -> getTexture () -> getwidth (); int texHeight = poly -> getTexture () -> getHeight ();
// compute range of texture coordinates
// for this poly Vector2D texMin; Vector2D texMax;
poly -> getTextureExtent ( texMin, texMax );
// find middle point Vector2D mid ( 0.5f * (texMin + texMax ) ) ;
texMin.x *= texwidth;
texMin.y *= texHeight;
texMax.x *= texwidth;
texMax.y *= texHeight;
// get size of lightmap intwidth = (int)ceil (texMax.x/STEP) -
(int)floor (texMin.x/STEP) + 1; intheight = (int)ceil (texMax.y/STEP) -
(int)floor (texMin.y/STEP) + 1;
// create texture object to hold lightmap
// with 24 bit format PixelFormat rgbFormat ( OxFF, OxFFOO, OxFFOOOO ); Texture * lightmap = new Texture ( lightmapName, width,
height, rgbFormat ) ,-
// create buffer to encode pixel data long * buf = new long [width];
for ( int i = 0; i < height; i++ ) {
for ( int j =0; j < width; j++ )

Работа с картами освещенности

Vector2D tex;
Vector3D sample;
Vector3D color ( ambient );
tex.x = (texMin.x + j * STEP) / texWidth; tex.y = (texMin.y + i * STEP) / texHeight;
// check whether we can nudge sample // point to lay within poly if ( buildSampleOnPoly ( poly, tex, mid,
sample ) )
{
// now sample is our sample point //on poly, accumulate light on it for ( Array :: Iterator it =
lights . getlterator (),-
lit.end (); ++it )
{
Light * light = (Light *) it.value ();
if ( poly -> isFrontFacing (light -> getPos()) ) if ( pointVisibleFrom (sample,

⇐ Предыдущая| |Следующая ⇒