nomatrix.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "qrad.h"
  2. // =====================================================================================
  3. // CheckVisBit
  4. // =====================================================================================
  5. #ifdef HLRAD_HULLU
  6. static bool CheckVisBitNoVismatrix(unsigned patchnum1, unsigned patchnum2, vec3_t &transparency_out, unsigned int &)
  7. #else
  8. static bool CheckVisBitNoVismatrix(unsigned patchnum1, unsigned patchnum2)
  9. #endif
  10. {
  11. #ifdef HLRAD_HULLU
  12. // This fix was in vismatrix and sparse methods but not in nomatrix
  13. // Without this nomatrix causes SwapTransfers output lots of errors
  14. if (patchnum1 > patchnum2)
  15. {
  16. const unsigned a = patchnum1;
  17. const unsigned b = patchnum2;
  18. patchnum1 = b;
  19. patchnum2 = a;
  20. }
  21. if (patchnum1 > g_num_patches)
  22. {
  23. Warning("in CheckVisBit(), patchnum1 > num_patches");
  24. }
  25. if (patchnum2 > g_num_patches)
  26. {
  27. Warning("in CheckVisBit(), patchnum2 > num_patches");
  28. }
  29. #endif
  30. patch_t* patch = &g_patches[patchnum1];
  31. patch_t* patch2 = &g_patches[patchnum2];
  32. vec3_t transparency;
  33. #ifdef HLRAD_HULLU
  34. VectorFill(transparency_out, 1.0);
  35. #endif
  36. // if emitter is behind that face plane, skip all patches
  37. if (patch2)
  38. {
  39. const dplane_t* plane2 = getPlaneFromFaceNumber(patch2->faceNumber);
  40. if (DotProduct(patch->origin, plane2->normal) > (PatchPlaneDist(patch2) + MINIMUM_PATCH_DISTANCE))
  41. {
  42. // we need to do a real test
  43. const dplane_t* plane = getPlaneFromFaceNumber(patch->faceNumber);
  44. // check vis between patch and patch2
  45. // if v2 is not behind light plane
  46. // && v2 is visible from v1
  47. #ifdef HLRAD_HULLU
  48. int facenum = TestSegmentAgainstOpaqueList(patch->origin, patch2->origin, transparency);
  49. #else
  50. int facenum = TestSegmentAgainstOpaqueList(patch->origin, patch2->origin);
  51. #endif
  52. if ((facenum < 0 || facenum == patch2->faceNumber)
  53. && (DotProduct(patch2->origin, plane->normal) > (PatchPlaneDist(patch) + MINIMUM_PATCH_DISTANCE))
  54. && (TestLine_r(0, patch->origin, patch2->origin) == CONTENTS_EMPTY))
  55. {
  56. #ifdef HLRAD_HULLU
  57. if(g_customshadow_with_bouncelight)
  58. {
  59. VectorCopy(transparency, transparency_out);
  60. }
  61. #endif
  62. return true;
  63. }
  64. }
  65. }
  66. return false;
  67. }
  68. //
  69. // end old vismat.c
  70. ////////////////////////////
  71. void MakeScalesNoVismatrix()
  72. {
  73. char transferfile[_MAX_PATH];
  74. hlassume(g_num_patches < MAX_PATCHES, assume_MAX_PATCHES);
  75. safe_strncpy(transferfile, g_source, _MAX_PATH);
  76. StripExtension(transferfile);
  77. DefaultExtension(transferfile, ".inc");
  78. if (!g_incremental || !readtransfers(transferfile, g_num_patches))
  79. {
  80. g_CheckVisBit = CheckVisBitNoVismatrix;
  81. #ifndef HLRAD_HULLU
  82. NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);
  83. #else
  84. if(g_rgb_transfers)
  85. {NamedRunThreadsOn(g_num_patches, g_estimate, MakeRGBScales);}
  86. else
  87. {NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);}
  88. #endif
  89. // invert the transfers for gather vs scatter
  90. #ifndef HLRAD_HULLU
  91. NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapTransfers);
  92. #else
  93. if(g_rgb_transfers)
  94. {NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapRGBTransfers);}
  95. else
  96. {NamedRunThreadsOnIndividual(g_num_patches, g_estimate, SwapTransfers);}
  97. #endif
  98. if (g_incremental)
  99. {
  100. writetransfers(transferfile, g_num_patches);
  101. }
  102. else
  103. {
  104. _unlink(transferfile);
  105. }
  106. DumpTransfersMemoryUsage();
  107. }
  108. }