int R_MarkLightsLeaf( dlight_t *light, int bit, mleaf_t *pLeaf ) { int countMarked = 0; for ( int i = 0; i < pLeaf->dispCount; i++ ) { IDispInfo *pDispInfo = MLeaf_Disaplcement( pLeaf, i ); SurfaceHandle_t parentSurfID = pDispInfo->GetParent(); if ( parentSurfID ) { // Don't redo all this work if we already hit this surface and decided it's lit by this light. msurfacelighting_t *pLighting = SurfaceLighting( parentSurfID ); if( !R_IsDLightAlreadyMarked( pLighting, bit) ) { // Do a different test for displacement surfaces. Vector bmin, bmax; MSurf_DispInfo( parentSurfID )->GetBoundingBox( bmin, bmax ); if ( IsBoxIntersectingSphere(bmin, bmax, light->origin, light->GetRadius()) ) { R_MarkSurfaceDLight( parentSurfID, pLighting, bit ); countMarked++; } } } } SurfaceHandle_t *pHandle = &host_state.worldbrush->marksurfaces[pLeaf->firstmarksurface]; for ( int i = 0; i < pLeaf->nummarksurfaces; i++ ) { SurfaceHandle_t surfID = pHandle[i]; ASSERT_SURF_VALID( surfID ); // only process leaf surfaces if ( MSurf_Flags( surfID ) & SURFDRAW_NODE ) continue; // Don't redo all this work if we already hit this surface and decided it's lit by this light. msurfacelighting_t *pLighting = SurfaceLighting( surfID ); if(R_IsDLightAlreadyMarked(pLighting, bit)) continue; float dist = DotProduct( light->origin, MSurf_Plane( surfID ).normal) - MSurf_Plane( surfID ).dist; if ( dist > light->GetRadius() || dist < -light->GetRadius() ) continue; countMarked += R_TryLightMarkSurface( light, pLighting, surfID, bit ); } return countMarked; }
void R_MarkLightsLeaf( dlight_t *light, int bit, mleaf_t *pLeaf ) { for( CDispIterator it=pLeaf->GetDispIterator(); it.IsValid(); ) { CDispLeafLink *pCur = it.Inc(); // get current displacement surface info IDispInfo *pDispInfo = static_cast<IDispInfo*>( pCur->m_pDispInfo ); int parentSurfID = pDispInfo->GetParent(); if ( parentSurfID ) { // Don't redo all this work if we already hit this surface and decided it's lit by this light. msurfacelighting_t *pLighting = SurfaceLighting( parentSurfID ); if( !R_IsDLightAlreadyMarked( pLighting, bit) ) { // Do a different test for displacement surfaces. Vector bmin, bmax; MSurf_DispInfo( parentSurfID )->GetBoundingBox( bmin, bmax ); if ( SphereToAABBIntersection( light->origin, light->radius, bmin, bmax ) ) { R_MarkSurfaceDLight( pLighting, bit ); } } } } for ( int i = 0; i < pLeaf->nummarksurfaces; i++ ) { int surfID = host_state.worldmodel->brush.marksurfaces[pLeaf->firstmarksurface + i]; ASSERT_SURF_VALID( surfID ); // only process leaf surfaces if ( MSurf_Flags( surfID ) & SURFDRAW_NODE ) continue; // Don't redo all this work if we already hit this surface and decided it's lit by this light. msurfacelighting_t *pLighting = SurfaceLighting( surfID ); if(R_IsDLightAlreadyMarked(pLighting, bit)) continue; float dist = DotProduct( light->origin, MSurf_Plane( surfID ).normal) - MSurf_Plane( surfID ).dist; if ( dist > light->radius || dist < -light->radius ) continue; R_TryLightMarkSurface( light, pLighting, surfID, bit ); } }
/* ============= R_MarkLights ============= */ void R_MarkLights (dlight_t *light, int bit, mnode_t *node) { cplane_t *splitplane; float dist; int i; if (node->contents >= 0) { // This is a leaf, so check displacement surfaces and leaf faces R_MarkLightsLeaf( light, bit, (mleaf_t*)node ); return; } splitplane = node->plane; dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist; if (dist > light->radius) { R_MarkLights (light, bit, node->children[0]); return; } if (dist < -light->radius) { R_MarkLights (light, bit, node->children[1]); return; } // mark the polygons int surfID = node->firstsurface; for (i=0 ; i<node->numsurfaces ; i++, surfID++) { // Don't redo all this work if we already hit this surface and decided it's lit by this light. msurfacelighting_t *pLighting = SurfaceLighting( surfID ); if(R_IsDLightAlreadyMarked( pLighting, bit)) continue; R_TryLightMarkSurface( light, pLighting, surfID, bit ); } R_MarkLights( light, bit, node->children[0] ); R_MarkLights( light, bit, node->children[1] ); }