+
+ if(lightDeluxel)
+ {
+ direction[ 0 ] /= samples;
+ direction[ 1 ] /= samples;
+ direction[ 2 ] /= samples;
+ VectorCopy( direction, lightDeluxel );
+ }
+ }
+}
+
+/* A mostly Gaussian-like bounded random distribution (sigma is expected standard deviation) */
+static void GaussLikeRandom(float sigma, float *x, float *y)
+{
+ float r;
+ r = Random() * 2 * Q_PI;
+ *x = sigma * 2.73861278752581783822 * cos(r);
+ *y = sigma * 2.73861278752581783822 * sin(r);
+ r = Random();
+ r = 1 - sqrt(r);
+ r = 1 - sqrt(r);
+ *x *= r;
+ *y *= r;
+}
+static void RandomSubsampleRawLuxel( rawLightmap_t *lm, trace_t *trace, vec3_t sampleOrigin, int x, int y, float bias, float *lightLuxel, float *lightDeluxel )
+{
+ int b, mapped;
+ int cluster;
+ vec3_t origin, normal;
+ vec3_t total, totaldirection;
+ float dx, dy;
+
+ VectorClear( total );
+ VectorClear( totaldirection );
+ mapped = 0;
+ for(b = 0; b < lightSamples; ++b)
+ {
+ /* set origin */
+ VectorCopy( sampleOrigin, origin );
+ GaussLikeRandom(bias, &dx, &dy);
+
+ /* calculate position */
+ if( !SubmapRawLuxel( lm, x, y, dx, dy, &cluster, origin, normal ) )
+ {
+ cluster = -1;
+ continue;
+ }
+ mapped++;
+
+ trace->cluster = cluster;
+ VectorCopy( origin, trace->origin );
+ VectorCopy( normal, trace->normal );
+
+ LightContributionToSample( trace );
+ VectorAdd( total, trace->color, total );
+ if(lightDeluxel)
+ {
+ VectorAdd( totaldirection, trace->directionContribution, totaldirection );
+ }
+ }
+
+ /* add to luxel */
+ if( mapped > 0 )
+ {
+ /* average */
+ lightLuxel[ 0 ] = total[ 0 ] / mapped;
+ lightLuxel[ 1 ] = total[ 1 ] / mapped;
+ lightLuxel[ 2 ] = total[ 2 ] / mapped;
+
+ if(lightDeluxel)
+ {
+ lightDeluxel[ 0 ] = totaldirection[ 0 ] / mapped;
+ lightDeluxel[ 1 ] = totaldirection[ 1 ] / mapped;
+ lightDeluxel[ 2 ] = totaldirection[ 2 ] / mapped;
+ }