]> icculus.org git repositories - divverent/nexuiz.git/blob - misc/gtkradiant/singlepatches/q3map2-UTtrianglecheck.diff
update the patches: fix unnecessary whitespace at line ends, and update line numbers
[divverent/nexuiz.git] / misc / gtkradiant / singlepatches / q3map2-UTtrianglecheck.diff
1 Index: tools/quake3/q3map2/light_ydnar.c
2 ===================================================================
3 --- tools/quake3/q3map2/light_ydnar.c.orig      2008-09-06 15:32:16.000000000 +0200
4 +++ tools/quake3/q3map2/light_ydnar.c   2008-09-06 15:32:18.000000000 +0200
5 @@ -420,7 +420,7 @@
6  #define NUDGE                  0.5f
7  #define BOGUS_NUDGE            -99999.0f
8  
9 -static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv, vec4_t plane, float pass, vec3_t stv[ 3 ], vec3_t ttv[ 3 ] )
10 +static int MapSingleLuxel( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv, vec4_t plane, float pass, vec3_t stv[ 3 ], vec3_t ttv[ 3 ], vec3_t worldverts[ 3 ] )
11  {
12         int                             i, x, y, numClusters, *clusters, pointCluster, *cluster;
13         float                   *luxel, *origin, *normal, d, lightmapSampleOffset;
14 @@ -428,6 +428,12 @@
15         vec3_t                  pNormal;
16         vec3_t                  vecs[ 3 ];
17         vec3_t                  nudged;
18 +       vec3_t                  cverts[ 3 ];
19 +       vec3_t                  temp;
20 +       vec4_t                  sideplane, hostplane;
21 +       vec3_t                  origintwo;
22 +       int                             j, next;
23 +       float                   e;
24         float                   *nudge;
25         static float    nudges[][ 2 ] =
26                                         {
27 @@ -521,6 +527,51 @@
28         /* non axial lightmap projection (explicit xyz) */
29         else
30                 VectorCopy( dv->xyz, origin );
31 +
32 +       //////////////////////
33 +       //27's test to make sure samples stay within the triangle boundaries
34 +       //1) Test the sample origin to see if it lays on the wrong side of any edge (x/y)
35 +       //2) if it does, nudge it onto the correct side.
36 +
37 +       if (worldverts!=NULL)
38 +       {
39 +               for (j=0;j<3;j++)
40 +               {
41 +                       VectorCopy(worldverts[j],cverts[j]);
42 +               }
43 +               PlaneFromPoints(hostplane,cverts[0],cverts[1],cverts[2]);
44 +
45 +               for (j=0;j<3;j++)
46 +               {
47 +                       for (i=0;i<3;i++)
48 +                       {
49 +                               //build plane using 2 edges and a normal
50 +                               next=(i+1)%3;
51 +
52 +                               VectorCopy(cverts[next],temp);
53 +                               VectorAdd(temp,hostplane,temp);
54 +                               PlaneFromPoints(sideplane,cverts[i],cverts[ next ], temp);
55 +
56 +                               //planetest sample point
57 +                               e=DotProduct(origin,sideplane);
58 +                               e=e-sideplane[3];
59 +                               if (e>0)
60 +                               {
61 +                                       //we're bad.
62 +                                       //VectorClear(origin);
63 +                                       //Move the sample point back inside triangle bounds
64 +                                       origin[0]-=sideplane[0]*(e+1);
65 +                                       origin[1]-=sideplane[1]*(e+1);
66 +                                       origin[2]-=sideplane[2]*(e+1);
67 +#ifdef DEBUG_27_1
68 +                                       VectorClear(origin);
69 +#endif
70 +                               }
71 +                       }
72 +               }
73 +       }
74 +
75 +       ////////////////////////
76         
77         /* planar surfaces have precalculated lightmap vectors for nudging */
78         if( lm->plane != NULL )
79 @@ -552,8 +603,13 @@
80         else
81                 origin[ lm->axisNum ] += lightmapSampleOffset;
82         
83 +       VectorCopy(origin,origintwo);
84 +       origintwo[0]+=vecs[2][0];
85 +       origintwo[1]+=vecs[2][1];
86 +       origintwo[2]+=vecs[2][2];
87 +
88         /* get cluster */
89 -       pointCluster = ClusterForPointExtFilter( origin, LUXEL_EPSILON, numClusters, clusters );
90 +       pointCluster = ClusterForPointExtFilter( origintwo, LUXEL_EPSILON, numClusters, clusters );
91         
92         /* another retarded hack, storing nudge count in luxel[ 1 ] */
93         luxel[ 1 ] = 0.0f;      
94 @@ -569,14 +625,14 @@
95                         for( i = 0; i < 3; i++ )
96                         {
97                                 /* set nudged point*/
98 -                               nudged[ i ] = origin[ i ] + (nudge[ 0 ] * vecs[ 0 ][ i ]) + (nudge[ 1 ] * vecs[ 1 ][ i ]);
99 +                               nudged[ i ] = origintwo[ i ] + (nudge[ 0 ] * vecs[ 0 ][ i ]) + (nudge[ 1 ] * vecs[ 1 ][ i ]);
100                         }
101                         nudge += 2;
102                         
103                         /* get pvs cluster */
104                         pointCluster = ClusterForPointExtFilter( nudged, LUXEL_EPSILON, numClusters, clusters ); //% + 0.625 );
105 -                       if( pointCluster >= 0 ) 
106 -                               VectorCopy( nudged, origin );
107 +                       //if( pointCluster >= 0 )
108 +                       //      VectorCopy( nudged, origin );
109                         luxel[ 1 ] += 1.0f;
110                 }
111         }
112 @@ -586,8 +642,8 @@
113         {
114                 VectorMA( dv->xyz, lightmapSampleOffset, dv->normal, nudged );
115                 pointCluster = ClusterForPointExtFilter( nudged, LUXEL_EPSILON, numClusters, clusters );
116 -               if( pointCluster >= 0 )
117 -                       VectorCopy( nudged, origin );
118 +               //if( pointCluster >= 0 )
119 +               //      VectorCopy( nudged, origin );
120                 luxel[ 1 ] += 1.0f;
121         }
122         
123 @@ -633,7 +689,7 @@
124  than the distance between two luxels (thanks jc :)
125  */
126  
127 -static void MapTriangle_r( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv[ 3 ], vec4_t plane, vec3_t stv[ 3 ], vec3_t ttv[ 3 ] )
128 +static void MapTriangle_r( rawLightmap_t *lm, surfaceInfo_t *info, bspDrawVert_t *dv[ 3 ], vec4_t plane, vec3_t stv[ 3 ], vec3_t ttv[ 3 ], vec3_t worldverts[ 3 ] )
129  {
130         bspDrawVert_t   mid, *dv2[ 3 ];
131         int                             max;
132 @@ -681,7 +737,7 @@
133         
134         /* split the longest edge and map it */
135         LerpDrawVert( dv[ max ], dv[ (max + 1) % 3 ], &mid );
136 -       MapSingleLuxel( lm, info, &mid, plane, 1, stv, ttv );
137 +       MapSingleLuxel( lm, info, &mid, plane, 1, stv, ttv, worldverts );
138         
139         /* push the point up a little bit to account for fp creep (fixme: revisit this) */
140         //%     VectorMA( mid.xyz, 2.0f, mid.normal, mid.xyz );
141 @@ -689,12 +745,12 @@
142         /* recurse to first triangle */
143         VectorCopy( dv, dv2 );
144         dv2[ max ] = &mid;
145 -       MapTriangle_r( lm, info, dv2, plane, stv, ttv );
146 +       MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
147         
148         /* recurse to second triangle */
149         VectorCopy( dv, dv2 );
150         dv2[ (max + 1) % 3 ] = &mid;
151 -       MapTriangle_r( lm, info, dv2, plane, stv, ttv );
152 +       MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
153  }
154  
155  
156 @@ -710,6 +766,7 @@
157         int                             i;
158         vec4_t                  plane;
159         vec3_t                  *stv, *ttv, stvStatic[ 3 ], ttvStatic[ 3 ];
160 +       vec3_t                  worldverts[ 3 ];
161         
162         
163         /* get plane if possible */
164 @@ -735,16 +792,20 @@
165                 ttv = NULL;
166         }
167         
168 +       VectorCopy( dv[ 0 ]->xyz, worldverts[ 0 ] );
169 +       VectorCopy( dv[ 1 ]->xyz, worldverts[ 1 ] );
170 +       VectorCopy( dv[ 2 ]->xyz, worldverts[ 2 ] );
171 +
172         /* map the vertexes */
173 -       MapSingleLuxel( lm, info, dv[ 0 ], plane, 1, stv, ttv );
174 -       MapSingleLuxel( lm, info, dv[ 1 ], plane, 1, stv, ttv );
175 -       MapSingleLuxel( lm, info, dv[ 2 ], plane, 1, stv, ttv );
176 +       MapSingleLuxel( lm, info, dv[ 0 ], plane, 1, stv, ttv, worldverts );
177 +       MapSingleLuxel( lm, info, dv[ 1 ], plane, 1, stv, ttv, worldverts );
178 +       MapSingleLuxel( lm, info, dv[ 2 ], plane, 1, stv, ttv, worldverts );
179         
180         /* 2002-11-20: prefer axial triangle edges */
181         if( mapNonAxial )
182         {
183                 /* subdivide the triangle */
184 -               MapTriangle_r( lm, info, dv, plane, stv, ttv );
185 +               MapTriangle_r( lm, info, dv, plane, stv, ttv, worldverts );
186                 return qtrue;
187         }
188         
189 @@ -766,7 +827,7 @@
190                         dv2[ 2 ] = dv[ (i + 1) % 3 ];
191                         
192                         /* map the degenerate triangle */
193 -                       MapTriangle_r( lm, info, dv2, plane, stv, ttv );
194 +                       MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
195                 }
196         }
197         
198 @@ -828,8 +889,8 @@
199         LerpDrawVert( dv[ max + 2 ], dv[ (max + 3) % 4 ], &mid[ 1 ] );
200         
201         /* map the vertexes */
202 -       MapSingleLuxel( lm, info, &mid[ 0 ], plane, 1, stv, ttv );
203 -       MapSingleLuxel( lm, info, &mid[ 1 ], plane, 1, stv, ttv );
204 +       MapSingleLuxel( lm, info, &mid[ 0 ], plane, 1, stv, ttv, NULL );
205 +       MapSingleLuxel( lm, info, &mid[ 1 ], plane, 1, stv, ttv, NULL );
206         
207         /* 0 and 2 */
208         if( max == 0 )
209 @@ -914,10 +975,10 @@
210         }
211         
212         /* map the vertexes */
213 -       MapSingleLuxel( lm, info, dv[ 0 ], plane, 1, stv, ttv );
214 -       MapSingleLuxel( lm, info, dv[ 1 ], plane, 1, stv, ttv );
215 -       MapSingleLuxel( lm, info, dv[ 2 ], plane, 1, stv, ttv );
216 -       MapSingleLuxel( lm, info, dv[ 3 ], plane, 1, stv, ttv );
217 +       MapSingleLuxel( lm, info, dv[ 0 ], plane, 1, stv, ttv, NULL );
218 +       MapSingleLuxel( lm, info, dv[ 1 ], plane, 1, stv, ttv, NULL );
219 +       MapSingleLuxel( lm, info, dv[ 2 ], plane, 1, stv, ttv, NULL );
220 +       MapSingleLuxel( lm, info, dv[ 3 ], plane, 1, stv, ttv, NULL );
221         
222         /* subdivide the quad */
223         MapQuad_r( lm, info, dv, plane, stv, ttv );
224 @@ -1209,7 +1270,7 @@
225                                         continue;
226                                 
227                                 /* map the fake vert */
228 -                               MapSingleLuxel( lm, NULL, &fake, lm->plane, pass, NULL, NULL );
229 +                               MapSingleLuxel( lm, NULL, &fake, lm->plane, pass, NULL, NULL, NULL );
230                         }
231                 }
232         }
233 @@ -2001,22 +2062,32 @@
234                                         deluxel = SUPER_DELUXEL( x, y );
235                                         origin = SUPER_ORIGIN( x, y );
236                                         normal = SUPER_NORMAL( x, y );
237 -                                       
238 -                                       /* set contribution count */
239 -                                       lightLuxel[ 3 ] = 1.0f;
240 -                                       
241 -                                       /* setup trace */
242 -                                       trace.cluster = *cluster;
243 -                                       VectorCopy( origin, trace.origin );
244 -                                       VectorCopy( normal, trace.normal );
245 -                                       
246 -                                       /* get light for this sample */
247 -                                       LightContributionToSample( &trace );
248 -                                       VectorCopy( trace.color, lightLuxel );
249 -                                       
250 -                                       /* add to count */
251 -                                       if( trace.color[ 0 ] || trace.color[ 1 ] || trace.color[ 2 ] )
252 +
253 +                                       ////////// 27's temp hack for testing edge clipping ////
254 +                                       if( origin[0]==0 && origin[1]==0 && origin[2]==0 )
255 +                                       {
256 +                                               lightLuxel[ 1 ] = 255;
257 +                                               lightLuxel[ 3 ] = 1.0f;
258                                                 totalLighted++;
259 +                                       }
260 +                                       else
261 +                                       {
262 +                                               /* set contribution count */
263 +                                               lightLuxel[ 3 ] = 1.0f;
264 +
265 +                                               /* setup trace */
266 +                                               trace.cluster = *cluster;
267 +                                               VectorCopy( origin, trace.origin );
268 +                                               VectorCopy( normal, trace.normal );
269 +
270 +                                               /* get light for this sample */
271 +                                               LightContributionToSample( &trace );
272 +                                               VectorCopy( trace.color, lightLuxel );
273 +
274 +                                               /* add to count */
275 +                                               if( trace.color[ 0 ] || trace.color[ 1 ] || trace.color[ 2 ] )
276 +                                                       totalLighted++;
277 +                                       }
278                                         
279                                         /* add to light direction map (fixme: use luxel normal as starting point for deluxel?) */
280                                         if( deluxemap )