int vertexupdatenum;
int r_shadow_buffer_numleafpvsbytes;
+unsigned char *r_shadow_buffer_visitingleafpvs;
unsigned char *r_shadow_buffer_leafpvs;
int *r_shadow_buffer_leaflist;
cvar_t r_shadow_gloss2intensity = {0, "r_shadow_gloss2intensity", "0.125", "how bright the forced flat gloss should look if r_shadow_gloss is 2"};
cvar_t r_shadow_glossintensity = {0, "r_shadow_glossintensity", "1", "how bright textured glossmaps should look if r_shadow_gloss is 1 or 2"};
cvar_t r_shadow_glossexponent = {0, "r_shadow_glossexponent", "32", "how 'sharp' the gloss should appear (specular power)"};
+cvar_t r_shadow_glossexact = {0, "r_shadow_glossexact", "1", "use exact reflection math for gloss (slightly slower, but should look a tad better)"};
cvar_t r_shadow_lightattenuationdividebias = {0, "r_shadow_lightattenuationdividebias", "1", "changes attenuation texture generation"};
cvar_t r_shadow_lightattenuationlinearscale = {0, "r_shadow_lightattenuationlinearscale", "2", "changes attenuation texture generation"};
cvar_t r_shadow_lightintensityscale = {0, "r_shadow_lightintensityscale", "1", "renders all world lights brighter or darker"};
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 r_glsl lighting)"};
cvar_t r_coronas = {CVAR_SAVE, "r_coronas", "1", "brightness of corona flare effects around certain lights, 0 disables corona effects"};
+cvar_t r_coronas_occlusionsizescale = {CVAR_SAVE, "r_coronas_occlusionsizescale", "0.1", "size of light source for corona occlusion checksm the proportion of hidden pixels controls corona intensity"};
+cvar_t r_coronas_occlusionquery = {CVAR_SAVE, "r_coronas_occlusionquery", "1", "use GL_ARB_occlusion_query extension if supported (fades coronas according to visibility)"};
cvar_t gl_flashblend = {CVAR_SAVE, "gl_flashblend", "0", "render bright coronas for dynamic lights instead of actual lighting, fast but ugly"};
cvar_t gl_ext_separatestencil = {0, "gl_ext_separatestencil", "1", "make use of OpenGL 2.0 glStencilOpSeparate or GL_ATI_separate_stencil extension"};
cvar_t gl_ext_stenciltwoside = {0, "gl_ext_stenciltwoside", "1", "make use of GL_EXT_stenciltwoside extension (NVIDIA only)"};
shadowmarklist = NULL;
shadowmarkcount = 0;
r_shadow_buffer_numleafpvsbytes = 0;
+ r_shadow_buffer_visitingleafpvs = NULL;
r_shadow_buffer_leafpvs = NULL;
r_shadow_buffer_leaflist = NULL;
r_shadow_buffer_numsurfacepvsbytes = 0;
shadowmarklist = NULL;
shadowmarkcount = 0;
r_shadow_buffer_numleafpvsbytes = 0;
+ if (r_shadow_buffer_visitingleafpvs)
+ Mem_Free(r_shadow_buffer_visitingleafpvs);
+ r_shadow_buffer_visitingleafpvs = NULL;
if (r_shadow_buffer_leafpvs)
Mem_Free(r_shadow_buffer_leafpvs);
r_shadow_buffer_leafpvs = NULL;
Cvar_RegisterVariable(&r_shadow_gloss2intensity);
Cvar_RegisterVariable(&r_shadow_glossintensity);
Cvar_RegisterVariable(&r_shadow_glossexponent);
+ Cvar_RegisterVariable(&r_shadow_glossexact);
Cvar_RegisterVariable(&r_shadow_lightattenuationdividebias);
Cvar_RegisterVariable(&r_shadow_lightattenuationlinearscale);
Cvar_RegisterVariable(&r_shadow_lightintensityscale);
Cvar_RegisterVariable(&r_shadow_polygonoffset);
Cvar_RegisterVariable(&r_shadow_texture3d);
Cvar_RegisterVariable(&r_coronas);
+ Cvar_RegisterVariable(&r_coronas_occlusionsizescale);
+ Cvar_RegisterVariable(&r_coronas_occlusionquery);
Cvar_RegisterVariable(&gl_flashblend);
Cvar_RegisterVariable(&gl_ext_separatestencil);
Cvar_RegisterVariable(&gl_ext_stenciltwoside);
shadowmarklist = NULL;
shadowmarkcount = 0;
r_shadow_buffer_numleafpvsbytes = 0;
+ r_shadow_buffer_visitingleafpvs = NULL;
r_shadow_buffer_leafpvs = NULL;
r_shadow_buffer_leaflist = NULL;
r_shadow_buffer_numsurfacepvsbytes = 0;
int numlighttrispvsbytes = (((numlighttriangles + 7) >> 3) + 255) & ~255;
if (r_shadow_buffer_numleafpvsbytes < numleafpvsbytes)
{
+ if (r_shadow_buffer_visitingleafpvs)
+ Mem_Free(r_shadow_buffer_visitingleafpvs);
if (r_shadow_buffer_leafpvs)
Mem_Free(r_shadow_buffer_leafpvs);
if (r_shadow_buffer_leaflist)
Mem_Free(r_shadow_buffer_leaflist);
r_shadow_buffer_numleafpvsbytes = numleafpvsbytes;
+ r_shadow_buffer_visitingleafpvs = (unsigned char *)Mem_Alloc(r_main_mempool, r_shadow_buffer_numleafpvsbytes);
r_shadow_buffer_leafpvs = (unsigned char *)Mem_Alloc(r_main_mempool, r_shadow_buffer_numleafpvsbytes);
r_shadow_buffer_leaflist = (int *)Mem_Alloc(r_main_mempool, r_shadow_buffer_numleafpvsbytes * 8 * sizeof(*r_shadow_buffer_leaflist));
}
else
VectorClear(projectvector);
- if (maxvertexupdate < innumvertices)
- {
- maxvertexupdate = innumvertices;
- if (vertexupdate)
- Mem_Free(vertexupdate);
- if (vertexremap)
- Mem_Free(vertexremap);
- vertexupdate = (int *)Mem_Alloc(r_main_mempool, maxvertexupdate * sizeof(int));
- vertexremap = (int *)Mem_Alloc(r_main_mempool, maxvertexupdate * sizeof(int));
- vertexupdatenum = 0;
- }
- vertexupdatenum++;
- if (vertexupdatenum == 0)
- {
- vertexupdatenum = 1;
- memset(vertexupdate, 0, maxvertexupdate * sizeof(int));
- memset(vertexremap, 0, maxvertexupdate * sizeof(int));
- }
-
- for (i = 0;i < numshadowmarktris;i++)
- shadowmark[shadowmarktris[i]] = shadowmarkcount;
-
// create the vertices
if (projectdirection)
{
}
}
-static void R_Shadow_RenderVolume(int numvertices, int numtriangles, const float *vertex3f, const int *element3i)
-{
- if (r_shadow_compilingrtlight)
- {
- // if we're compiling an rtlight, capture the mesh
- Mod_ShadowMesh_AddMesh(r_main_mempool, r_shadow_compilingrtlight->static_meshchain_shadow, NULL, NULL, NULL, vertex3f, NULL, NULL, NULL, NULL, numtriangles, element3i);
- return;
- }
- r_refdef.stats.lights_shadowtriangles += numtriangles;
- CHECKGLERROR
- R_Mesh_VertexPointer(vertex3f, 0, 0);
- GL_LockArrays(0, numvertices);
- if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCIL)
- {
- // decrement stencil if backface is behind depthbuffer
- GL_CullFace(r_refdef.view.cullface_front);
- qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);CHECKGLERROR
- R_Mesh_Draw(0, numvertices, 0, numtriangles, element3i, NULL, 0, 0);
- // increment stencil if frontface is behind depthbuffer
- GL_CullFace(r_refdef.view.cullface_back);
- qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);CHECKGLERROR
- }
- R_Mesh_Draw(0, numvertices, 0, numtriangles, element3i, NULL, 0, 0);
- GL_LockArrays(0, 0);
- CHECKGLERROR
-}
-
-void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f, const int *elements, const int *neighbors, const vec3_t projectorigin, const vec3_t projectdirection, float projectdistance, int nummarktris, const int *marktris)
+void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f, const int *elements, const int *neighbors, const vec3_t projectorigin, const vec3_t projectdirection, float projectdistance, int nummarktris, const int *marktris, vec3_t trismins, vec3_t trismaxs)
{
- int tris, outverts;
+ int i, tris, outverts;
if (projectdistance < 0.1)
{
Con_Printf("R_Shadow_Volume: projectdistance %f\n", projectdistance);
// make sure shadowelements is big enough for this volume
if (maxshadowtriangles < nummarktris || maxshadowvertices < numverts)
R_Shadow_ResizeShadowArrays((numverts + 255) & ~255, (nummarktris + 255) & ~255);
- tris = R_Shadow_ConstructShadowVolume(numverts, numtris, elements, neighbors, invertex3f, &outverts, shadowelements, shadowvertex3f, projectorigin, projectdirection, projectdistance, nummarktris, marktris);
- r_refdef.stats.lights_dynamicshadowtriangles += tris;
- R_Shadow_RenderVolume(outverts, tris, shadowvertex3f, shadowelements);
+
+ if (maxvertexupdate < numverts)
+ {
+ maxvertexupdate = numverts;
+ if (vertexupdate)
+ Mem_Free(vertexupdate);
+ if (vertexremap)
+ Mem_Free(vertexremap);
+ vertexupdate = (int *)Mem_Alloc(r_main_mempool, maxvertexupdate * sizeof(int));
+ vertexremap = (int *)Mem_Alloc(r_main_mempool, maxvertexupdate * sizeof(int));
+ vertexupdatenum = 0;
+ }
+ vertexupdatenum++;
+ if (vertexupdatenum == 0)
+ {
+ vertexupdatenum = 1;
+ memset(vertexupdate, 0, maxvertexupdate * sizeof(int));
+ memset(vertexremap, 0, maxvertexupdate * sizeof(int));
+ }
+
+ for (i = 0;i < nummarktris;i++)
+ shadowmark[marktris[i]] = shadowmarkcount;
+
+ if (r_shadow_compilingrtlight)
+ {
+ // if we're compiling an rtlight, capture the mesh
+ tris = R_Shadow_ConstructShadowVolume(numverts, numtris, elements, neighbors, invertex3f, &outverts, shadowelements, shadowvertex3f, projectorigin, projectdirection, projectdistance, nummarktris, marktris);
+ Mod_ShadowMesh_AddMesh(r_main_mempool, r_shadow_compilingrtlight->static_meshchain_shadow, NULL, NULL, NULL, shadowvertex3f, NULL, NULL, NULL, NULL, tris, shadowelements);
+ }
+ else
+ {
+ tris = R_Shadow_ConstructShadowVolume(numverts, numtris, elements, neighbors, invertex3f, &outverts, shadowelements, shadowvertex3f, projectorigin, projectdirection, projectdistance, nummarktris, marktris);
+ r_refdef.stats.lights_dynamicshadowtriangles += tris;
+ r_refdef.stats.lights_shadowtriangles += tris;
+ CHECKGLERROR
+ R_Mesh_VertexPointer(shadowvertex3f, 0, 0);
+ GL_LockArrays(0, outverts);
+ if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCIL)
+ {
+ // decrement stencil if backface is behind depthbuffer
+ GL_CullFace(r_refdef.view.cullface_front);
+ qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);CHECKGLERROR
+ R_Mesh_Draw(0, outverts, 0, tris, shadowelements, NULL, 0, 0);
+ // increment stencil if frontface is behind depthbuffer
+ GL_CullFace(r_refdef.view.cullface_back);
+ qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);CHECKGLERROR
+ }
+ R_Mesh_Draw(0, outverts, 0, tris, shadowelements, NULL, 0, 0);
+ GL_LockArrays(0, 0);
+ CHECKGLERROR
+ }
}
static void R_Shadow_MakeTextures_MakeCorona(void)
R_SetupGenericShader(false);
}
-void R_Shadow_RenderMode_StencilShadowVolumes(qboolean clearstencil)
+void R_Shadow_ClearStencil(void)
+{
+ CHECKGLERROR
+ GL_Clear(GL_STENCIL_BUFFER_BIT);
+ r_refdef.stats.lights_clears++;
+}
+
+void R_Shadow_RenderMode_StencilShadowVolumes(void)
{
CHECKGLERROR
R_Shadow_RenderMode_Reset();
qglStencilMask(~0);CHECKGLERROR
qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);CHECKGLERROR
}
- if (clearstencil)
- GL_Clear(GL_STENCIL_BUFFER_BIT);
- r_refdef.stats.lights_clears++;
}
void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent)
// this variable must be set for the CompileShadowVolume code
r_shadow_compilingrtlight = rtlight;
R_Shadow_EnlargeLeafSurfaceTrisBuffer(model->brush.num_leafs, model->num_surfaces, model->brush.shadowmesh ? model->brush.shadowmesh->numtriangles : model->surfmesh.num_triangles, model->surfmesh.num_triangles);
- model->GetLightInfo(ent, rtlight->shadoworigin, rtlight->radius, rtlight->cullmins, rtlight->cullmaxs, r_shadow_buffer_leaflist, r_shadow_buffer_leafpvs, &numleafs, r_shadow_buffer_surfacelist, r_shadow_buffer_surfacepvs, &numsurfaces, r_shadow_buffer_shadowtrispvs, r_shadow_buffer_lighttrispvs);
+ model->GetLightInfo(ent, rtlight->shadoworigin, rtlight->radius, rtlight->cullmins, rtlight->cullmaxs, r_shadow_buffer_leaflist, r_shadow_buffer_leafpvs, &numleafs, r_shadow_buffer_surfacelist, r_shadow_buffer_surfacepvs, &numsurfaces, r_shadow_buffer_shadowtrispvs, r_shadow_buffer_lighttrispvs, r_shadow_buffer_visitingleafpvs);
numleafpvsbytes = (model->brush.num_leafs + 7) >> 3;
numshadowtrispvsbytes = ((model->brush.shadowmesh ? model->brush.shadowmesh->numtriangles : model->surfmesh.num_triangles) + 7) >> 3;
numlighttrispvsbytes = (model->surfmesh.num_triangles + 7) >> 3;
size_t range = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); // checked
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (!light)
continue;
R_RTLight_Uncompile(&light->rtlight);
if (CHECKPVSBIT(trispvs, t))
shadowmarklist[numshadowmark++] = t;
}
- R_Shadow_VolumeFromList(r_refdef.scene.worldmodel->brush.shadowmesh->numverts, r_refdef.scene.worldmodel->brush.shadowmesh->numtriangles, r_refdef.scene.worldmodel->brush.shadowmesh->vertex3f, r_refdef.scene.worldmodel->brush.shadowmesh->element3i, r_refdef.scene.worldmodel->brush.shadowmesh->neighbor3i, rsurface.rtlight->shadoworigin, NULL, rsurface.rtlight->radius + r_refdef.scene.worldmodel->radius*2 + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
+ R_Shadow_VolumeFromList(r_refdef.scene.worldmodel->brush.shadowmesh->numverts, r_refdef.scene.worldmodel->brush.shadowmesh->numtriangles, r_refdef.scene.worldmodel->brush.shadowmesh->vertex3f, r_refdef.scene.worldmodel->brush.shadowmesh->element3i, r_refdef.scene.worldmodel->brush.shadowmesh->neighbor3i, rsurface.rtlight->shadoworigin, NULL, rsurface.rtlight->radius + r_refdef.scene.worldmodel->radius*2 + r_shadow_projectdistance.value, numshadowmark, shadowmarklist, r_refdef.scene.worldmodel->normalmins, r_refdef.scene.worldmodel->normalmaxs);
}
else if (numsurfaces)
r_refdef.scene.worldmodel->DrawShadowVolume(r_refdef.scene.worldentity, rsurface.rtlight->shadoworigin, NULL, rsurface.rtlight->radius, numsurfaces, surfacelist, rsurface.rtlight_cullmins, rsurface.rtlight_cullmaxs);
int numlightentities_noselfshadow;
int numshadowentities;
int numshadowentities_noselfshadow;
- entity_render_t *lightentities[MAX_EDICTS];
- entity_render_t *lightentities_noselfshadow[MAX_EDICTS];
- entity_render_t *shadowentities[MAX_EDICTS];
- entity_render_t *shadowentities_noselfshadow[MAX_EDICTS];
+ static entity_render_t *lightentities[MAX_EDICTS];
+ static entity_render_t *lightentities_noselfshadow[MAX_EDICTS];
+ static entity_render_t *shadowentities[MAX_EDICTS];
+ static entity_render_t *shadowentities_noselfshadow[MAX_EDICTS];
// skip lights that don't light because of ambientscale+diffusescale+specularscale being 0 (corona only lights)
// skip lights that are basically invisible (color 0 0 0)
// dynamic light, world available and can receive realtime lighting
// calculate lit surfaces and leafs
R_Shadow_EnlargeLeafSurfaceTrisBuffer(r_refdef.scene.worldmodel->brush.num_leafs, r_refdef.scene.worldmodel->num_surfaces, r_refdef.scene.worldmodel->brush.shadowmesh ? r_refdef.scene.worldmodel->brush.shadowmesh->numtriangles : r_refdef.scene.worldmodel->surfmesh.num_triangles, r_refdef.scene.worldmodel->surfmesh.num_triangles);
- r_refdef.scene.worldmodel->GetLightInfo(r_refdef.scene.worldentity, rtlight->shadoworigin, rtlight->radius, rsurface.rtlight_cullmins, rsurface.rtlight_cullmaxs, r_shadow_buffer_leaflist, r_shadow_buffer_leafpvs, &numleafs, r_shadow_buffer_surfacelist, r_shadow_buffer_surfacepvs, &numsurfaces, r_shadow_buffer_shadowtrispvs, r_shadow_buffer_lighttrispvs);
+ r_refdef.scene.worldmodel->GetLightInfo(r_refdef.scene.worldentity, rtlight->shadoworigin, rtlight->radius, rsurface.rtlight_cullmins, rsurface.rtlight_cullmaxs, r_shadow_buffer_leaflist, r_shadow_buffer_leafpvs, &numleafs, r_shadow_buffer_surfacelist, r_shadow_buffer_surfacepvs, &numsurfaces, r_shadow_buffer_shadowtrispvs, r_shadow_buffer_lighttrispvs, r_shadow_buffer_visitingleafpvs);
leaflist = r_shadow_buffer_leaflist;
leafpvs = r_shadow_buffer_leafpvs;
surfacelist = r_shadow_buffer_surfacelist;
{
// draw stencil shadow volumes to mask off pixels that are in shadow
// so that they won't receive lighting
- R_Shadow_RenderMode_StencilShadowVolumes(true);
+ R_Shadow_ClearStencil();
+ R_Shadow_RenderMode_StencilShadowVolumes();
if (numsurfaces)
R_Shadow_DrawWorldShadow(numsurfaces, surfacelist, shadowtrispvs);
for (i = 0;i < numshadowentities;i++)
R_Shadow_DrawEntityLight(lightentities_noselfshadow[i]);
}
- R_Shadow_RenderMode_StencilShadowVolumes(false);
+ R_Shadow_RenderMode_StencilShadowVolumes();
}
for (i = 0;i < numshadowentities_noselfshadow;i++)
R_Shadow_DrawEntityShadow(shadowentities_noselfshadow[i]);
if (r_shadow_debuglight.integer >= 0)
{
lightindex = r_shadow_debuglight.integer;
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (light && (light->flags & flag))
R_DrawRTLight(&light->rtlight, visible);
}
range = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); // checked
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (light && (light->flags & flag))
R_DrawRTLight(&light->rtlight, visible);
}
}
extern void R_SetupView(qboolean allowwaterclippingplane);
+extern cvar_t r_shadows;
extern cvar_t r_shadows_throwdistance;
void R_DrawModelShadows(void)
{
vec3_t relativelightorigin;
vec3_t relativelightdirection;
vec3_t relativeshadowmins, relativeshadowmaxs;
+ vec3_t tmp;
float vertex3f[12];
if (!r_drawentities.integer || !gl_stencil)
else
r_shadow_shadowingrendermode = R_SHADOW_RENDERMODE_STENCIL;
- R_Shadow_RenderMode_StencilShadowVolumes(true);
+ R_Shadow_ClearStencil();
+ R_Shadow_RenderMode_StencilShadowVolumes();
for (i = 0;i < r_refdef.scene.numentities;i++)
{
relativethrowdistance = r_shadows_throwdistance.value * Matrix4x4_ScaleFromMatrix(&ent->inversematrix);
VectorSet(relativeshadowmins, -relativethrowdistance, -relativethrowdistance, -relativethrowdistance);
VectorSet(relativeshadowmaxs, relativethrowdistance, relativethrowdistance, relativethrowdistance);
- VectorNegate(ent->modellight_lightdir, relativelightdirection);
+
+ if(r_shadows.integer == 2)
+ {
+ // 2: simpler mode, throw shadows always DOWN
+ VectorSet(tmp, 0, 0, -1);
+ Matrix4x4_Transform3x3(&ent->inversematrix, tmp, relativelightdirection);
+ }
+ else
+ {
+ if(ent->entitynumber != 0)
+ {
+ // networked entity - might be attached in some way (then we should use the parent's light direction, to not tear apart attached entities)
+ int entnum, entnum2, recursion;
+ entnum = entnum2 = ent->entitynumber;
+ for(recursion = 32; recursion > 0; --recursion)
+ {
+ entnum2 = cl.entities[entnum].state_current.tagentity;
+ if(entnum2 >= 1 && entnum2 < cl.num_entities && cl.entities_active[entnum2])
+ entnum = entnum2;
+ else
+ break;
+ }
+ if(recursion && recursion != 32) // if we followed a valid non-empty attachment chain
+ {
+ VectorNegate(cl.entities[entnum].render.modellight_lightdir, relativelightdirection);
+ // transform into modelspace of OUR entity
+ Matrix4x4_Transform3x3(&cl.entities[entnum].render.matrix, relativelightdirection, tmp);
+ Matrix4x4_Transform3x3(&ent->inversematrix, tmp, relativelightdirection);
+ }
+ else
+ VectorNegate(ent->modellight_lightdir, relativelightdirection);
+ }
+ else
+ VectorNegate(ent->modellight_lightdir, relativelightdirection);
+ }
+
VectorScale(relativelightdirection, -relativethrowdistance, relativelightorigin);
RSurf_ActiveModelEntity(ent, false, false);
ent->model->DrawShadowVolume(ent, relativelightorigin, relativelightdirection, relativethrowdistance, ent->model->nummodelsurfaces, ent->model->surfacelist, relativeshadowmins, relativeshadowmaxs);
R_Shadow_RenderMode_End();
}
+void R_BeginCoronaQuery(rtlight_t *rtlight, float scale, qboolean usequery)
+{
+ // if it's too close, skip it
+ if (VectorLength(rtlight->color) < (1.0f / 256.0f))
+ return;
+ if (VectorDistance2(rtlight->shadoworigin, r_refdef.view.origin) < 32.0f * 32.0f)
+ return;
+ if (usequery && r_numqueries + 2 <= r_maxqueries)
+ {
+ rtlight->corona_queryindex_allpixels = r_queries[r_numqueries++];
+ rtlight->corona_queryindex_visiblepixels = r_queries[r_numqueries++];
+ CHECKGLERROR
+ qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, rtlight->corona_queryindex_allpixels);
+ R_DrawSprite(GL_ONE, GL_ZERO, r_shadow_lightcorona, NULL, true, false, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, 1, 1, 1, 1);
+ qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
+ qglBeginQueryARB(GL_SAMPLES_PASSED_ARB, rtlight->corona_queryindex_visiblepixels);
+ R_DrawSprite(GL_ONE, GL_ZERO, r_shadow_lightcorona, NULL, false, false, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, 1, 1, 1, 1);
+ qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
+ CHECKGLERROR
+ }
+ rtlight->corona_visibility = 1;
+}
+
+void R_DrawCorona(rtlight_t *rtlight, float cscale, float scale)
+{
+ vec3_t color;
+ GLint allpixels = 0, visiblepixels = 0;
+ // now we have to check the query result
+ if (rtlight->corona_queryindex_visiblepixels)
+ {
+ CHECKGLERROR
+ qglGetQueryObjectivARB(rtlight->corona_queryindex_visiblepixels, GL_QUERY_RESULT_ARB, &visiblepixels);
+ qglGetQueryObjectivARB(rtlight->corona_queryindex_allpixels, GL_QUERY_RESULT_ARB, &allpixels);
+ CHECKGLERROR
+ //Con_Printf("%i of %i pixels\n", (int)visiblepixels, (int)allpixels);
+ if (visiblepixels < 1 || allpixels < 1)
+ return;
+ rtlight->corona_visibility *= (float)visiblepixels / (float)allpixels;
+ cscale *= rtlight->corona_visibility;
+ }
+ else
+ {
+ // FIXME: these traces should scan all render entities instead of cl.world
+ if (CL_Move(r_refdef.view.origin, vec3_origin, vec3_origin, rtlight->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction < 1)
+ return;
+ }
+ VectorScale(rtlight->color, cscale, color);
+ if (VectorLength(color) > (1.0f / 256.0f))
+ R_DrawSprite(GL_ONE, GL_ONE, r_shadow_lightcorona, NULL, true, false, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, color[0], color[1], color[2], 1);
+}
+
void R_DrawCoronas(void)
{
int i, flag;
- float cscale, scale;
+ qboolean usequery;
size_t lightindex;
dlight_t *light;
rtlight_t *rtlight;
size_t range;
if (r_coronas.value < (1.0f / 256.0f) && !gl_flashblend.integer)
return;
- R_Mesh_Matrix(&identitymatrix);
+ if (r_waterstate.renderingscene)
+ return;
flag = r_refdef.scene.rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE;
- // FIXME: these traces should scan all render entities instead of cl.world
+ R_Mesh_Matrix(&identitymatrix);
+
range = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); // checked
+
+ // check occlusion of coronas
+ // use GL_ARB_occlusion_query if available
+ // otherwise use raytraces
+ r_numqueries = 0;
+ usequery = gl_support_arb_occlusion_query && r_coronas_occlusionquery.integer;
+ if (usequery)
+ {
+ GL_ColorMask(0,0,0,0);
+ if (r_maxqueries < range + r_refdef.scene.numlights)
+ if (r_maxqueries < R_MAX_OCCLUSION_QUERIES)
+ {
+ i = r_maxqueries;
+ r_maxqueries = (range + r_refdef.scene.numlights) * 2;
+ r_maxqueries = min(r_maxqueries, R_MAX_OCCLUSION_QUERIES);
+ CHECKGLERROR
+ qglGenQueriesARB(r_maxqueries - i, r_queries + i);
+ CHECKGLERROR
+ }
+ }
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (!light)
continue;
rtlight = &light->rtlight;
+ rtlight->corona_visibility = 0;
+ rtlight->corona_queryindex_visiblepixels = 0;
+ rtlight->corona_queryindex_allpixels = 0;
if (!(rtlight->flags & flag))
continue;
- if (rtlight->corona * r_coronas.value <= 0)
+ if (rtlight->corona <= 0)
continue;
if (r_shadow_debuglight.integer >= 0 && r_shadow_debuglight.integer != (int)lightindex)
continue;
- cscale = rtlight->corona * r_coronas.value* 0.25f;
- scale = rtlight->radius * rtlight->coronasizescale;
- if (VectorDistance2(rtlight->shadoworigin, r_refdef.view.origin) < 16.0f * 16.0f)
- continue;
- if (CL_Move(r_refdef.view.origin, vec3_origin, vec3_origin, rtlight->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction < 1)
- continue;
- R_DrawSprite(GL_ONE, GL_ONE, r_shadow_lightcorona, NULL, true, false, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, rtlight->color[0] * cscale, rtlight->color[1] * cscale, rtlight->color[2] * cscale, 1);
+ R_BeginCoronaQuery(rtlight, rtlight->radius * rtlight->coronasizescale * r_coronas_occlusionsizescale.value, usequery);
}
for (i = 0;i < r_refdef.scene.numlights;i++)
{
rtlight = &r_refdef.scene.lights[i];
+ rtlight->corona_visibility = 0;
+ rtlight->corona_queryindex_visiblepixels = 0;
+ rtlight->corona_queryindex_allpixels = 0;
if (!(rtlight->flags & flag))
continue;
if (rtlight->corona <= 0)
continue;
- if (VectorDistance2(rtlight->shadoworigin, r_refdef.view.origin) < 32.0f * 32.0f)
+ R_BeginCoronaQuery(rtlight, rtlight->radius * rtlight->coronasizescale * r_coronas_occlusionsizescale.value, usequery);
+ }
+ if (usequery)
+ GL_ColorMask(r_refdef.view.colormask[0], r_refdef.view.colormask[1], r_refdef.view.colormask[2], 1);
+
+ // now draw the coronas using the query data for intensity info
+ for (lightindex = 0;lightindex < range;lightindex++)
+ {
+ light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ if (!light)
continue;
- if (gl_flashblend.integer)
- {
- cscale = rtlight->corona * 1.0f;
- scale = rtlight->radius * rtlight->coronasizescale * 2.0f;
- }
- else
- {
- cscale = rtlight->corona * r_coronas.value* 0.25f;
- scale = rtlight->radius * rtlight->coronasizescale;
- }
- if (VectorLength(rtlight->color) * cscale < (1.0f / 256.0f))
+ rtlight = &light->rtlight;
+ if (rtlight->corona_visibility <= 0)
continue;
- if (CL_Move(r_refdef.view.origin, vec3_origin, vec3_origin, rtlight->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction < 1)
+ R_DrawCorona(rtlight, rtlight->corona * r_coronas.value * 0.25f, rtlight->radius * rtlight->coronasizescale);
+ }
+ for (i = 0;i < r_refdef.scene.numlights;i++)
+ {
+ rtlight = &r_refdef.scene.lights[i];
+ if (rtlight->corona_visibility <= 0)
continue;
- R_DrawSprite(GL_ONE, GL_ONE, r_shadow_lightcorona, NULL, true, false, rtlight->shadoworigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, rtlight->color[0] * cscale, rtlight->color[1] * cscale, rtlight->color[2] * cscale, 1);
+ if (gl_flashblend.integer)
+ R_DrawCorona(rtlight, rtlight->corona, rtlight->radius * rtlight->coronasizescale * 2.0f);
+ else
+ R_DrawCorona(rtlight, rtlight->corona * r_coronas.value * 0.25f, rtlight->radius * rtlight->coronasizescale);
}
}
size_t range = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); // checked
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (light)
R_Shadow_FreeWorldLight(light);
}
size_t range = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); // checked
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (light)
R_MeshQueue_AddTransparent(light->origin, R_Shadow_DrawLightSprite_TransparentCallback, (entity_render_t *)light, 5, &light->rtlight);
}
bestrating = 0;
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (!light)
continue;
VectorSubtract(light->origin, r_refdef.view.origin, temp);
buf = NULL;
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (!light)
continue;
if (light->coronasizescale != 0.25f || light->ambientscale != 0 || light->diffusescale != 1 || light->specularscale != 1 || light->flags != LIGHTFLAG_REALTIMEMODE)
range = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); // checked
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (!light)
continue;
R_Shadow_SelectLight(light);
range = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); // checked
for (lightindex = 0;lightindex < range;lightindex++)
{
- light = Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
+ light = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, lightindex);
if (!light)
continue;
if (light == r_shadow_selectedlight)