DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

StaticShadowVolume.cpp (4349B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #include "StaticShadowVolume_local.h"
     30 
     31 /*
     32 ===================
     33 StaticShadowVolumeJob
     34 ===================
     35 */
     36 void StaticShadowVolumeJob( const staticShadowVolumeParms_t * parms ) {
     37 	if ( parms->tempCullBits == NULL ) {
     38 		*const_cast< byte ** >( &parms->tempCullBits ) = (byte *)_alloca16( TEMP_CULLBITS( parms->numVerts ) );
     39 	}
     40 
     41 	// Calculate the shadow depth bounds.
     42 	float shadowZMin = parms->lightZMin;
     43 	float shadowZMax = parms->lightZMax;
     44 	if ( parms->useShadowDepthBounds ) {
     45 		idRenderMatrix::DepthBoundsForShadowBounds( shadowZMin, shadowZMax, parms->triangleMVP, parms->triangleBounds, parms->localLightOrigin, true );
     46 		shadowZMin = Max( shadowZMin, parms->lightZMin );
     47 		shadowZMax = Min( shadowZMax, parms->lightZMax );
     48 	}
     49 
     50 	bool renderZFail = false;
     51 	int numShadowIndices = 0;
     52 
     53 	// The shadow volume may be depth culled if either the shadow volume was culled to the view frustum or if the
     54 	// depth range of the visible part of the shadow volume is outside the depth range of the light volume.
     55 	if ( shadowZMin < shadowZMax ) {
     56 		// Check if we need to render the shadow volume with Z-fail.
     57 		// If the view is potentially inside the shadow volume bounds we may need to render with Z-fail.
     58 		if ( R_ViewPotentiallyInsideInfiniteShadowVolume( parms->triangleBounds, parms->localLightOrigin, parms->localViewOrigin, parms->zNear * INSIDE_SHADOW_VOLUME_EXTRA_STRETCH ) ) {
     59 			// Optionally perform a more precise test to see whether or not the view is inside the shadow volume.
     60 			if ( parms->useShadowPreciseInsideTest && parms->verts != NULL && parms->indexes != NULL ) {
     61 				renderZFail = R_ViewInsideShadowVolume( parms->tempCullBits, parms->verts, parms->numVerts, parms->indexes, parms->numIndexes,
     62 																parms->localLightOrigin, parms->localViewOrigin, parms->zNear * INSIDE_SHADOW_VOLUME_EXTRA_STRETCH );
     63 			} else {
     64 				renderZFail = true;
     65 			}
     66 		}
     67 
     68 		// Check if we can avoid rendering the shadow volume caps.
     69 		numShadowIndices = ( parms->forceShadowCaps || renderZFail ) ? parms->numShadowIndicesWithCaps : parms->numShadowIndicesNoCaps;
     70 	}
     71 
     72 	// write out the number of shadow indices
     73 	if ( parms->numShadowIndices != NULL ) {
     74 		*parms->numShadowIndices = numShadowIndices;
     75 	}
     76 	// write out whether or not the shadow volume needs to be rendered with Z-Fail
     77 	if ( parms->renderZFail != NULL ) {
     78 		*parms->renderZFail = renderZFail;
     79 	}
     80 	// write out the shadow depth bounds
     81 	if ( parms->shadowZMin != NULL ) {
     82 		*parms->shadowZMin = shadowZMin;
     83 	}
     84 	if ( parms->shadowZMax != NULL ) {
     85 		*parms->shadowZMax = shadowZMax;
     86 	}
     87 	// write out the shadow volume state
     88 	if ( parms->shadowVolumeState != NULL ) {
     89 		*parms->shadowVolumeState = SHADOWVOLUME_DONE;
     90 	}
     91 }
     92 
     93 REGISTER_PARALLEL_JOB( StaticShadowVolumeJob, "StaticShadowVolumeJob" );