]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
sRGB: also convert vertex colors
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 20 Oct 2011 17:40:31 +0000 (17:40 +0000)
committerRudolf Polzer <divverent@xonotic.org>
Fri, 21 Oct 2011 10:05:45 +0000 (12:05 +0200)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11448 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=526bfd4273b914ea2e47355251f6d932b19f6414

image.c
image.h
model_brush.c

diff --git a/image.c b/image.c
index 5bc83a0089b11ddf1f11c1afb222828fb339008a..c891c3cec939b679f4bac92fc4f105211431e78d 100644 (file)
--- a/image.c
+++ b/image.c
@@ -821,7 +821,7 @@ void Image_MakesRGBColorsFromLinear_Lightmap(unsigned char *pout, const unsigned
        // this math from http://www.opengl.org/registry/specs/EXT/texture_sRGB.txt
        if (!image_srgbfromlinear_lightmap[255])
                for (i = 0;i < 256;i++)
-                       image_srgbfromlinear_lightmap[i] = (unsigned char)bound(0, Image_sRGBFloatFromLinear(i*2) * 128.0f, 255);
+                       image_srgbfromlinear_lightmap[i] = (unsigned char)bound(0, Image_sRGBFloatFromLinear_Lightmap(i) * 256.0f, 255);
        for (i = 0;i < numpixels;i++)
        {
                pout[i*4+0] = image_srgbfromlinear_lightmap[pin[i*4+0]];
diff --git a/image.h b/image.h
index 823ca397e783f5187a09710752a09ef17d9c4db2..8c501c0dafd30c1f69e89a7efed10e04c3fc69ef 100644 (file)
--- a/image.h
+++ b/image.h
@@ -51,6 +51,7 @@ extern cvar_t r_fixtrans_auto;
 
 #define Image_LinearFloatFromsRGB(c) (((c) < 11) ? (c) * 0.000302341331f : (float)pow(((c)*(1.0f/256.0f) + 0.055f)*(1.0f/1.0555f), 2.4f))
 #define Image_sRGBFloatFromLinear(c) (((c) < 1) ? (c) * 0.05046875f : 1.055f * (float)pow((c)*(1.0f/256.0f), 1.0f/2.4f) - 0.055f)
+#define Image_sRGBFloatFromLinear_Lightmap(c) (Image_sRGBFloatFromLinear(c*2.0f)*0.5f)
 
 void Image_MakeLinearColorsFromsRGB(unsigned char *pout, const unsigned char *pin, int numpixels);
 void Image_MakesRGBColorsFromLinear_Lightmap(unsigned char *pout, const unsigned char *pin, int numpixels);
index 8bfee8298d354631332ab90ba3d9d4cf7b8dc9dc..aed624c912120b501efe643f8c15a4472256cf96 100644 (file)
@@ -4724,9 +4724,18 @@ static void Mod_Q3BSP_LoadVertices(lump_t *l)
                loadmodel->brushq3.data_texcoordlightmap2f[i * 2 + 0] = LittleFloat(in->lightmap2f[0]);
                loadmodel->brushq3.data_texcoordlightmap2f[i * 2 + 1] = LittleFloat(in->lightmap2f[1]);
                // svector/tvector are calculated later in face loading
-               loadmodel->brushq3.data_color4f[i * 4 + 0] = in->color4ub[0] * (1.0f / 255.0f);
-               loadmodel->brushq3.data_color4f[i * 4 + 1] = in->color4ub[1] * (1.0f / 255.0f);
-               loadmodel->brushq3.data_color4f[i * 4 + 2] = in->color4ub[2] * (1.0f / 255.0f);
+               if(vid_sRGB.integer && !vid.sRGBcapable3D)
+               {
+                       loadmodel->brushq3.data_color4f[i * 4 + 0] = Image_sRGBFloatFromLinear_Lightmap(in->color4ub[0]);
+                       loadmodel->brushq3.data_color4f[i * 4 + 1] = Image_sRGBFloatFromLinear_Lightmap(in->color4ub[1]);
+                       loadmodel->brushq3.data_color4f[i * 4 + 2] = Image_sRGBFloatFromLinear_Lightmap(in->color4ub[2]);
+               }
+               else
+               {
+                       loadmodel->brushq3.data_color4f[i * 4 + 0] = in->color4ub[0] * (1.0f / 255.0f);
+                       loadmodel->brushq3.data_color4f[i * 4 + 1] = in->color4ub[1] * (1.0f / 255.0f);
+                       loadmodel->brushq3.data_color4f[i * 4 + 2] = in->color4ub[2] * (1.0f / 255.0f);
+               }
                loadmodel->brushq3.data_color4f[i * 4 + 3] = in->color4ub[3] * (1.0f / 255.0f);
                if(in->color4ub[0] != 255 || in->color4ub[1] != 255 || in->color4ub[2] != 255)
                        loadmodel->lit = true;