- if (r_refdef.scene.worldmodel && isstatic)
- {
- VectorSet(spacing, bound(1, r_shadow_bouncegrid_spacingx.value, 512), bound(1, r_shadow_bouncegrid_spacingy.value, 512), bound(1, r_shadow_bouncegrid_spacingz.value, 512));
- VectorMA(r_refdef.scene.worldmodel->normalmins, -2.0f, spacing, mins);
- VectorMA(r_refdef.scene.worldmodel->normalmaxs, 2.0f, spacing, maxs);
- VectorSubtract(maxs, mins, size);
- resolution[0] = (int)floor(size[0] / spacing[0] + 0.5f);
- resolution[1] = (int)floor(size[1] / spacing[1] + 0.5f);
- resolution[2] = (int)floor(size[2] / spacing[2] + 0.5f);
- resolution[0] = min(resolution[0], bound(4, r_shadow_bouncegrid_x.integer, (int)vid.maxtexturesize_3d));
- resolution[1] = min(resolution[1], bound(4, r_shadow_bouncegrid_y.integer, (int)vid.maxtexturesize_3d));
- resolution[2] = min(resolution[2], bound(4, r_shadow_bouncegrid_z.integer, (int)vid.maxtexturesize_3d));
- spacing[0] = size[0] / resolution[0];
- spacing[1] = size[1] / resolution[1];
- spacing[2] = size[2] / resolution[2];
- ispacing[0] = 1.0f / spacing[0];
- ispacing[1] = 1.0f / spacing[1];
- ispacing[2] = 1.0f / spacing[2];
+
+ // build up a complete collection of the desired settings, so that memcmp can be used to compare parameters
+ memset(&settings, 0, sizeof(settings));
+ settings.staticmode = r_shadow_bouncegrid_static.integer != 0;
+ settings.bounceanglediffuse = r_shadow_bouncegrid_bounceanglediffuse.integer != 0;
+ settings.directionalshading = (r_shadow_bouncegrid_static.integer != 0 ? r_shadow_bouncegrid_static_directionalshading.integer != 0 : r_shadow_bouncegrid_directionalshading.integer != 0) && allowdirectionalshading;
+ settings.dlightparticlemultiplier = r_shadow_bouncegrid_dlightparticlemultiplier.value;
+ settings.hitmodels = r_shadow_bouncegrid_hitmodels.integer != 0;
+ settings.includedirectlighting = r_shadow_bouncegrid_includedirectlighting.integer != 0 || r_shadow_bouncegrid.integer == 2;
+ settings.lightradiusscale = (r_shadow_bouncegrid_static.integer != 0 ? r_shadow_bouncegrid_static_lightradiusscale.value : r_shadow_bouncegrid_lightradiusscale.value);
+ settings.maxbounce = (r_shadow_bouncegrid_static.integer != 0 ? r_shadow_bouncegrid_static_maxbounce.integer : r_shadow_bouncegrid_maxbounce.integer);
+ settings.particlebounceintensity = r_shadow_bouncegrid_particlebounceintensity.value;
+ settings.particleintensity = r_shadow_bouncegrid_particleintensity.value * 16384.0f * (settings.directionalshading ? 4.0f : 1.0f) / (r_shadow_bouncegrid_spacing.value * r_shadow_bouncegrid_spacing.value);
+ settings.photons = r_shadow_bouncegrid_static.integer ? r_shadow_bouncegrid_static_photons.integer : r_shadow_bouncegrid_photons.integer;
+ settings.spacing[0] = r_shadow_bouncegrid_spacing.value;
+ settings.spacing[1] = r_shadow_bouncegrid_spacing.value;
+ settings.spacing[2] = r_shadow_bouncegrid_spacing.value;
+ settings.stablerandom = r_shadow_bouncegrid_stablerandom.integer;
+
+ // bound the values for sanity
+ settings.photons = bound(1, settings.photons, 1048576);
+ settings.lightradiusscale = bound(0.0001f, settings.lightradiusscale, 1024.0f);
+ settings.maxbounce = bound(0, settings.maxbounce, 16);
+ settings.spacing[0] = bound(1, settings.spacing[0], 512);
+ settings.spacing[1] = bound(1, settings.spacing[1], 512);
+ settings.spacing[2] = bound(1, settings.spacing[2], 512);
+
+ // get the spacing values
+ spacing[0] = settings.spacing[0];
+ spacing[1] = settings.spacing[1];
+ spacing[2] = settings.spacing[2];
+ ispacing[0] = 1.0f / spacing[0];
+ ispacing[1] = 1.0f / spacing[1];
+ ispacing[2] = 1.0f / spacing[2];
+
+ // calculate texture size enclosing entire world bounds at the spacing
+ VectorMA(r_refdef.scene.worldmodel->normalmins, -2.0f, spacing, mins);
+ VectorMA(r_refdef.scene.worldmodel->normalmaxs, 2.0f, spacing, maxs);
+ VectorSubtract(maxs, mins, size);
+ // now we can calculate the resolution we want
+ c[0] = (int)floor(size[0] / spacing[0] + 0.5f);
+ c[1] = (int)floor(size[1] / spacing[1] + 0.5f);
+ c[2] = (int)floor(size[2] / spacing[2] + 0.5f);
+ // figure out the exact texture size (honoring power of 2 if required)
+ c[0] = bound(4, c[0], (int)vid.maxtexturesize_3d);
+ c[1] = bound(4, c[1], (int)vid.maxtexturesize_3d);
+ c[2] = bound(4, c[2], (int)vid.maxtexturesize_3d);
+ if (vid.support.arb_texture_non_power_of_two)
+ {
+ resolution[0] = c[0];
+ resolution[1] = c[1];
+ resolution[2] = c[2];