From 4c13f3153544330f482f9c821b23045c122de375 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 3 Oct 2010 21:14:54 +0200 Subject: [PATCH] use a Gaussian-like random distribution for random subsampling --- tools/quake3/q3map2/light_ydnar.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tools/quake3/q3map2/light_ydnar.c b/tools/quake3/q3map2/light_ydnar.c index 4d32545..393548b 100644 --- a/tools/quake3/q3map2/light_ydnar.c +++ b/tools/quake3/q3map2/light_ydnar.c @@ -1889,12 +1889,27 @@ static void SubsampleRawLuxel_r( rawLightmap_t *lm, trace_t *trace, vec3_t sampl } } } + +/* 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 ); mapped = 0; @@ -1902,9 +1917,14 @@ static void RandomSubsampleRawLuxel( rawLightmap_t *lm, trace_t *trace, vec3_t s { /* set origin */ VectorCopy( sampleOrigin, origin ); - + GaussLikeRandom(bias, &dx, &dy); + if(dx > 1) dx = 1; + if(dy > 1) dy = 1; + if(dx < -1) dx = -1; + if(dy < -1) dy = -1; + /* calculate position */ - if( !SubmapRawLuxel( lm, x, y, (bias * (2 * Random() - 1)), (bias * (2 * Random() - 1)), &cluster, origin, normal ) ) + if( !SubmapRawLuxel( lm, x, y, dx, dy, &cluster, origin, normal ) ) { cluster = -1; continue; -- 2.39.2