ModelDecal.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifndef __MODELDECAL_H__
  21. #define __MODELDECAL_H__
  22. /*
  23. ===============================================================================
  24. Decals are lightweight primitives for bullet / blood marks on static
  25. geometry. Decals with common materials will be merged together, but
  26. additional decals will be allocated as needed. The material should not
  27. be one that receives lighting, because no interactions are generated
  28. for these lightweight surfaces.
  29. FIXME: Decals on models in portalled off areas do not get freed
  30. until the area becomes visible again.
  31. ===============================================================================
  32. */
  33. static const int NUM_DECAL_BOUNDING_PLANES = 6;
  34. #ifdef ID_PC
  35. static const int MAX_DEFERRED_DECALS = 8;
  36. static const int DEFFERED_DECAL_TIMEOUT = 1000; // don't create a decal if it wasn't visible within the first second
  37. static const int MAX_DECALS = 64;
  38. #else
  39. static const int MAX_DEFERRED_DECALS = 4;
  40. static const int DEFFERED_DECAL_TIMEOUT = 200; // don't create a decal if it wasn't visible within the first 200 milliseconds
  41. static const int MAX_DECALS = 32;
  42. #endif
  43. static const int MAX_DECAL_VERTS = 3 + NUM_DECAL_BOUNDING_PLANES + 3 + 6; // 3 triangle verts clipped NUM_DECAL_BOUNDING_PLANES + 3 times (plus 6 for safety)
  44. static const int MAX_DECAL_INDEXES = ( MAX_DECAL_VERTS - 2 ) * 3;
  45. compile_time_assert( CONST_ISPOWEROFTWO( MAX_DECALS ) );
  46. // the max indices must be a multiple of 2 for copying indices to write-combined memory
  47. compile_time_assert( ( ( MAX_DECAL_INDEXES * sizeof( triIndex_t ) ) & 15 ) == 0 );
  48. struct decalProjectionParms_t {
  49. idPlane boundingPlanes[NUM_DECAL_BOUNDING_PLANES];
  50. idPlane fadePlanes[2];
  51. idPlane textureAxis[2];
  52. idVec3 projectionOrigin;
  53. idBounds projectionBounds;
  54. const idMaterial * material;
  55. float fadeDepth;
  56. int startTime;
  57. bool parallel;
  58. bool force;
  59. };
  60. ALIGNTYPE16 struct decal_t {
  61. ALIGNTYPE16 idDrawVert verts[MAX_DECAL_VERTS];
  62. ALIGNTYPE16 triIndex_t indexes[MAX_DECAL_INDEXES];
  63. float vertDepthFade[MAX_DECAL_VERTS];
  64. int numVerts;
  65. int numIndexes;
  66. int startTime;
  67. const idMaterial * material;
  68. };
  69. class idRenderModelDecal {
  70. public:
  71. idRenderModelDecal();
  72. ~idRenderModelDecal();
  73. // Creates decal projection parameters.
  74. static bool CreateProjectionParms( decalProjectionParms_t &parms, const idFixedWinding &winding, const idVec3 &projectionOrigin, const bool parallel, const float fadeDepth, const idMaterial *material, const int startTime );
  75. // Transform the projection parameters from global space to local.
  76. static void GlobalProjectionParmsToLocal( decalProjectionParms_t &localParms, const decalProjectionParms_t &globalParms, const idVec3 &origin, const idMat3 &axis );
  77. // clear the model for reuse
  78. void ReUse();
  79. // Save the parameters for the renderer front-end to actually create the decal.
  80. void AddDeferredDecal( const decalProjectionParms_t & localParms );
  81. // Creates a decal on the given model.
  82. void CreateDeferredDecals( const idRenderModel *model );
  83. // Remove decals that are completely faded away.
  84. void RemoveFadedDecals( int time );
  85. unsigned int GetNumDecalDrawSurfs();
  86. struct drawSurf_t * CreateDecalDrawSurf( const struct viewEntity_t *space, unsigned int index );
  87. void ReadFromDemoFile( class idDemoFile *f );
  88. void WriteToDemoFile( class idDemoFile *f ) const;
  89. private:
  90. decal_t decals[MAX_DECALS];
  91. unsigned int firstDecal;
  92. unsigned int nextDecal;
  93. decalProjectionParms_t deferredDecals[MAX_DEFERRED_DECALS];
  94. unsigned int firstDeferredDecal;
  95. unsigned int nextDeferredDecal;
  96. const idMaterial * decalMaterials[MAX_DECALS];
  97. unsigned int numDecalMaterials;
  98. void CreateDecalFromWinding( const idWinding &w, const idMaterial *decalMaterial, const idPlane fadePlanes[2], float fadeDepth, int startTime );
  99. void CreateDecal( const idRenderModel *model, const decalProjectionParms_t &localParms );
  100. };
  101. #endif /* !__MODELDECAL_H__ */