]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
option -randomsamples: makes -samples use adaptive random subsampling (only subsample...
authorRudolf Polzer <divverent@alientrap.org>
Sun, 3 Oct 2010 18:23:14 +0000 (20:23 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Sun, 3 Oct 2010 18:23:14 +0000 (20:23 +0200)
tools/quake3/q3map2/light.c
tools/quake3/q3map2/light_ydnar.c
tools/quake3/q3map2/q3map2.h

index c072be0c62e88a347580fa1e2bbaa99a21f14450..41bc1dc6e121b2617eda95c72f1c1df1867230a8 100644 (file)
@@ -2245,6 +2245,12 @@ int LightMain( int argc, char **argv )
                        i++;
                }
                
+               else if( !strcmp( argv[ i ], "-randomsamples" ) )
+               {
+                       lightRandomSamples = qtrue;
+                       Sys_Printf( "Random sampling enabled\n", lightRandomSamples );
+               }
+               
                else if( !strcmp( argv[ i ], "-samples" ) )
                {
                        lightSamples = atoi( argv[ i + 1 ] );
index 8ba5a9af8cf2282161dfc3e912369eb74a57b317..3c17d4bb90276fe6a50bf8496c061029a7c437f9 100644 (file)
@@ -1871,6 +1871,45 @@ static void SubsampleRawLuxel_r( rawLightmap_t *lm, trace_t *trace, vec3_t sampl
                lightLuxel[ 3 ] += 1.0f;
        }
 }
+static void RandomSubsampleRawLuxel( rawLightmap_t *lm, trace_t *trace, vec3_t sampleOrigin, int x, int y, float bias, float *lightLuxel )
+{
+       int                     b, samples, mapped;
+       int                     cluster;
+       vec3_t          origin, normal;
+       vec3_t          total;
+       
+       VectorClear( total );
+       mapped = 0;
+       for(b = 0; b < lightSamples; ++b)
+       {
+               /* set origin */
+               VectorCopy( sampleOrigin, origin );
+               
+               /* calculate position */
+               if( !SubmapRawLuxel( lm, x, y, (bias * (2 * Random() - 1)), (bias * (2 * Random() - 1)), &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 );
+       }
+
+       /* add to luxel */
+       if( mapped > 0 )
+       {
+               /* average */
+               lightLuxel[ 0 ] = total[ 0 ] / mapped;
+               lightLuxel[ 1 ] = total[ 1 ] / mapped;
+               lightLuxel[ 2 ] = total[ 2 ] / mapped;
+       }
+}
 
 
 
@@ -2099,7 +2138,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                luxelFilterRadius = 1;
 
                        /* allocate sampling flags storage */
-                       if(lightSamples > 1 && luxelFilterRadius == 0)
+                       if((lightSamples > 1 || lightRandomSamples) && luxelFilterRadius == 0)
                        {
                                size = lm->sw * lm->sh * SUPER_LUXEL_SIZE * sizeof( unsigned char );
                                if(lm->superFlags == NULL)
@@ -2152,7 +2191,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                                        VectorAdd( deluxel, trace.directionContribution, deluxel );
 
                                                /* check for evilness */
-                                               if(trace.forceSubsampling > 1.0f && lightSamples > 1 && luxelFilterRadius == 0)
+                                               if(trace.forceSubsampling > 1.0f && (lightSamples > 1 || lightRandomSamples) && luxelFilterRadius == 0)
                                                {
                                                        totalLighted++;
                                                        *flag |= FLAG_FORCE_SUBSAMPLING; /* force */
@@ -2170,7 +2209,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
                        
                        /* secondary pass, adaptive supersampling (fixme: use a contrast function to determine if subsampling is necessary) */
                        /* 2003-09-27: changed it so filtering disamples supersampling, as it would waste time */
-                       if( lightSamples > 1 && luxelFilterRadius == 0 )
+                       if( (lightSamples > 1 || lightRandomSamples) && luxelFilterRadius == 0 )
                        {
                                /* walk luxels */
                                for( y = 0; y < (lm->sh - 1); y++ )
@@ -2238,7 +2277,10 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                                                //%             continue;
                                                                
                                                                /* subsample it */
-                                                               SubsampleRawLuxel_r( lm, &trace, origin, sx, sy, 0.25f * lightSamplesSearchBoxSize, lightLuxel );
+                                                               if(lightRandomSamples)
+                                                                       RandomSubsampleRawLuxel( lm, &trace, origin, sx, sy, 0.5f, lightLuxel );
+                                                               else
+                                                                       SubsampleRawLuxel_r( lm, &trace, origin, sx, sy, 0.25f * lightSamplesSearchBoxSize, lightLuxel );
 
                                                                *flag |= FLAG_ALREADY_SUBSAMPLED;
                                                                
index 0294be7d7243fc8bfc578a7431557a7be735c65a..b0e5f4725019955b37e7cc080ffa869ae1a38c5e 100644 (file)
@@ -2197,6 +2197,7 @@ Q_EXTERN qboolean                 shade Q_ASSIGN( qfalse );
 Q_EXTERN float                         shadeAngleDegrees Q_ASSIGN( 0.0f );
 Q_EXTERN int                           superSample Q_ASSIGN( 0 );
 Q_EXTERN int                           lightSamples Q_ASSIGN( 1 );
+Q_EXTERN qboolean                      lightRandomSamples Q_ASSIGN( qfalse );
 Q_EXTERN int                           lightSamplesSearchBoxSize Q_ASSIGN( 1 );
 Q_EXTERN qboolean                      filter Q_ASSIGN( qfalse );
 Q_EXTERN qboolean                      dark Q_ASSIGN( qfalse );