]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
introduce a lightmap scale for models, and use this for the sRGB fallback instead...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 25 Nov 2011 11:46:26 +0000 (11:46 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 25 Nov 2011 11:46:26 +0000 (11:46 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11567 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
model_brush.c
model_shared.c
model_shared.h

index 6c26b8de7040514c4269c65a585f824a9255e8cf..28b8efe8cf2415d937307694e9014a18bf3c73e3 100644 (file)
@@ -6682,6 +6682,10 @@ void R_UpdateVariables(void)
        {
                r_refdef.lightmapintensity *= r_fakelight_intensity.value;
        }
+       else if (r_refdef.scene.worldmodel)
+       {
+               r_refdef.lightmapintensity *= r_refdef.scene.worldmodel->lightmapscale;
+       }
        if (r_showsurfaces.integer)
        {
                r_refdef.scene.rtworld = false;
index eca6546481101dedfd507574e689578fe36e6d35..6fceeb8776a766133a8809c83981b0276b8df44b 100644 (file)
@@ -4735,13 +4735,10 @@ static void Mod_Q3BSP_LoadVertices(lump_t *l)
                        // working like this may be odd, but matches q3map2 -gamma 2.2
                        if(vid_sRGB.integer && vid_sRGB_fallback.integer && !vid.sRGB3D)
                        {
-                               // actually we do: Image_sRGBFloatFromLinear_Lightmap(Image_LinearFloatFromsRGBFloat(x))
-                               // neutral point is at Image_sRGBFloatFromLinearFloat(0.5)
-                               // so we need to map Image_sRGBFloatFromLinearFloat(0.5) to 0.5
-                               // factor is 0.5 / Image_sRGBFloatFromLinearFloat(0.5)
-                               loadmodel->brushq3.data_color4f[i * 4 + 0] = in->color4ub[0] * (1.0f / 255.0f) * 0.679942f; // fixes neutral level
-                               loadmodel->brushq3.data_color4f[i * 4 + 1] = in->color4ub[1] * (1.0f / 255.0f) * 0.679942f; // fixes neutral level
-                               loadmodel->brushq3.data_color4f[i * 4 + 2] = in->color4ub[2] * (1.0f / 255.0f) * 0.679942f; // fixes neutral level
+                               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);
+                               // we fix the brightness consistently via lightmapscale
                        }
                        else
                        {
@@ -5055,20 +5052,8 @@ static void Mod_Q3BSP_LoadLightmaps(lump_t *l, lump_t *faceslump)
                                        textype_t t;
                                        if(vid_sRGB.integer && vid_sRGB_fallback.integer && !vid.sRGB3D)
                                        {
-                                               // TODO (should we do this, or should we instead knowingly render brighter in sRGB fallback mode?)
-                                               int n = mergedwidth * mergedheight * 4;
-                                               int i;
-                                               for(i = 0; i < n; i += 4)
-                                               {
-                                                       // actually we do: Image_sRGBFloatFromLinear_Lightmap(Image_LinearFloatFromsRGBFloat(x))
-                                                       // neutral point is at Image_sRGBFloatFromLinearFloat(0.5)
-                                                       // so we need to map Image_sRGBFloatFromLinearFloat(0.5) to 0.5
-                                                       // factor is 0.5 / Image_sRGBFloatFromLinearFloat(0.5)
-                                                       mergedpixels[i+0] = (mergedpixels[i+0] * (int)173 + 128) / 255;
-                                                       mergedpixels[i+1] = (mergedpixels[i+1] * (int)173 + 128) / 255;
-                                                       mergedpixels[i+2] = (mergedpixels[i+2] * (int)173 + 128) / 255;
-                                               }
                                                t = TEXTYPE_BGRA; // in stupid fallback mode, we upload lightmaps in sRGB form and just fix their brightness
+                                               // we fix the brightness consistently via lightmapscale
                                        }
                                        else
                                                t = TEXTYPE_SRGB_BGRA; // normally, we upload lightmaps in sRGB form (possibly downconverted to linear)
@@ -5871,20 +5856,7 @@ static void Mod_Q3BSP_LoadLightGrid(lump_t *l)
                {
                        if(vid_sRGB.integer && vid_sRGB_fallback.integer && !vid.sRGB3D)
                        {
-                               // TODO (should we do this, or should we instead knowingly render brighter in sRGB fallback mode?)
-                               for(i = 0; i < count; ++i)
-                               {
-                                       // actually we do: Image_sRGBFloatFromLinear_Lightmap(Image_LinearFloatFromsRGBFloat(x))
-                                       // neutral point is at Image_sRGBFloatFromLinearFloat(0.5)
-                                       // so we need to map Image_sRGBFloatFromLinearFloat(0.5) to 0.5
-                                       // factor is 0.5 / Image_sRGBFloatFromLinearFloat(0.5)
-                                       out[i].ambientrgb[0] = (out[i].ambientrgb[0] * (int)173 + 128) / 255; // fixes neutral level
-                                       out[i].ambientrgb[1] = (out[i].ambientrgb[1] * (int)173 + 128) / 255; // fixes neutral level
-                                       out[i].ambientrgb[2] = (out[i].ambientrgb[2] * (int)173 + 128) / 255; // fixes neutral level
-                                       out[i].diffusergb[0] = (out[i].diffusergb[0] * (int)173 + 128) / 255; // fixes neutral level
-                                       out[i].diffusergb[1] = (out[i].diffusergb[1] * (int)173 + 128) / 255; // fixes neutral level
-                                       out[i].diffusergb[2] = (out[i].diffusergb[2] * (int)173 + 128) / 255; // fixes neutral level
-                               }
+                               // we fix the brightness consistently via lightmapscale
                        }
                        else
                        {
@@ -7322,6 +7294,15 @@ static void Mod_Q3BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
                        Mod_BuildVBOs();
        }
 
+       if (mod_q3bsp_sRGBlightmaps.integer && vid_sRGB.integer && vid_sRGB_fallback.integer && !vid.sRGB3D)
+       {
+               // actually we do in sRGB fallback with sRGB lightmaps: Image_sRGBFloatFromLinear_Lightmap(Image_LinearFloatFromsRGBFloat(x))
+               // neutral point is at Image_sRGBFloatFromLinearFloat(0.5)
+               // so we need to map Image_sRGBFloatFromLinearFloat(0.5) to 0.5
+               // factor is 0.5 / Image_sRGBFloatFromLinearFloat(0.5)
+               mod->lightmapscale *= 0.679942f; // fixes neutral level
+       }
+
        Con_DPrintf("Stats for q3bsp model \"%s\": %i faces, %i nodes, %i leafs, %i clusters, %i clusterportals, mesh: %i vertices, %i triangles, %i surfaces\n", loadmodel->name, loadmodel->num_surfaces, loadmodel->brush.num_nodes, loadmodel->brush.num_leafs, mod->brush.num_pvsclusters, loadmodel->brush.num_portals, loadmodel->surfmesh.num_vertices, loadmodel->surfmesh.num_triangles, loadmodel->num_surfaces);
 }
 
index 2afe928b13d5daee77c506d932ce7f34550f1ea3..92cf45a5bf30d49f81e4b2c41acb10ddbee65ce9 100644 (file)
@@ -467,6 +467,9 @@ dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk)
        // errors can prevent the corresponding mod->loaded = true;
        mod->loaded = false;
 
+       // default lightmap scale
+       mod->lightmapscale = 1;
+
        // default model radius and bounding box (mainly for missing models)
        mod->radius = 16;
        VectorSet(mod->normalmins, -mod->radius, -mod->radius, -mod->radius);
index 747bec0cfb32b39b703156937e1b638ff1aba4c9..bd292ab094db1396a55e94742ac222881cdd56d5 100644 (file)
@@ -1048,6 +1048,7 @@ typedef struct model_s
 
        // if set, the model contains light information (lightmap, or vertexlight)
        qboolean lit;
+       float lightmapscale;
 }
 dp_model_t;