]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light_bounce.c
clang: fix build. Still doesn't work right
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light_bounce.c
index 182494578de048fa2204fb932101da93c03a0808..bf2b63e5293e24cec76eb25dc635e253f786fd5c 100644 (file)
@@ -234,6 +234,13 @@ qboolean RadSampleImage( byte *pixels, int width, int height, float st[ 2 ], flo
        pixels += ( y * width * 4 ) + ( x * 4 );
        VectorCopy( pixels, color );
        color[ 3 ] = pixels[ 3 ];
+
+       if ( texturesRGB ) {
+               color[0] = Image_LinearFloatFromsRGBFloat( color[0] * ( 1.0 / 255.0 ) ) * 255.0;
+               color[1] = Image_LinearFloatFromsRGBFloat( color[1] * ( 1.0 / 255.0 ) ) * 255.0;
+               color[2] = Image_LinearFloatFromsRGBFloat( color[2] * ( 1.0 / 255.0 ) ) * 255.0;
+       }
+
        return qtrue;
 }
 
@@ -257,6 +264,8 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
        float st[ 2 ], lightmap[ 2 ], *radLuxel;
        radVert_t   *rv[ 3 ];
 
+       if (!bouncing)
+               Sys_Printf( "BUG: RadSample: !bouncing shouldn't happen\n" );
 
        /* initial setup */
        ClearBounds( mins, maxs );
@@ -279,7 +288,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
                        /* multiply by texture color */
                        if ( !RadSampleImage( si->lightImage->pixels, si->lightImage->width, si->lightImage->height, rw->verts[ samples ].st, textureColor ) ) {
                                VectorCopy( si->averageColor, textureColor );
-                               textureColor[ 4 ] = 255.0f;
+                               textureColor[ 3 ] = 255.0f;
                        }
                        for ( i = 0; i < 3; i++ )
                                color[ i ] = ( textureColor[ i ] / 255 ) * ( rw->verts[ samples ].color[ lightmapNum ][ i ] / 255.0f );
@@ -363,7 +372,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
                                                /* multiply by texture color */
                                                if ( !RadSampleImage( si->lightImage->pixels, si->lightImage->width, si->lightImage->height, st, textureColor ) ) {
                                                        VectorCopy( si->averageColor, textureColor );
-                                                       textureColor[ 4 ] = 255;
+                                                       textureColor[ 3 ] = 255;
                                                }
                                                for ( i = 0; i < 3; i++ )
                                                        color[ i ] = ( textureColor[ i ] / 255 ) * ( radLuxel[ i ] / 255 );
@@ -417,7 +426,7 @@ static void RadSample( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm,
 
 static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, rawLightmap_t *lm, shaderInfo_t *si,
                                                                          float scale, float subdivide, qboolean original, radWinding_t *rw, clipWork_t *cw ){
-       int i, style;
+       int i, style = 0;
        float dist, area, value;
        vec3_t mins, maxs, normal, d1, d2, cross, color, gradient;
        light_t         *light, *splash;
@@ -544,6 +553,9 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
 
        /* bouncing light? */
        if ( bouncing == qfalse ) {
+               /* This is weird. This actually handles surfacelight and not
+                * bounces. */
+
                /* handle first-pass lights in normal q3a style */
                value = si->value;
                light->photons = value * area * areaScale;
@@ -609,6 +621,9 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
                light->dist = DotProduct( light->origin, normal );
        }
 
+       if (light->photons < 0 || light->add < 0 || light->color[0] < 0 || light->color[1] < 0 || light->color[2] < 0)
+               Sys_Printf( "BUG: RadSubdivideDiffuseLight created a darkbulb\n" );
+
        /* emit light from both sides? */
        if ( si->compileFlags & C_FOG || si->twoSided ) {
                light->flags |= LIGHT_TWOSIDED;
@@ -630,14 +645,12 @@ static void RadSubdivideDiffuseLight( int lightmapNum, bspDrawSurface_t *ds, raw
 void RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw ){
        int i, j, k, v;
        bspDrawSurface_t    *ds;
-       surfaceInfo_t       *info;
        float               *radVertexLuxel;
        radWinding_t rw;
 
 
        /* get surface */
        ds = &bspDrawSurfaces[ num ];
-       info = &surfaceInfos[ num ];
 
        /* each triangle is a potential emitter */
        rw.numVerts = 3;
@@ -840,6 +853,9 @@ void RadLight( int num ){
        contentFlags = surfaceFlags = compileFlags = 0;
        ApplySurfaceParm( "nodraw", &contentFlags, &surfaceFlags, &compileFlags );
 
+       // jal : avoid bouncing on trans surfaces
+       ApplySurfaceParm( "trans", &contentFlags, &surfaceFlags, &compileFlags );
+
        /* early outs? */
        if ( scale <= 0.0f || ( si->compileFlags & C_SKY ) || si->autosprite ||
                 ( bspShaders[ ds->shaderNum ].contentFlags & contentFlags ) || ( bspShaders[ ds->shaderNum ].surfaceFlags & surfaceFlags ) ||