typedef enum r_shadow_shadowmode_e
{
+ R_SHADOW_SHADOWMODE_DISABLED,
R_SHADOW_SHADOWMODE_SHADOWMAP2D
}
r_shadow_shadowmode_t;
#endif
int r_shadow_cullface_front, r_shadow_cullface_back;
GLuint r_shadow_fbo2d;
+int r_shadow_shadowmode_shadowmapping; // cached value of r_shadow_shadowmapping cvar
+int r_shadow_shadowmode_deferred; // cached value of r_shadow_deferred cvar
r_shadow_shadowmode_t r_shadow_shadowmode;
int r_shadow_shadowmapfilterquality;
int r_shadow_shadowmapdepthbits;
static void R_Shadow_MakeVSDCT(void);
static void R_Shadow_SetShadowMode(void)
{
+ r_shadow_shadowmode_shadowmapping = r_shadow_shadowmapping.integer;
+ r_shadow_shadowmode_deferred = r_shadow_deferred.integer;
r_shadow_shadowmapborder = bound(1, r_shadow_shadowmapping_bordersize.integer, 16);
r_shadow_shadowmaptexturesize = bound(256, r_shadow_shadowmapping_texturesize.integer, (int)vid.maxtexturesize_2d);
r_shadow_shadowmapmaxsize = bound(r_shadow_shadowmapborder+2, r_shadow_shadowmapping_maxsize.integer, r_shadow_shadowmaptexturesize / 8);
r_shadow_shadowmapsampler = false;
r_shadow_shadowmappcf = 0;
r_shadow_shadowmapdepthtexture = r_fb.usedepthtextures;
- r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
- Mod_AllocLightmap_Init(&r_shadow_shadowmapatlas_state, r_main_mempool, r_shadow_shadowmaptexturesize, r_shadow_shadowmaptexturesize);
- if (r_shadow_shadowmapping.integer || r_shadow_deferred.integer)
+ r_shadow_shadowmode = R_SHADOW_SHADOWMODE_DISABLED;
+ if (r_shadow_shadowmode_shadowmapping || r_shadow_shadowmode_deferred)
{
- switch(vid.renderpath)
+ switch (vid.renderpath)
{
case RENDERPATH_GL32:
- if(r_shadow_shadowmapfilterquality < 0)
+ if (r_shadow_shadowmapfilterquality < 0)
{
if (!r_fb.usedepthtextures)
r_shadow_shadowmappcf = 1;
- else if((strstr(gl_vendor, "NVIDIA") || strstr(gl_renderer, "Radeon HD")) && r_shadow_shadowmapshadowsampler)
+ else if ((strstr(gl_vendor, "NVIDIA") || strstr(gl_renderer, "Radeon HD")) && r_shadow_shadowmapshadowsampler)
{
r_shadow_shadowmapsampler = true;
r_shadow_shadowmappcf = 1;
}
- else if(vid.support.amd_texture_texture4 || vid.support.arb_texture_gather)
+ else if (vid.support.amd_texture_texture4 || vid.support.arb_texture_gather)
r_shadow_shadowmappcf = 1;
- else if((strstr(gl_vendor, "ATI") || strstr(gl_vendor, "Advanced Micro Devices")) && !strstr(gl_renderer, "Mesa") && !strstr(gl_version, "Mesa"))
+ else if ((strstr(gl_vendor, "ATI") || strstr(gl_vendor, "Advanced Micro Devices")) && !strstr(gl_renderer, "Mesa") && !strstr(gl_version, "Mesa"))
r_shadow_shadowmappcf = 1;
else
r_shadow_shadowmapsampler = r_shadow_shadowmapshadowsampler;
}
else
{
- r_shadow_shadowmapsampler = r_shadow_shadowmapshadowsampler;
+ r_shadow_shadowmapsampler = r_shadow_shadowmapshadowsampler;
switch (r_shadow_shadowmapfilterquality)
{
case 1:
r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
break;
case RENDERPATH_GLES2:
+ r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
break;
}
}
+ switch (r_shadow_shadowmode)
+ {
+ case R_SHADOW_SHADOWMODE_SHADOWMAP2D:
+ Mod_AllocLightmap_Init(&r_shadow_shadowmapatlas_state, r_main_mempool, r_shadow_shadowmaptexturesize, r_shadow_shadowmaptexturesize);
+ break;
+ case R_SHADOW_SHADOWMODE_DISABLED:
+ break;
+ }
+
if(R_CompileShader_CheckStaticParms())
R_GLSL_Restart_f(&cmd_client);
}
{
case R_SHADOW_SHADOWMODE_SHADOWMAP2D:
return true;
- default:
+ case R_SHADOW_SHADOWMODE_DISABLED:
return false;
}
+ return false;
}
static void R_Shadow_FreeShadowMaps(void)
{
+ R_Shadow_UncompileWorldLights();
+
Mod_AllocLightmap_Free(&r_shadow_shadowmapatlas_state);
R_Shadow_SetShadowMode();
if (r_shadow_shadowmapvsdcttexture)
R_FreeTexture(r_shadow_shadowmapvsdcttexture);
r_shadow_shadowmapvsdcttexture = NULL;
+
}
static void r_shadow_start(void)
// allocate vertex processing arrays
memset(&r_shadow_bouncegrid_state, 0, sizeof(r_shadow_bouncegrid_state));
r_shadow_attenuationgradienttexture = NULL;
- r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
+ r_shadow_shadowmode = R_SHADOW_SHADOWMODE_DISABLED;
r_shadow_shadowmap2ddepthtexture = NULL;
r_shadow_shadowmap2ddepthbuffer = NULL;
r_shadow_shadowmapvsdcttexture = NULL;
static void r_shadow_shutdown(void)
{
CHECKGLERROR
- R_Shadow_UncompileWorldLights();
R_Shadow_FreeShadowMaps();
r_shadow_fbo2d = R_Mesh_CreateFramebufferObject(r_shadow_shadowmap2ddepthbuffer, r_shadow_shadowmap2ddepthtexture, NULL, NULL, NULL);
}
break;
- default:
- return;
+ case R_SHADOW_SHADOWMODE_DISABLED:
+ break;
}
}
static void R_Shadow_RenderMode_ShadowMap(int side, int size, int x, int y)
{
- float nearclip, farclip, bias;
+ float nearclip, farclip;
r_viewport_t viewport;
int flipped;
- float clearcolor[4];
if (r_shadow_rendermode != R_SHADOW_RENDERMODE_SHADOWMAP2D)
{
nearclip = r_shadow_shadowmapping_nearclip.value / rsurface.rtlight->radius;
farclip = 1.0f;
- bias = r_shadow_shadowmapping_bias.value * nearclip * (1024.0f / size);// * rsurface.rtlight->radius;
R_Viewport_InitRectSideView(&viewport, &rsurface.rtlight->matrix_lighttoworld, side, size, r_shadow_shadowmapborder, nearclip, farclip, NULL, x, y);
R_SetViewport(&viewport);
r_refdef.view.cullface_front = flipped ? r_shadow_cullface_back : r_shadow_cullface_front;
r_refdef.view.cullface_back = flipped ? r_shadow_cullface_front : r_shadow_cullface_back;
- Vector4Set(clearcolor, 1,1,1,1);
if (r_shadow_shadowmap2ddepthbuffer)
GL_ColorMask(1,1,1,1);
else
settings->rng_type = r_shadow_bouncegrid_rng_type.integer;
settings->rng_seed = r_shadow_bouncegrid_rng_seed.integer;
settings->bounceminimumintensity2 = bounceminimumintensity * bounceminimumintensity;
- settings->bounceminimumintensity2 = bounceminimumintensity * bounceminimumintensity;
settings->normalizevectors = r_shadow_bouncegrid_normalizevectors.integer != 0;
settings->subsamples = bound(1, r_shadow_bouncegrid_subsamples.integer, 4);
randomseed_t randomseed;
vec3_t baseshotcolor;
- t->started = 1;
-
normalphotonscaling = 1.0f / max(0.0000001f, r_shadow_bouncegrid_state.settings.energyperphoton);
for (lightindex = 0;lightindex < range2;lightindex++)
{
static void R_Shadow_BounceGrid_Slice_Task(taskqueue_task_t *t)
{
- t->started = 1;
R_Shadow_BounceGrid_Slice((int)t->i[0]);
t->done = 1;
}
TaskQueue_Yield(t);
return;
}
- t->started = 1;
slices = r_shadow_bouncegrid_state.resolution[2] - 2;
for (i = 0; i < slices; i++)
TaskQueue_Setup(r_shadow_bouncegrid_state.slices_tasks + i, NULL, R_Shadow_BounceGrid_Slice_Task, i + 1, 0, NULL, NULL);
{
float *pixels[4];
unsigned int resolution[3];
- t->started = 1;
if (r_shadow_bouncegrid_state.settings.blur)
{
VectorCopy(r_shadow_bouncegrid_state.resolution, resolution);
r_shadow_bouncegrid_state.lastupdatetime = realtime;
}
-void R_Shadow_BounceGrid_ClearTex_Task(taskqueue_task_t *t)
+static void R_Shadow_BounceGrid_ClearTex_Task(taskqueue_task_t *t)
{
- t->started = 1;
memset(r_shadow_bouncegrid_state.highpixels, 0, r_shadow_bouncegrid_state.numpixels * sizeof(float[4]));
t->done = 1;
}
static void R_Shadow_BounceGrid_TracePhotons_ShotTask(taskqueue_task_t *t)
{
r_shadow_bouncegrid_photon_t *p = (r_shadow_bouncegrid_photon_t *)t->p[0];
- t->started = 1;
R_Shadow_BounceGrid_TracePhotons_Shot(p, r_shadow_bouncegrid_state.settings.maxbounce, p->start, p->end, p->color, p->bounceminimumintensity2, p->startrefractiveindex);
t->done = 1;
}
static void R_Shadow_BounceGrid_EnqueuePhotons_Task(taskqueue_task_t *t)
{
int i;
- t->started = 1;
for (i = 0; i < r_shadow_bouncegrid_state.numphotons; i++)
TaskQueue_Setup(r_shadow_bouncegrid_state.photons_tasks + i, NULL, R_Shadow_BounceGrid_TracePhotons_ShotTask, 0, 0, r_shadow_bouncegrid_state.photons + i, NULL);
TaskQueue_Setup(&r_shadow_bouncegrid_state.photons_done_task, NULL, TaskQueue_Task_CheckTasksDone, r_shadow_bouncegrid_state.numphotons, 0, r_shadow_bouncegrid_state.photons_tasks, NULL);
// compile the light
rtlight->compiled = true;
- rtlight->shadowmode = rtlight->shadow ? (int)r_shadow_shadowmode : -1;
rtlight->static_numleafs = 0;
rtlight->static_numleafpvsbytes = 0;
rtlight->static_leaflist = NULL;
// all at once at the start of a level, not when it stalls gameplay.
// (especially important to benchmarks)
// compile light
- if (rtlight->isstatic && !nolight && (!rtlight->compiled || (rtlight->shadow && rtlight->shadowmode != (int)r_shadow_shadowmode)) && r_shadow_realtime_world_compile.integer)
- {
- if (rtlight->compiled)
- R_RTLight_Uncompile(rtlight);
+ if (rtlight->isstatic && !nolight && !rtlight->compiled && r_shadow_realtime_world_compile.integer)
R_RTLight_Compile(rtlight);
- }
// load cubemap
rtlight->currentcubemap = rtlight->cubemapname[0] ? R_GetCubemap(rtlight->cubemapname) : r_texture_whitecube;
{
int i;
int numsurfaces;
- unsigned char *shadowtrispvs, *lighttrispvs, *surfacesides;
+ unsigned char *shadowtrispvs, *surfacesides;
int numlightentities;
int numlightentities_noselfshadow;
int numshadowentities;
shadowentities = rtlight->cached_shadowentities;
shadowentities_noselfshadow = rtlight->cached_shadowentities_noselfshadow;
shadowtrispvs = rtlight->cached_shadowtrispvs;
- lighttrispvs = rtlight->cached_lighttrispvs;
surfacelist = rtlight->cached_surfacelist;
// make this the active rtlight for rendering purposes
{
int i;
int numsurfaces;
- unsigned char *shadowtrispvs, *lighttrispvs;
+ unsigned char *lighttrispvs;
int numlightentities;
int numlightentities_noselfshadow;
- int numshadowentities;
- int numshadowentities_noselfshadow;
entity_render_t **lightentities;
entity_render_t **lightentities_noselfshadow;
- entity_render_t **shadowentities;
- entity_render_t **shadowentities_noselfshadow;
int *surfacelist;
qboolean castshadows;
numlightentities = rtlight->cached_numlightentities;
numlightentities_noselfshadow = rtlight->cached_numlightentities_noselfshadow;
- numshadowentities = rtlight->cached_numshadowentities;
- numshadowentities_noselfshadow = rtlight->cached_numshadowentities_noselfshadow;
numsurfaces = rtlight->cached_numsurfaces;
lightentities = rtlight->cached_lightentities;
lightentities_noselfshadow = rtlight->cached_lightentities_noselfshadow;
- shadowentities = rtlight->cached_shadowentities;
- shadowentities_noselfshadow = rtlight->cached_shadowentities_noselfshadow;
- shadowtrispvs = rtlight->cached_shadowtrispvs;
lighttrispvs = rtlight->cached_lighttrispvs;
surfacelist = rtlight->cached_surfacelist;
castshadows = rtlight->castshadows;
if (castshadows && r_shadow_shadowmode == R_SHADOW_SHADOWMODE_SHADOWMAP2D)
{
- float borderbias;
- int size;
- float shadowmapoffsetnoselfshadow = 0;
matrix4x4_t radiustolight = rtlight->matrix_worldtolight;
Matrix4x4_Abs(&radiustolight);
- size = rtlight->shadowmapatlassidesize;
- borderbias = r_shadow_shadowmapborder / (float)(size - r_shadow_shadowmapborder);
-
//Con_Printf("distance %f lodlinear %i size %i\n", distance, lodlinear, size);
- if (rtlight->cached_numshadowentities_noselfshadow)
- shadowmapoffsetnoselfshadow = rtlight->shadowmapatlassidesize * 2;
-
// render lighting using the depth texture as shadowmap
// draw lighting in the unmasked areas
if (numsurfaces + numlightentities)
}
#define MAX_SCENELIGHTS 65536
-qboolean R_Shadow_PrepareLights_AddSceneLight(rtlight_t *rtlight)
+static qboolean R_Shadow_PrepareLights_AddSceneLight(rtlight_t *rtlight)
{
if (r_shadow_scenemaxlights <= r_shadow_scenenumlights)
{
int shadowmaptexturesize = bound(256, r_shadow_shadowmapping_texturesize.integer, (int)vid.maxtexturesize_2d);
int shadowmapmaxsize = bound(shadowmapborder+2, r_shadow_shadowmapping_maxsize.integer, shadowmaptexturesize / 8);
- if (r_shadow_shadowmaptexturesize != shadowmaptexturesize ||
- !(r_shadow_shadowmapping.integer || r_shadow_deferred.integer) ||
+ if (r_shadow_shadowmode_shadowmapping != r_shadow_shadowmapping.integer ||
+ r_shadow_shadowmode_deferred != r_shadow_deferred.integer ||
+ r_shadow_shadowmaptexturesize != shadowmaptexturesize ||
r_shadow_shadowmapvsdct != (r_shadow_shadowmapping_vsdct.integer != 0 && vid.renderpath == RENDERPATH_GL32) ||
r_shadow_shadowmapfilterquality != r_shadow_shadowmapping_filterquality.integer ||
r_shadow_shadowmapshadowsampler != r_shadow_shadowmapping_useshadowsampler.integer ||