]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
illuminated surfaces are now sorted by texture, giving a good fps
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 14 Nov 2010 13:24:27 +0000 (13:24 +0000)
committerRudolf Polzer <divverent@alientrap.org>
Fri, 19 Nov 2010 12:33:49 +0000 (13:33 +0100)
increase, especially in realtime world lighting, this can be turned off
with the r_shadow_sortsurfaces cvar if desired

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10599 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=14b5649a2b45037ad244a2d2c2dcae6049fc6ce6

gl_rsurf.c
r_shadow.c

index 8027d9605083793fee7e6889df3498b091d5a78a..49754e4d83ab95246a496af529becd6119c3cad5 100644 (file)
@@ -951,6 +951,23 @@ static void R_Q1BSP_CallRecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, qboo
        }
 }
 
+static msurface_t *r_q1bsp_getlightinfo_surfaces;
+
+int R_Q1BSP_GetLightInfo_comparefunc(const void *ap, const void *bp)
+{
+       int a = *(int*)ap;
+       int b = *(int*)bp;
+       const msurface_t *as = r_q1bsp_getlightinfo_surfaces + a;
+       const msurface_t *bs = r_q1bsp_getlightinfo_surfaces + b;
+       if (as->texture < bs->texture)
+               return -1;
+       if (as->texture > bs->texture)
+               return 1;
+       return a - b;
+}
+
+extern cvar_t r_shadow_sortsurfaces;
+
 void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outleaflist, unsigned char *outleafpvs, int *outnumleafspointer, int *outsurfacelist, unsigned char *outsurfacepvs, int *outnumsurfacespointer, unsigned char *outshadowtrispvs, unsigned char *outlighttrispvs, unsigned char *visitingleafpvs, int numfrustumplanes, const mplane_t *frustumplanes)
 {
        r_q1bsp_getlightinfo_t info;
@@ -1029,6 +1046,11 @@ void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
 
        *outnumleafspointer = info.outnumleafs;
        *outnumsurfacespointer = info.outnumsurfaces;
+
+       // now sort surfaces by texture for faster rendering
+       r_q1bsp_getlightinfo_surfaces = info.model->data_surfaces;
+       if (r_shadow_sortsurfaces.integer)
+               qsort(info.outsurfacelist, info.outnumsurfaces, sizeof(*info.outsurfacelist), R_Q1BSP_GetLightInfo_comparefunc);
 }
 
 void R_Q1BSP_CompileShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativelightdirection, float lightradius, int numsurfaces, const int *surfacelist)
index 654cfa91b2e9c279aa67060cac0ac95f1966ed06..1d22d930fc50fd53fd17ecaccc33fbc712e88de9 100644 (file)
@@ -317,6 +317,7 @@ cvar_t r_shadow_shadowmapping_nearclip = {CVAR_SAVE, "r_shadow_shadowmapping_nea
 cvar_t r_shadow_shadowmapping_bias = {CVAR_SAVE, "r_shadow_shadowmapping_bias", "0.03", "shadowmap bias parameter (this is multiplied by nearclip * 1024 / lodsize)"};
 cvar_t r_shadow_shadowmapping_polygonfactor = {CVAR_SAVE, "r_shadow_shadowmapping_polygonfactor", "2", "slope-dependent shadowmapping bias"};
 cvar_t r_shadow_shadowmapping_polygonoffset = {CVAR_SAVE, "r_shadow_shadowmapping_polygonoffset", "0", "constant shadowmapping bias"};
+cvar_t r_shadow_sortsurfaces = {0, "r_shadow_sortsurfaces", "1", "improve performance by sorting illuminated surfaces by texture"};
 cvar_t r_shadow_polygonfactor = {0, "r_shadow_polygonfactor", "0", "how much to enlarge shadow volume polygons when rendering (should be 0!)"};
 cvar_t r_shadow_polygonoffset = {0, "r_shadow_polygonoffset", "1", "how much to push shadow volumes into the distance when rendering, to reduce chances of zfighting artifacts (should not be less than 0)"};
 cvar_t r_shadow_texture3d = {0, "r_shadow_texture3d", "1", "use 3D voxel textures for spherical attenuation rather than cylindrical (does not affect OpenGL 2.0 render path)"};
@@ -718,6 +719,7 @@ void R_Shadow_Init(void)
        Cvar_RegisterVariable(&r_shadow_shadowmapping_bias);
        Cvar_RegisterVariable(&r_shadow_shadowmapping_polygonfactor);
        Cvar_RegisterVariable(&r_shadow_shadowmapping_polygonoffset);
+       Cvar_RegisterVariable(&r_shadow_sortsurfaces);
        Cvar_RegisterVariable(&r_shadow_polygonfactor);
        Cvar_RegisterVariable(&r_shadow_polygonoffset);
        Cvar_RegisterVariable(&r_shadow_texture3d);
@@ -3941,7 +3943,7 @@ void R_Shadow_DrawPrepass(void)
        {
                lightindex = r_shadow_debuglight.integer;
                light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
-               if (light && (light->flags & flag))
+               if (light && (light->flags & flag) && light->rtlight.draw)
                        R_Shadow_DrawLight(&light->rtlight);
        }
        else
@@ -3950,13 +3952,14 @@ void R_Shadow_DrawPrepass(void)
                for (lightindex = 0;lightindex < range;lightindex++)
                {
                        light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
-                       if (light && (light->flags & flag))
+                       if (light && (light->flags & flag) && light->rtlight.draw)
                                R_Shadow_DrawLight(&light->rtlight);
                }
        }
        if (r_refdef.scene.rtdlight)
                for (lnum = 0;lnum < r_refdef.scene.numlights;lnum++)
-                       R_Shadow_DrawLight(r_refdef.scene.lights[lnum]);
+                       if (r_refdef.scene.lights[lnum]->draw)
+                               R_Shadow_DrawLight(r_refdef.scene.lights[lnum]);
 
        qglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);CHECKGLERROR
        if (r_refdef.fogenabled)