+/*
+ Modulo1IfNegative()
+ Previously the bias computation was doing:
+
+ while ( f < 0.0f ) {
+ f += 1.0f;
+ }
+
+ That may end in infinite loop in some case.
+ It may also be slower because of useless loops.
+ I don't know what that computation is for.
+ -- illwieckz
+*/
+float Modulo1IfNegative( float f ){
+ return f < 0.0f ? f - floor( f ) : f;
+}
+
/*
*/
qboolean RadSampleImage( byte *pixels, int width, int height, float st[ 2 ], float color[ 4 ] ){
- float sto[ 2 ];
int x, y;
-
/* clear color first */
color[ 0 ] = color[ 1 ] = color[ 2 ] = color[ 3 ] = 255;
return qfalse;
}
- /* bias st */
- sto[ 0 ] = st[ 0 ];
- while ( sto[ 0 ] < 0.0f )
- sto[ 0 ] += 1.0f;
- sto[ 1 ] = st[ 1 ];
- while ( sto[ 1 ] < 0.0f )
- sto[ 1 ] += 1.0f;
-
/* get offsets */
- x = ( (float) width * sto[ 0 ] ) + 0.5f;
+ x = ( (float) width * Modulo1IfNegative( st[ 0 ] ) ) + 0.5f;
x %= width;
- y = ( (float) height * sto[ 1 ] ) + 0.5f;
+ y = ( (float) height * Modulo1IfNegative( st[ 1 ] ) ) + 0.5f;
y %= height;
/* get pixel */
#define SAMPLE_GRANULARITY 6
static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, shaderInfo_t *si, radWinding_t *rw, vec3_t average, vec3_t gradient, int *style ){
- int i, j, k, l, v, x, y, samples, avgcolor;
+ int i, j, k, l, v, x, y, samples, avgcolor, f_superSample;
vec3_t color, mins, maxs;
vec4_t textureColor;
float alpha, alphaI, bf;
/* sample lightmap */
else
{
+ f_superSample = (float)superSample;
/* fracture the winding into a fan (including degenerate tris) */
for ( v = 1; v < ( rw->numVerts - 1 ) && samples < MAX_SAMPLES; v++ )
{
blend[ 0 ] = i;
blend[ 1 ] = j;
blend[ 2 ] = k;
- bf = ( 1.0 / ( blend[ 0 ] + blend[ 1 ] + blend[ 2 ] ) );
+ bf = ( 1.0f / ( blend[ 0 ] + blend[ 1 ] + blend[ 2 ] ) );
VectorScale( blend, bf, blend );
/* create a blended sample */
}
/* get lightmap xy coords */
- x = lightmap[ 0 ] / (float) superSample;
- y = lightmap[ 1 ] / (float) superSample;
+ /* xy = clamp(lightmap/superSample, 0, lm - 1)*/
+ x = lightmap[ 0 ] / f_superSample;
+ y = lightmap[ 1 ] / f_superSample;
+
if ( x < 0 ) {
x = 0;
}
textureColor[ 3 ] = 255;
}
avgcolor = ( textureColor[ 0 ] + textureColor[ 1 ] + textureColor[ 2 ] ) / 3;
- for ( l = 0; l < 3; l++ ){
+ for ( i = 0; i < 3; i++ ){
+ color[ i ] = ( ( textureColor[ i ] * bounceColorRatio + ( avgcolor * ( 1 - bounceColorRatio ) ) ) / 255 ) * ( radLuxel[ i ] / 255 );
+ /*
+ Workaround for https://gitlab.com/xonotic/netradiant/-/issues/182
+ This loop normally uses the l iterator instead of i:
+ for ( l = 0; l < 3; l++ ){
color[ l ] = ( ( textureColor[ l ] * bounceColorRatio + ( avgcolor * ( 1 - bounceColorRatio ) ) ) / 255 ) * ( radLuxel[ l ] / 255 );
+ }
+ */
//Sys_Printf( "%i %i %i %i %i \n", (int) textureColor[ 0 ], (int) textureColor[ 1 ], (int) textureColor[ 2 ], (int) avgcolor, (int) color[ i ] );
}
AddPointToBounds( color, mins, maxs );
}
/* create a light */
- light = safe_malloc( sizeof( *light ) );
- memset( light, 0, sizeof( *light ) );
+ light = safe_malloc0( sizeof( *light ) );
/* attach it */
ThreadLock();
if ( si->backsplashFraction > 0 ) {
/* allocate a new point light */
- splash = safe_malloc( sizeof( *splash ) );
- memset( splash, 0, sizeof( *splash ) );
+ splash = safe_malloc0( sizeof( *splash ) );
splash->next = lights;
lights = splash;