]> 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 f291e7a5871da5303bceeb9bb8fc688f1401026a..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 ];