PreLightShadowVolume.cpp 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "PreLightShadowVolume_local.h"
  21. /*
  22. ===================
  23. PreLightShadowVolumeJob
  24. ===================
  25. */
  26. void PreLightShadowVolumeJob( const preLightShadowVolumeParms_t * parms ) {
  27. if ( parms->tempCullBits == NULL ) {
  28. *const_cast< byte ** >( &parms->tempCullBits ) = (byte *)_alloca16( TEMP_CULLBITS( parms->numVerts ) );
  29. }
  30. // Calculate the shadow depth bounds.
  31. float shadowZMin = parms->lightZMin;
  32. float shadowZMax = parms->lightZMax;
  33. if ( parms->useShadowDepthBounds ) {
  34. // NOTE: pre-light shadow volumes typically cover the whole light volume so
  35. // there is no real point in trying to calculate tighter depth bounds here
  36. shadowZMin = Max( shadowZMin, parms->lightZMin );
  37. shadowZMax = Min( shadowZMax, parms->lightZMax );
  38. }
  39. bool renderZFail = false;
  40. int numShadowIndices = 0;
  41. // The shadow volume may be depth culled if either the shadow volume was culled to the view frustum or if the
  42. // depth range of the visible part of the shadow volume is outside the depth range of the light volume.
  43. if ( shadowZMin < shadowZMax ) {
  44. // Check if we need to render the shadow volume with Z-fail.
  45. // If the view is potentially inside the shadow volume bounds we may need to render with Z-fail.
  46. if ( parms->triangleBounds.Expand( parms->zNear * INSIDE_SHADOW_VOLUME_EXTRA_STRETCH ).ContainsPoint( parms->localViewOrigin ) ) {
  47. // Optionally perform a more precise test to see whether or not the view is inside the shadow volume.
  48. if ( parms->useShadowPreciseInsideTest && parms->verts != NULL && parms->indexes != NULL ) {
  49. renderZFail = R_ViewInsideShadowVolume( parms->tempCullBits, parms->verts, parms->numVerts, parms->indexes, parms->numIndexes,
  50. parms->localLightOrigin, parms->localViewOrigin, parms->zNear * INSIDE_SHADOW_VOLUME_EXTRA_STRETCH );
  51. } else {
  52. renderZFail = true;
  53. }
  54. }
  55. // must always draw the caps because pre-light shadows do not project to infinity
  56. numShadowIndices = parms->numIndexes;
  57. }
  58. // write out the number of shadow indices
  59. if ( parms->numShadowIndices != NULL ) {
  60. *parms->numShadowIndices = numShadowIndices;
  61. }
  62. // write out whether or not the shadow volume needs to be rendered with Z-Fail
  63. if ( parms->renderZFail != NULL ) {
  64. *parms->renderZFail = renderZFail;
  65. }
  66. // write out the shadow depth bounds
  67. if ( parms->shadowZMin != NULL ) {
  68. *parms->shadowZMin = shadowZMin;
  69. }
  70. if ( parms->shadowZMax != NULL ) {
  71. *parms->shadowZMax = shadowZMax;
  72. }
  73. // write out the shadow volume state
  74. if ( parms->shadowVolumeState != NULL ) {
  75. *parms->shadowVolumeState = SHADOWVOLUME_DONE;
  76. }
  77. }
  78. REGISTER_PARALLEL_JOB( PreLightShadowVolumeJob, "PreLightShadowVolumeJob" );