]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix a serious bug with r_shadow_bouncegrid_static where it used
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 27 Aug 2016 03:17:49 +0000 (03:17 +0000)
committerRudolf Polzer <divVerent@xonotic.org>
Tue, 29 Nov 2016 18:33:07 +0000 (19:33 +0100)
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

r_shadow.c

index b97ae62d2a089a90578e6ffe1cbea4880b6179f8..e267d5f0b207eb9b132683b6d2f9e897d444aed3 100644 (file)
@@ -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;