@ -6,49 +6,23 @@ bool sample_lightmap(const world_t* world, const face_t* face, const FaceBound&
if ( face - > lightmap < 0 )
if ( face - > lightmap < 0 )
return false ;
return false ;
const unsigned char * lightmap = & world - > lightmap [ face - > lightmap ] ;
const plane_t * plane = & world - > planes [ face - > plane_id ] ;
Vec3 minBounds = ( bounds . lightmapBounds . min / 16 ) . floor ( ) ;
Vec3 maxBounds = ( bounds . lightmapBounds . max / 16 ) . ceil ( ) ;
Vec3 minBounds = ( bounds . worldBounds . min / 16 ) . floor ( ) * 16.f ;
Vec3 maxBounds = ( bounds . worldBounds . max / 16 ) . ceil ( ) * 16.f ;
int width = ( int ) ( ( maxBounds . x - minBounds . x ) * 16.f ) ; // extents[0]
int height = ( int ) ( ( maxBounds . y - minBounds . y ) * 16.f ) ; // extents[1]
int width , height ;
int u , v ;
switch ( plane - > type )
{
case 0 :
case 3 :
// Towards X
width = ( int ) ( maxBounds . y - minBounds . y ) ;
height = ( int ) ( maxBounds . z - minBounds . z ) ;
u = ( int ) ( point . y - minBounds . y ) ;
v = ( int ) ( point . z - minBounds . z ) ;
break ;
case 1 :
case 4 :
// Towards Y
width = ( int ) ( maxBounds . x - minBounds . x ) ;
height = ( int ) ( maxBounds . z - minBounds . z ) ;
u = ( int ) ( point . x - minBounds . x ) ;
v = ( int ) ( point . z - minBounds . z ) ;
break ;
case 2 :
case 5 :
// Towards Z
width = ( int ) ( maxBounds . x - minBounds . x ) ;
height = ( int ) ( maxBounds . y - minBounds . y ) ;
u = ( int ) ( point . x - minBounds . x ) ;
v = ( int ) ( point . y - minBounds . y ) ;
break ;
default :
printf ( " Error: unknown plane type %d \n " , plane - > type ) ;
return 0 ;
}
minBounds = minBounds * 16.f ; // texturemins.xy
Vec3 uv = bounds . lightmapTransform . TransformPoint ( point ) ;
int u = ( int ) ( uv . x - minBounds . x ) ;
int v = ( int ) ( uv . y - minBounds . y ) ;
if ( u < 0 | | v < 0 | | u > width | | v > height )
if ( u < 0 | | v < 0 | | u > width | | v > height )
return false ;
return false ;
* outSample = lightmap [ ( v > > 4 ) * ( width > > 4 ) + ( u > > 4 ) ] ;
const unsigned char * lightmap = & world - > lightmap [ face - > lightmap ] ;
* outSample = lightmap [ ( v > > 4 ) * ( ( width > > 4 ) + 1 ) + ( u > > 4 ) ] ;
return true ;
return true ;
}
}