From: havoc Date: Sat, 27 Aug 2016 03:17:49 +0000 (+0000) Subject: Fix a serious bug with r_shadow_bouncegrid_static where it used X-Git-Tag: xonotic-v0.8.2~25 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=81804fa83299b491dc24dd5f058527165faa38da;p=xonotic%2Fdarkplaces.git Fix a serious bug with r_shadow_bouncegrid_static where it used R_CullBox and other view-dependent performance optimizations when compiling the static texture - thanks to Vic for finding this bug! git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12273 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=3dfd03a33dc34d8a469d9b2f334991de226fd897 --- diff --git a/r_shadow.c b/r_shadow.c index b97ae62d..e267d5f0 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -2647,14 +2647,21 @@ void R_Shadow_UpdateBounceGridTexture(void) cullmaxs[0] = rtlight->shadoworigin[0] + radius; cullmaxs[1] = rtlight->shadoworigin[1] + radius; cullmaxs[2] = rtlight->shadoworigin[2] + radius; - if (R_CullBox(cullmins, cullmaxs)) - continue; - if (r_refdef.scene.worldmodel - && r_refdef.scene.worldmodel->brush.BoxTouchingVisibleLeafs - && !r_refdef.scene.worldmodel->brush.BoxTouchingVisibleLeafs(r_refdef.scene.worldmodel, r_refdef.viewcache.world_leafvisible, cullmins, cullmaxs)) - continue; w = r_shadow_lightintensityscale.value * (rtlight->ambientscale + rtlight->diffusescale + rtlight->specularscale); - if (w * VectorLength2(rtlight->color) == 0.0f) + if (!settings.staticmode) + { + if (R_CullBox(cullmins, cullmaxs)) + continue; + if (r_refdef.scene.worldmodel + && r_refdef.scene.worldmodel->brush.BoxTouchingVisibleLeafs + && !r_refdef.scene.worldmodel->brush.BoxTouchingVisibleLeafs(r_refdef.scene.worldmodel, r_refdef.viewcache.world_leafvisible, cullmins, cullmaxs)) + continue; + if (w * VectorLength2(rtlight->color) == 0.0f) + continue; + } + // a light that does not emit any light before style is applied, can be + // skipped entirely (it may just be a corona) + if (rtlight->radius == 0.0f || VectorLength2(rtlight->color) == 0.0f) continue; w *= ((rtlight->style >= 0 && rtlight->style < MAX_LIGHTSTYLES) ? r_refdef.scene.rtlightstylevalue[rtlight->style] : 1); VectorScale(rtlight->color, w, rtlight->photoncolor); @@ -2669,8 +2676,12 @@ void R_Shadow_UpdateBounceGridTexture(void) lightintensity = VectorLength(rtlight->color) * (rtlight->ambientscale + rtlight->diffusescale + rtlight->specularscale); if (lightindex >= range) lightintensity *= settings.dlightparticlemultiplier; - rtlight->photons = max(0.0f, lightintensity * s * s); + rtlight->photons = bound(0.0f, lightintensity * s * s, MAXBOUNCEGRIDPARTICLESPERLIGHT); photoncount += rtlight->photons; + // if the lightstyle happens to be off right now, we can skip actually + // firing the photons, but we did have to count them in the total. + if (VectorLength2(rtlight->photoncolor) == 0.0f) + rtlight->photons = 0; } photonscaling = (float)settings.photons / max(1, photoncount); photonresidual = 0.0f; @@ -2688,11 +2699,8 @@ void R_Shadow_UpdateBounceGridTexture(void) // skip a light with no photons if (rtlight->photons == 0.0f) continue; - // skip a light with no photon color) - if (VectorLength2(rtlight->photoncolor) == 0.0f) - continue; photonresidual += rtlight->photons * photonscaling; - shootparticles = (int)bound(0, photonresidual, MAXBOUNCEGRIDPARTICLESPERLIGHT); + shootparticles = (int)floor(photonresidual); if (!shootparticles) continue; photonresidual -= shootparticles;