]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_shadow.c
clear mouse input at a better stage (should fix cl_maxfps issues)
[xonotic/darkplaces.git] / r_shadow.c
index b8e2e51f7b5ce120dac8e0d3036d3daa32dcb717..f18154877700b8ccb0b9985f8c639502362a3c87 100644 (file)
@@ -215,7 +215,7 @@ cvar_t r_shadow_gloss = {CVAR_SAVE, "r_shadow_gloss", "1", "0 disables gloss (sp
 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_glossexact = {0, "r_shadow_glossexact", "0", "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"};
@@ -2995,6 +2995,8 @@ void R_Shadow_DrawWorldShadow(int numsurfaces, int *surfacelist, const unsigned
        }
        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);
+
+       rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
 }
 
 void R_Shadow_DrawEntityShadow(entity_render_t *ent)
@@ -3010,7 +3012,8 @@ void R_Shadow_DrawEntityShadow(entity_render_t *ent)
        relativeshadowmaxs[0] = relativeshadoworigin[0] + relativeshadowradius;
        relativeshadowmaxs[1] = relativeshadoworigin[1] + relativeshadowradius;
        relativeshadowmaxs[2] = relativeshadoworigin[2] + relativeshadowradius;
-       ent->model->DrawShadowVolume(ent, relativeshadoworigin, NULL, relativeshadowradius, ent->model->nummodelsurfaces, ent->model->surfacelist, relativeshadowmins, relativeshadowmaxs);
+       ent->model->DrawShadowVolume(ent, relativeshadoworigin, NULL, relativeshadowradius, ent->model->nummodelsurfaces, ent->model->sortedmodelsurfaces, relativeshadowmins, relativeshadowmaxs);
+       rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
 }
 
 void R_Shadow_SetupEntityLight(const entity_render_t *ent)
@@ -3042,6 +3045,8 @@ void R_Shadow_DrawWorldLight(int numsurfaces, int *surfacelist, const unsigned c
                R_Mesh_TexMatrix(3, &rsurface.entitytolight);
 
        r_refdef.scene.worldmodel->DrawLight(r_refdef.scene.worldentity, numsurfaces, surfacelist, trispvs);
+
+       rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
 }
 
 void R_Shadow_DrawEntityLight(entity_render_t *ent)
@@ -3052,7 +3057,9 @@ void R_Shadow_DrawEntityLight(entity_render_t *ent)
 
        R_Shadow_SetupEntityLight(ent);
 
-       model->DrawLight(ent, model->nummodelsurfaces, model->surfacelist, NULL);
+       model->DrawLight(ent, model->nummodelsurfaces, model->sortedmodelsurfaces, NULL);
+
+       rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
 }
 
 void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
@@ -3461,7 +3468,8 @@ void R_DrawModelShadows(void)
 
                        VectorScale(relativelightdirection, -relativethrowdistance, relativelightorigin);
                        RSurf_ActiveModelEntity(ent, false, false);
-                       ent->model->DrawShadowVolume(ent, relativelightorigin, relativelightdirection, relativethrowdistance, ent->model->nummodelsurfaces, ent->model->surfacelist, relativeshadowmins, relativeshadowmaxs);
+                       ent->model->DrawShadowVolume(ent, relativelightorigin, relativelightdirection, relativethrowdistance, ent->model->nummodelsurfaces, ent->model->sortedmodelsurfaces, relativeshadowmins, relativeshadowmaxs);
+                       rsurface.entity = NULL; // used only by R_GetCurrentTexture and RSurf_ActiveWorldEntity/RSurf_ActiveModelEntity
                }
        }
 
@@ -3510,25 +3518,33 @@ void R_DrawModelShadows(void)
 
 void R_BeginCoronaQuery(rtlight_t *rtlight, float scale, qboolean usequery)
 {
+       float zdist;
+       vec3_t centerorigin;
        // 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;
+       zdist = (DotProduct(rtlight->shadoworigin, r_refdef.view.forward) - DotProduct(r_refdef.view.origin, r_refdef.view.forward));
+       if (zdist < 32)
+               return;
        if (usequery && r_numqueries + 2 <= r_maxqueries)
        {
                rtlight->corona_queryindex_allpixels = r_queries[r_numqueries++];
                rtlight->corona_queryindex_visiblepixels = r_queries[r_numqueries++];
+               VectorMA(r_refdef.view.origin, zdist, r_refdef.view.forward, centerorigin);
+
                CHECKGLERROR
+               // NOTE: we can't disable depth testing using R_DrawSprite's depthdisable argument, which calls GL_DepthTest, as that's broken in the ATI drivers
                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);
+               qglDepthFunc(GL_ALWAYS);
+               R_DrawSprite(GL_ONE, GL_ZERO, r_shadow_lightcorona, NULL, false, false, centerorigin, r_refdef.view.right, r_refdef.view.up, scale, -scale, -scale, scale, 1, 1, 1, 1);
                qglEndQueryARB(GL_SAMPLES_PASSED_ARB);
+               qglDepthFunc(GL_LEQUAL);
                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;
+       rtlight->corona_visibility = bound(0, (zdist - 32) / 32, 1);
 }
 
 void R_DrawCorona(rtlight_t *rtlight, float cscale, float scale)
@@ -3545,7 +3561,7 @@ void R_DrawCorona(rtlight_t *rtlight, float cscale, float scale)
                //Con_Printf("%i of %i pixels\n", (int)visiblepixels, (int)allpixels);
                if (visiblepixels < 1 || allpixels < 1)
                        return;
-               rtlight->corona_visibility *= (float)visiblepixels / (float)allpixels;
+               rtlight->corona_visibility *= bound(0, (float)visiblepixels / (float)allpixels, 1);
                cscale *= rtlight->corona_visibility;
        }
        else
@@ -3584,11 +3600,11 @@ void R_DrawCoronas(void)
        if (usequery)
        {
                GL_ColorMask(0,0,0,0);
-               if (r_maxqueries < range + r_refdef.scene.numlights)
+               if (r_maxqueries < (range + r_refdef.scene.numlights) * 2)
                if (r_maxqueries < R_MAX_OCCLUSION_QUERIES)
                {
                        i = r_maxqueries;
-                       r_maxqueries = (range + r_refdef.scene.numlights) * 2;
+                       r_maxqueries = (range + r_refdef.scene.numlights) * 4;
                        r_maxqueries = min(r_maxqueries, R_MAX_OCCLUSION_QUERIES);
                        CHECKGLERROR
                        qglGenQueriesARB(r_maxqueries - i, r_queries + i);