From 526bfd4273b914ea2e47355251f6d932b19f6414 Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 20 Oct 2011 17:40:31 +0000 Subject: [PATCH] sRGB: also convert vertex colors git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11448 d7cf8633-e32d-0410-b094-e92efae38249 --- image.c | 2 +- image.h | 1 + model_brush.c | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/image.c b/image.c index 5bc83a00..c891c3ce 100644 --- 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 823ca397..8c501c0d 100644 --- 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); diff --git a/model_brush.c b/model_brush.c index 8bfee829..aed624c9 100644 --- a/model_brush.c +++ b/model_brush.c @@ -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; -- 2.39.2