]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/light_ydnar.c
experimental q3map2 command line option: -sRGB (store lightmaps in sRGB)
[xonotic/netradiant.git] / tools / quake3 / q3map2 / light_ydnar.c
index e1762234393efe247e92d3e94103e0811ec6a7ce..09a8e484090463a80981b0a1bc6d6037f92c05f5 100644 (file)
@@ -44,6 +44,7 @@ ColorToBytes()
 ydnar: moved to here 2001-02-04
 */
 
+#define Image_sRGBFloatFromLinear(c) (((c) < 0.8014848f) ? (c) * 0.05046875f : 1.055f * (float)pow((c)*(1.0f/256.0f), 1.0f/2.4f) - 0.055f)
 void ColorToBytes( const float *color, byte *colorBytes, float scale )
 {
        int             i;
@@ -120,6 +121,14 @@ void ColorToBytes( const float *color, byte *colorBytes, float scale )
        
        /* compensate for ingame overbrighting/bitshifting */
        VectorScale( sample, (1.0f / lightmapCompensate), sample );
+
+       /* sRGB lightmaps */
+       if(lightmapsRGB)
+       {
+               sample[0] = floor(Image_sRGBFloatFromLinear(sample[0]) * 255.0 + 0.5);
+               sample[1] = floor(Image_sRGBFloatFromLinear(sample[1]) * 255.0 + 0.5);
+               sample[2] = floor(Image_sRGBFloatFromLinear(sample[2]) * 255.0 + 0.5);
+       }
        
        /* store it off */
        colorBytes[ 0 ] = sample[ 0 ];
@@ -1157,6 +1166,8 @@ void MapRawLightmap( int rawLightmapNum )
                                                for( mapNonAxial = 0; mapNonAxial < 2; mapNonAxial++ )
                                                {
                                                        /* get drawverts and map first triangle */
+                                                       dv[ 1 ] = &verts[ pw[ r + 1 ] ];
+                                                       dv[ 2 ] = &verts[ pw[ r + 2 ] ];
                                                        MapTriangle( lm, info, dv, mapNonAxial );
                                                        
                                                        /* get drawverts and map second triangle */
@@ -1474,7 +1485,7 @@ float DirtForSample( trace_t *trace )
                        
                        /* trace */
                        TraceLine( trace );
-                       if( trace->opaque )
+                       if( trace->opaque && !(trace->compileFlags & C_SKY) )
                        {
                                VectorSubtract( trace->hit, trace->origin, displacement );
                                gatherDirt += 1.0f - ooDepth * VectorLength( displacement );
@@ -1565,8 +1576,8 @@ void DirtyRawLightmap( int rawLightmapNum )
        trace.recvShadows = lm->recvShadows;
        trace.numSurfaces = lm->numLightSurfaces;
        trace.surfaces = &lightSurfaces[ lm->firstLightSurface ];
-       trace.inhibitRadius = DEFAULT_INHIBIT_RADIUS;
-       trace.testAll = qtrue;
+       trace.inhibitRadius = 0.0f;
+       trace.testAll = qfalse;
        
        /* twosided lighting (may or may not be a good idea for lightmapped stuff) */
        trace.twoSided = qfalse;
@@ -1786,7 +1797,7 @@ static void SubsampleRawLuxel_r( rawLightmap_t *lm, trace_t *trace, vec3_t sampl
        vec3_t          deluxel[ 3 ];
        vec3_t          origin[ 4 ], normal[ 4 ];
        float           biasDirs[ 4 ][ 2 ] = { { -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f }, { 1.0f, 1.0f } };
-       vec3_t          color, direction, total;
+       vec3_t          color, direction = { 0, 0, 0 }, total;
        
        
        /* limit check */
@@ -1859,7 +1870,10 @@ static void SubsampleRawLuxel_r( rawLightmap_t *lm, trace_t *trace, vec3_t sampl
        //%     VectorClear( color );
        //%     samples = 0;
        VectorCopy( lightLuxel, color );
-       VectorCopy( lightDeluxel, direction );
+       if(lightDeluxel)
+       {
+               VectorCopy( lightDeluxel, direction );
+       }
        samples = 1;
        for( b = 0; b < 4; b++ )
        {
@@ -1924,10 +1938,6 @@ 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, dx, dy, &cluster, origin, normal ) )
@@ -2345,7 +2355,7 @@ void IlluminateRawLightmap( int rawLightmapNum )
                                                                
                                                                /* subsample it */
                                                                if(lightRandomSamples)
-                                                                       RandomSubsampleRawLuxel( lm, &trace, origin, sx, sy, 0.5f, lightLuxel, deluxemap ? lightDeluxel : NULL );
+                                                                       RandomSubsampleRawLuxel( lm, &trace, origin, sx, sy, 0.5f * lightSamplesSearchBoxSize, lightLuxel, deluxemap ? lightDeluxel : NULL );
                                                                else
                                                                        SubsampleRawLuxel_r( lm, &trace, origin, sx, sy, 0.25f * lightSamplesSearchBoxSize, lightLuxel, deluxemap ? lightDeluxel : NULL );
 
@@ -3203,7 +3213,7 @@ determines if two clusters are visible to each other using the PVS
 
 qboolean ClusterVisible( int a, int b )
 {
-       int                     portalClusters, leafBytes;
+       int                     leafBytes;
        byte            *pvs;
        
        
@@ -3220,7 +3230,7 @@ qboolean ClusterVisible( int a, int b )
                return qtrue;
        
        /* get pvs data */
-       portalClusters = ((int *) bspVisBytes)[ 0 ];
+       /* portalClusters = ((int *) bspVisBytes)[ 0 ]; */
        leafBytes = ((int*) bspVisBytes)[ 1 ];
        pvs = bspVisBytes + VIS_HEADER_SIZE + (a * leafBytes);
        
@@ -4015,7 +4025,7 @@ void SetupFloodLight( void )
        int             i, j;
        float   angle, elevation, angleStep, elevationStep;
        const char      *value;
-       double v1,v2,v3,v4,v5;
+       double v1,v2,v3,v4,v5,v6;
 
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- SetupFloodLight ---\n" );
@@ -4049,8 +4059,9 @@ void SetupFloodLight( void )
                v1=v2=v3=0;
                v4=floodlightDistance;
                v5=floodlightIntensity;
+               v6=floodlightDirectionScale;
 
-               sscanf( value, "%lf %lf %lf %lf %lf", &v1, &v2, &v3, &v4, &v5);
+               sscanf( value, "%lf %lf %lf %lf %lf %lf", &v1, &v2, &v3, &v4, &v5, &v6);
 
                floodlightRGB[0]=v1;
                floodlightRGB[1]=v2;
@@ -4063,9 +4074,11 @@ void SetupFloodLight( void )
 
                if (v4<1) v4=1024;
                if (v5<1) v5=128;
+               if (v6<0) v6=1;
 
                floodlightDistance=v4;
                floodlightIntensity=v5;
+               floodlightDirectionScale=v6;
 
                floodlighty = qtrue;
                Sys_Printf( "FloodLighting enabled via worldspawn _floodlight key.\n" );
@@ -4160,7 +4173,7 @@ float FloodLightForSample( trace_t *trace , float floodLightDistance, qboolean f
                        TraceLine( trace );
                        contribution=1;
 
-                       if (trace->compileFlags & C_SKY )
+                       if ( trace->compileFlags & C_SKY || trace->compileFlags & C_TRANSLUCENT )
                        {
                                contribution=1.0f;
                        }
@@ -4344,7 +4357,7 @@ void FloodLightRawLightmap( int rawLightmapNum )
 
        /* global pass */
        if (floodlighty && floodlightIntensity)
-               FloodLightRawLightmapPass(lm, floodlightRGB, floodlightIntensity, floodlightDistance, floodlight_lowquality, 1.0f);
+               FloodLightRawLightmapPass(lm, floodlightRGB, floodlightIntensity, floodlightDistance, floodlight_lowquality, floodlightDirectionScale);
 
        /* custom pass */
        if (lm->floodlightIntensity)