1 Index: tools/quake3/q3map2/light_ydnar.c
2 ===================================================================
3 --- tools/quake3/q3map2/light_ydnar.c (revision 191)
4 +++ tools/quake3/q3map2/light_ydnar.c (working copy)
7 #define BOGUS_NUDGE -99999.0f
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 ] )
12 int i, x, y, numClusters, *clusters, pointCluster, *cluster;
13 float *luxel, *origin, *normal, d, lightmapSampleOffset;
20 + vec4_t sideplane, hostplane;
25 static float nudges[][ 2 ] =
28 /* non axial lightmap projection (explicit xyz) */
30 VectorCopy( dv->xyz, origin );
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.
37 + if (worldverts!=NULL)
41 + VectorCopy(worldverts[j],cverts[j]);
43 + PlaneFromPoints(hostplane,cverts[0],cverts[1],cverts[2]);
49 + //build plane using 2 edges and a normal
52 + VectorCopy(cverts[next],temp);
53 + VectorAdd(temp,hostplane,temp);
54 + PlaneFromPoints(sideplane,cverts[i],cverts[ next ], temp);
56 + //planetest sample point
57 + e=DotProduct(origin,sideplane);
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);
68 + VectorClear(origin);
75 + ////////////////////////
77 /* planar surfaces have precalculated lightmap vectors for nudging */
78 if( lm->plane != NULL )
81 origin[ lm->axisNum ] += lightmapSampleOffset;
83 + VectorCopy(origin,origintwo);
84 + origintwo[0]+=vecs[2][0];
85 + origintwo[1]+=vecs[2][1];
86 + origintwo[2]+=vecs[2][2];
89 - pointCluster = ClusterForPointExtFilter( origin, LUXEL_EPSILON, numClusters, clusters );
90 + pointCluster = ClusterForPointExtFilter( origintwo, LUXEL_EPSILON, numClusters, clusters );
92 /* another retarded hack, storing nudge count in luxel[ 1 ] */
95 for( i = 0; i < 3; i++ )
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 ]);
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 );
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 );
124 than the distance between two luxels (thanks jc :)
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 ] )
130 bspDrawVert_t mid, *dv2[ 3 ];
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 );
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 @@ -653,12 +745,12 @@
142 /* recurse to first triangle */
143 VectorCopy( dv, dv2 );
145 - MapTriangle_r( lm, info, dv2, plane, stv, ttv );
146 + MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
148 /* recurse to second triangle */
149 VectorCopy( dv, dv2 );
150 dv2[ (max + 1) % 3 ] = ∣
151 - MapTriangle_r( lm, info, dv2, plane, stv, ttv );
152 + MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
159 vec3_t *stv, *ttv, stvStatic[ 3 ], ttvStatic[ 3 ];
160 + vec3_t worldverts[ 3 ];
163 /* get plane if possible */
164 @@ -699,16 +792,20 @@
168 + VectorCopy( dv[ 0 ]->xyz, worldverts[ 0 ] );
169 + VectorCopy( dv[ 1 ]->xyz, worldverts[ 1 ] );
170 + VectorCopy( dv[ 2 ]->xyz, worldverts[ 2 ] );
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 );
180 /* 2002-11-20: prefer axial triangle edges */
183 /* subdivide the triangle */
184 - MapTriangle_r( lm, info, dv, plane, stv, ttv );
185 + MapTriangle_r( lm, info, dv, plane, stv, ttv, worldverts );
190 dv2[ 2 ] = dv[ (i + 1) % 3 ];
192 /* map the degenerate triangle */
193 - MapTriangle_r( lm, info, dv2, plane, stv, ttv );
194 + MapTriangle_r( lm, info, dv2, plane, stv, ttv, worldverts );
199 LerpDrawVert( dv[ max + 2 ], dv[ (max + 3) % 4 ], &mid[ 1 ] );
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 );
209 @@ -878,10 +975,10 @@
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 );
222 /* subdivide the quad */
223 MapQuad_r( lm, info, dv, plane, stv, ttv );
224 @@ -1173,7 +1270,7 @@
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 );
233 @@ -1963,22 +2062,32 @@
234 deluxel = SUPER_DELUXEL( x, y );
235 origin = SUPER_ORIGIN( x, y );
236 normal = SUPER_NORMAL( x, y );
238 - /* set contribution count */
239 - lightLuxel[ 3 ] = 1.0f;
242 - trace.cluster = *cluster;
243 - VectorCopy( origin, trace.origin );
244 - VectorCopy( normal, trace.normal );
246 - /* get light for this sample */
247 - LightContributionToSample( &trace );
248 - VectorCopy( trace.color, lightLuxel );
251 - if( trace.color[ 0 ] || trace.color[ 1 ] || trace.color[ 2 ] )
253 + ////////// 27's temp hack for testing edge clipping ////
254 + if( origin[0]==0 && origin[1]==0 && origin[2]==0 )
256 + lightLuxel[ 1 ] = 255;
257 + lightLuxel[ 3 ] = 1.0f;
262 + /* set contribution count */
263 + lightLuxel[ 3 ] = 1.0f;
266 + trace.cluster = *cluster;
267 + VectorCopy( origin, trace.origin );
268 + VectorCopy( normal, trace.normal );
270 + /* get light for this sample */
271 + LightContributionToSample( &trace );
272 + VectorCopy( trace.color, lightLuxel );
275 + if( trace.color[ 0 ] || trace.color[ 1 ] || trace.color[ 2 ] )
279 /* add to light direction map (fixme: use luxel normal as starting point for deluxel?) */