]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
fix GLSL compile errors caused by use of * 64 rather than * 64.0 (oops)
[xonotic/darkplaces.git] / model_brush.c
index 6941af6bbe5335c6edd36a1d749960060b834d02..5788727d4c6f4da4f6f6731a26163b92736bda02 100644 (file)
@@ -58,8 +58,6 @@ cvar_t mod_q3shader_force_addalpha = {0, "mod_q3shader_force_addalpha", "0", "tr
 cvar_t mod_q1bsp_polygoncollisions = {0, "mod_q1bsp_polygoncollisions", "0", "disables use of precomputed cliphulls and instead collides with polygons (uses Bounding Interval Hierarchy optimizations)"};
 cvar_t mod_collision_bih = {0, "mod_collision_bih", "1", "enables use of generated Bounding Interval Hierarchy tree instead of compiled bsp tree in collision code"};
 cvar_t mod_recalculatenodeboxes = {0, "mod_recalculatenodeboxes", "1", "enables use of generated node bounding boxes based on BSP tree portal reconstruction, rather than the node boxes supplied by the map compiler"};
-extern cvar_t vid_sRGB;
-extern cvar_t vid_sRGB_fallback;
 
 static texture_t mod_q1bsp_texture_solid;
 static texture_t mod_q1bsp_texture_sky;
@@ -1776,6 +1774,7 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                {
                        tx->supercontents = mod_q1bsp_texture_sky.supercontents;
                        tx->surfaceflags = mod_q1bsp_texture_sky.surfaceflags;
+                       tx->supercontents |= SUPERCONTENTS_SOLID; // for the surface traceline we need to hit this surface as a solid...
                }
                else
                {
@@ -2078,13 +2077,13 @@ static void Mod_Q1BSP_ParseWadsFromEntityLump(const char *data)
        int i, j, k;
        if (!data)
                return;
-       if (!COM_ParseToken_Simple(&data, false, false))
+       if (!COM_ParseToken_Simple(&data, false, false, true))
                return; // error
        if (com_token[0] != '{')
                return; // error
        while (1)
        {
-               if (!COM_ParseToken_Simple(&data, false, false))
+               if (!COM_ParseToken_Simple(&data, false, false, true))
                        return; // error
                if (com_token[0] == '}')
                        break; // end of worldspawn
@@ -2094,7 +2093,7 @@ static void Mod_Q1BSP_ParseWadsFromEntityLump(const char *data)
                        strlcpy(key, com_token, sizeof(key));
                while (key[strlen(key)-1] == ' ') // remove trailing spaces
                        key[strlen(key)-1] = 0;
-               if (!COM_ParseToken_Simple(&data, false, false))
+               if (!COM_ParseToken_Simple(&data, false, false, true))
                        return; // error
                dpsnprintf(value, sizeof(value), "%s", com_token);
                if (!strcmp("wad", key)) // for HalfLife maps
@@ -3064,12 +3063,12 @@ static void Mod_Q1BSP_LoadMapBrushes(void)
        if (!maptext)
                return;
        text = maptext;
-       if (!COM_ParseToken_Simple(&data, false, false))
+       if (!COM_ParseToken_Simple(&data, false, false, true))
                return; // error
        submodel = 0;
        for (;;)
        {
-               if (!COM_ParseToken_Simple(&data, false, false))
+               if (!COM_ParseToken_Simple(&data, false, false, true))
                        break;
                if (com_token[0] != '{')
                        return; // error
@@ -3080,7 +3079,7 @@ static void Mod_Q1BSP_LoadMapBrushes(void)
                brushes = Mem_Alloc(loadmodel->mempool, maxbrushes * sizeof(mbrush_t));
                for (;;)
                {
-                       if (!COM_ParseToken_Simple(&data, false, false))
+                       if (!COM_ParseToken_Simple(&data, false, false, true))
                                return; // error
                        if (com_token[0] == '}')
                                break; // end of entity
@@ -3104,7 +3103,7 @@ static void Mod_Q1BSP_LoadMapBrushes(void)
                                }
                                for (;;)
                                {
-                                       if (!COM_ParseToken_Simple(&data, false, false))
+                                       if (!COM_ParseToken_Simple(&data, false, false, true))
                                                return; // error
                                        if (com_token[0] == '}')
                                                break; // end of brush
@@ -3113,25 +3112,25 @@ static void Mod_Q1BSP_LoadMapBrushes(void)
                                        // FIXME: support hl .map format
                                        for (pointnum = 0;pointnum < 3;pointnum++)
                                        {
-                                               COM_ParseToken_Simple(&data, false, false);
+                                               COM_ParseToken_Simple(&data, false, false, true);
                                                for (componentnum = 0;componentnum < 3;componentnum++)
                                                {
-                                                       COM_ParseToken_Simple(&data, false, false);
+                                                       COM_ParseToken_Simple(&data, false, false, true);
                                                        point[pointnum][componentnum] = atof(com_token);
                                                }
-                                               COM_ParseToken_Simple(&data, false, false);
+                                               COM_ParseToken_Simple(&data, false, false, true);
                                        }
-                                       COM_ParseToken_Simple(&data, false, false);
+                                       COM_ParseToken_Simple(&data, false, false, true);
                                        strlcpy(facetexture, com_token, sizeof(facetexture));
-                                       COM_ParseToken_Simple(&data, false, false);
+                                       COM_ParseToken_Simple(&data, false, false, true);
                                        //scroll_s = atof(com_token);
-                                       COM_ParseToken_Simple(&data, false, false);
+                                       COM_ParseToken_Simple(&data, false, false, true);
                                        //scroll_t = atof(com_token);
-                                       COM_ParseToken_Simple(&data, false, false);
+                                       COM_ParseToken_Simple(&data, false, false, true);
                                        //rotate = atof(com_token);
-                                       COM_ParseToken_Simple(&data, false, false);
+                                       COM_ParseToken_Simple(&data, false, false, true);
                                        //scale_s = atof(com_token);
-                                       COM_ParseToken_Simple(&data, false, false);
+                                       COM_ParseToken_Simple(&data, false, false, true);
                                        //scale_t = atof(com_token);
                                        TriangleNormal(point[0], point[1], point[2], planenormal);
                                        VectorNormalizeDouble(planenormal);
@@ -4454,11 +4453,11 @@ static void Mod_Q3BSP_LoadEntities(lump_t *l)
        // some Q3 maps override the lightgrid_cellsize with a worldspawn key
        // VorteX: q3map2 FS-R generates tangentspace deluxemaps for q3bsp and sets 'deluxeMaps' key
        loadmodel->brushq3.deluxemapping = false;
-       if (data && COM_ParseToken_Simple(&data, false, false) && com_token[0] == '{')
+       if (data && COM_ParseToken_Simple(&data, false, false, true) && com_token[0] == '{')
        {
                while (1)
                {
-                       if (!COM_ParseToken_Simple(&data, false, false))
+                       if (!COM_ParseToken_Simple(&data, false, false, true))
                                break; // error
                        if (com_token[0] == '}')
                                break; // end of worldspawn
@@ -4468,7 +4467,7 @@ static void Mod_Q3BSP_LoadEntities(lump_t *l)
                                strlcpy(key, com_token, sizeof(key));
                        while (key[strlen(key)-1] == ' ') // remove trailing spaces
                                key[strlen(key)-1] = 0;
-                       if (!COM_ParseToken_Simple(&data, false, false))
+                       if (!COM_ParseToken_Simple(&data, false, false, true))
                                break; // error
                        strlcpy(value, com_token, sizeof(value));
                        if (!strcasecmp("gridsize", key)) // this one is case insensitive to 100% match q3map2
@@ -4736,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
                        {
@@ -5056,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)
@@ -5872,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
                        {
@@ -7323,6 +7294,30 @@ static void Mod_Q3BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
                        Mod_BuildVBOs();
        }
 
+       if (mod_q3bsp_sRGBlightmaps.integer)
+       {
+               if (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)
+                       //loadmodel->lightmapscale *= 0.679942f; // fixes neutral level
+               }
+               else // if this is NOT set, regular rendering looks right by this requirement anyway
+               {
+                       /*
+                       // we want color 1 to do the same as without sRGB
+                       // so, we want to map 1 to Image_LinearFloatFromsRGBFloat(2) instead of to 2
+                       loadmodel->lightmapscale *= 2.476923f; // fixes max level
+                       */
+
+                       // neutral level 0.5 gets uploaded as sRGB and becomes Image_LinearFloatFromsRGBFloat(0.5)
+                       // we need to undo that
+                       loadmodel->lightmapscale *= 2.336f; // 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);
 }