}
}
+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;
*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)
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)"};
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);
{
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
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)