]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
added trace.realfraction field which is now used for comparisons instead of fraction...
[xonotic/darkplaces.git] / gl_rsurf.c
index 94622dc05d6154f9f84b8b0c9951739d9d7d923d..c05b8794cbcc2680e593f25f6f29abfb79877c93 100644 (file)
@@ -35,7 +35,8 @@ cvar_t r_testvis = {0, "r_testvis", "0"};
 cvar_t r_floatbuildlightmap = {0, "r_floatbuildlightmap", "0"};
 cvar_t r_detailtextures = {CVAR_SAVE, "r_detailtextures", "1"};
 cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "1"};
-cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "-4"};
+cvar_t r_drawcollisionbrushes_polygonfactor = {0, "r_drawcollisionbrushes_polygonfactor", "-1"};
+cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "0"};
 
 static int dlightdivtable[32768];
 
@@ -249,7 +250,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
 
        // set to full bright if no light data
                bl = intblocklights;
-               if ((ent->effects & EF_FULLBRIGHT) || !ent->model->brushq1.lightdata)
+               if (!ent->model->brushq1.lightdata)
                {
                        for (i = 0;i < size3;i++)
                                bl[i] = 255*256;
@@ -337,7 +338,7 @@ static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
 
        // set to full bright if no light data
                bl = floatblocklights;
-               if ((ent->effects & EF_FULLBRIGHT) || !ent->model->brushq1.lightdata)
+               if (!ent->model->brushq1.lightdata)
                        j = 255*256;
                else
                        j = r_ambient.value * 512.0f; // would be 128.0f logically, but using 512.0f to match winquake style
@@ -1232,6 +1233,16 @@ static void RSurfShader_Wall_Lightmap(const entity_render_t *ent, const texture_
                        }
                }
        }
+       else if (ent->effects & EF_FULLBRIGHT)
+       {
+               RSurfShader_OpaqueWall_Pass_BaseTexture(ent, texture, surfchain);
+               if (r_detailtextures.integer)
+                       RSurfShader_OpaqueWall_Pass_BaseDetail(ent, texture, surfchain);
+               if (texture->skin.glow)
+                       RSurfShader_OpaqueWall_Pass_Glow(ent, texture, surfchain);
+               if (fogenabled)
+                       RSurfShader_OpaqueWall_Pass_Fog(ent, texture, surfchain);
+       }
        else if (r_shadow_realtime_world.integer)
        {
                // opaque base lighting
@@ -1786,6 +1797,7 @@ void R_Q3BSP_DrawSkyFace(entity_render_t *ent, q3mface_t *face)
        rmeshstate_t m;
        if (!face->num_triangles)
                return;
+       c_faces++;
        if (skyrendernow)
        {
                skyrendernow = false;
@@ -1877,7 +1889,7 @@ void R_Q3BSP_DrawFace_OpaqueWall_Pass_Lightmap(entity_render_t *ent, q3mface_t *
 {
        rmeshstate_t m;
        memset(&m, 0, sizeof(m));
-       GL_BlendFunc(GL_ONE, GL_SRC_COLOR);
+       GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
        GL_DepthMask(true);
        GL_DepthTest(true);
        m.tex[0] = R_GetTexture(face->lightmaptexture);
@@ -2025,6 +2037,7 @@ void R_Q3BSP_DrawFace(entity_render_t *ent, q3mface_t *face)
                if (face->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW))
                        return;
        }
+       c_faces++;
        face->visframe = r_framecount;
        if ((face->texture->surfaceparms & Q3SURFACEPARM_TRANS) || ent->alpha < 1 || (ent->effects & EF_ADDITIVE))
        {
@@ -2071,19 +2084,42 @@ void R_Q3BSP_RecursiveWorldNode(entity_render_t *ent, q3mnode_t *node, const vec
 {
        int i;
        q3mleaf_t *leaf;
-       while (node->isnode)
+       for (;;)
        {
                if (R_CullBox(node->mins, node->maxs))
                        return;
+               if (!node->plane)
+                       break;
+               c_nodes++;
                R_Q3BSP_RecursiveWorldNode(ent, node->children[0], modelorg, pvs, markframe);
                node = node->children[1];
        }
-       if (R_CullBox(node->mins, node->maxs))
-               return;
        leaf = (q3mleaf_t *)node;
        if (pvs[leaf->clusterindex >> 3] & (1 << (leaf->clusterindex & 7)))
+       {
+               c_leafs++;
                for (i = 0;i < leaf->numleaffaces;i++)
                        leaf->firstleafface[i]->markframe = markframe;
+       }
+}
+
+// FIXME: num_leafs needs to be recalculated at load time to include only
+// node-referenced leafs, as some maps are incorrectly compiled with leafs for
+// the submodels (which would render the submodels occasionally, as part of
+// the world - not good)
+void R_Q3BSP_MarkLeafPVS(entity_render_t *ent, qbyte *pvs, int markframe)
+{
+       int i, j;
+       q3mleaf_t *leaf;
+       for (j = 0, leaf = ent->model->brushq3.data_leafs;j < ent->model->brushq3.num_leafs;j++, leaf++)
+       {
+               if (pvs[leaf->clusterindex >> 3] & (1 << (leaf->clusterindex & 7)))
+               {
+                       c_leafs++;
+                       for (i = 0;i < leaf->numleaffaces;i++)
+                               leaf->firstleafface[i]->markframe = markframe;
+               }
+       }
 }
 
 static int r_q3bsp_framecount = -1;
@@ -2106,6 +2142,7 @@ void R_Q3BSP_DrawSky(entity_render_t *ent)
                        {
                                r_q3bsp_framecount = r_framecount;
                                R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, r_framecount);
+                               //R_Q3BSP_MarkLeafPVS(ent, pvs, r_framecount);
                        }
                        for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
                                if (face->markframe == r_framecount && (face->texture->surfaceflags & Q3SURFACEFLAG_SKY) && !R_CullBox(face->mins, face->maxs))
@@ -2136,6 +2173,7 @@ void R_Q3BSP_Draw(entity_render_t *ent)
                        {
                                r_q3bsp_framecount = r_framecount;
                                R_Q3BSP_RecursiveWorldNode(ent, model->brushq3.data_nodes, modelorg, pvs, r_framecount);
+                               //R_Q3BSP_MarkLeafPVS(ent, pvs, r_framecount);
                        }
                        for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
                                if (face->markframe == r_framecount && !R_CullBox(face->mins, face->maxs))
@@ -2153,9 +2191,11 @@ void R_Q3BSP_Draw(entity_render_t *ent)
                GL_DepthMask(false);
                GL_DepthTest(true);
                R_Mesh_State_Texture(&m);
+               qglPolygonOffset(r_drawcollisionbrushes_polygonfactor.value, r_drawcollisionbrushes_polygonoffset.value);
                for (i = 0;i < model->brushq3.data_thismodel->numbrushes;i++)
                        if (model->brushq3.data_thismodel->firstbrush[i].colbrushf && model->brushq3.data_thismodel->firstbrush[i].colbrushf->numtriangles)
                                R_DrawCollisionBrush(model->brushq3.data_thismodel->firstbrush[i].colbrushf);
+               qglPolygonOffset(0, 0);
        }
 }
 
@@ -2248,6 +2288,7 @@ void GL_Surf_Init(void)
        Cvar_RegisterVariable(&r_floatbuildlightmap);
        Cvar_RegisterVariable(&r_detailtextures);
        Cvar_RegisterVariable(&r_surfaceworldnode);
+       Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor);
        Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);
 
        R_RegisterModule("GL_Surf", gl_surf_start, gl_surf_shutdown, gl_surf_newmap);