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