if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCIL)
{
// decrement stencil if backface is behind depthbuffer
- qglCullFace(GL_BACK);CHECKGLERROR // quake is backwards, this culls front faces
+ GL_CullFace(GL_BACK); // quake is backwards, this culls front faces
qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);CHECKGLERROR
R_Mesh_Draw(0, numvertices, numtriangles, element3i);
// increment stencil if frontface is behind depthbuffer
- qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
+ GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);CHECKGLERROR
}
R_Mesh_Draw(0, numvertices, numtriangles, element3i);
R_Mesh_ResetTextureState();
GL_BlendFunc(GL_ONE, GL_ZERO);
GL_DepthMask(false);
- GL_DepthTest(true);
GL_Color(0, 0, 0, 1);
- qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
- qglEnable(GL_CULL_FACE);CHECKGLERROR
GL_Scissor(r_view.x, r_view.y, r_view.width, r_view.height);
r_shadow_rendermode = R_SHADOW_RENDERMODE_NONE;
GL_ColorMask(0, 0, 0, 0);
GL_BlendFunc(GL_ONE, GL_ZERO);
GL_DepthMask(false);
- GL_DepthTest(true);
qglPolygonOffset(r_refdef.shadowpolygonfactor, r_refdef.shadowpolygonoffset);CHECKGLERROR
qglDepthFunc(GL_LESS);CHECKGLERROR
- qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
qglEnable(GL_STENCIL_TEST);CHECKGLERROR
qglStencilFunc(GL_ALWAYS, 128, ~0);CHECKGLERROR
r_shadow_rendermode = r_shadow_shadowingrendermode;
if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCILTWOSIDE)
{
- qglDisable(GL_CULL_FACE);CHECKGLERROR
+ GL_CullFace(GL_NONE);
qglEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);CHECKGLERROR
qglActiveStencilFaceEXT(GL_BACK);CHECKGLERROR // quake is backwards, this is front faces
qglStencilMask(~0);CHECKGLERROR
}
else
{
- qglEnable(GL_CULL_FACE);CHECKGLERROR
+ GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
qglStencilMask(~0);CHECKGLERROR
// this is changed by every shadow render so its value here is unimportant
qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);CHECKGLERROR
R_Shadow_RenderMode_Reset();
GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
GL_DepthMask(false);
- GL_DepthTest(true);
qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
//qglDisable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
GL_Color(1, 1, 1, 1);
{
qglDepthFunc(GL_EQUAL);CHECKGLERROR
}
- qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
- qglEnable(GL_CULL_FACE);CHECKGLERROR
if (stenciltest)
{
qglEnable(GL_STENCIL_TEST);CHECKGLERROR
R_Shadow_RenderMode_Reset();
GL_BlendFunc(GL_ONE, GL_ONE);
GL_DepthMask(false);
- GL_DepthTest(!r_showdisabledepthtest.integer);
qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
GL_Color(0.0, 0.0125 * r_view.colorscale, 0.1 * r_view.colorscale, 1);
GL_ColorMask(r_view.colormask[0], r_view.colormask[1], r_view.colormask[2], 1);
qglDepthFunc(GL_GEQUAL);CHECKGLERROR
- qglCullFace(GL_FRONT);CHECKGLERROR // this culls back
- qglDisable(GL_CULL_FACE);CHECKGLERROR
qglDisable(GL_STENCIL_TEST);CHECKGLERROR
r_shadow_rendermode = R_SHADOW_RENDERMODE_VISIBLEVOLUMES;
}
R_Shadow_RenderMode_Reset();
GL_BlendFunc(GL_ONE, GL_ONE);
GL_DepthMask(false);
- GL_DepthTest(!r_showdisabledepthtest.integer);
qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
GL_Color(0.1 * r_view.colorscale, 0.0125 * r_view.colorscale, 0, 1);
GL_ColorMask(r_view.colormask[0], r_view.colormask[1], r_view.colormask[2], 1);
{
qglDepthFunc(GL_EQUAL);CHECKGLERROR
}
- qglCullFace(GL_FRONT);CHECKGLERROR // this culls back
- qglEnable(GL_CULL_FACE);CHECKGLERROR
if (stenciltest)
{
qglEnable(GL_STENCIL_TEST);CHECKGLERROR
R_Shadow_RenderMode_ActiveLight(NULL);
GL_BlendFunc(GL_ONE, GL_ZERO);
GL_DepthMask(true);
- GL_DepthTest(true);
qglPolygonOffset(r_refdef.polygonfactor, r_refdef.polygonoffset);CHECKGLERROR
//qglDisable(GL_POLYGON_OFFSET_FILL);CHECKGLERROR
GL_Color(1, 1, 1, 1);
GL_ColorMask(r_view.colormask[0], r_view.colormask[1], r_view.colormask[2], 1);
GL_Scissor(r_view.x, r_view.y, r_view.width, r_view.height);
qglDepthFunc(GL_LEQUAL);CHECKGLERROR
- qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
- qglEnable(GL_CULL_FACE);CHECKGLERROR
qglDisable(GL_STENCIL_TEST);CHECKGLERROR
qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);CHECKGLERROR
if (gl_support_stenciltwoside)
lightcolorbase[2] = r_shadow_rtlight->currentcolor[2] * rsurface_entity->colormod[2] * rsurface_texture->currentalpha;
if ((r_shadow_rtlight->ambientscale + r_shadow_rtlight->diffusescale) * VectorLength2(lightcolorbase) + (r_shadow_rtlight->specularscale * rsurface_texture->specularscale) * VectorLength2(lightcolorbase) < (1.0f / 1048576.0f))
return;
- if ((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE))
- {
- qglDisable(GL_CULL_FACE);CHECKGLERROR
- }
- else
- {
- qglEnable(GL_CULL_FACE);CHECKGLERROR
- }
+ GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
+ GL_CullFace(((rsurface_texture->textureflags & Q3TEXTUREFLAG_TWOSIDED) || (rsurface_entity->flags & RENDER_NOCULLFACE)) ? GL_NONE : GL_FRONT); // quake is backwards, this culls back faces
if (rsurface_texture->colormapping)
{
- qboolean dopants = rsurface_texture->skin.pants != NULL && VectorLength2(rsurface_entity->colormap_pantscolor) >= (1.0f / 1048576.0f);
- qboolean doshirt = rsurface_texture->skin.shirt != NULL && VectorLength2(rsurface_entity->colormap_shirtcolor) >= (1.0f / 1048576.0f);
+ qboolean dopants = rsurface_texture->currentskinframe->pants != NULL && VectorLength2(rsurface_entity->colormap_pantscolor) >= (1.0f / 1048576.0f);
+ qboolean doshirt = rsurface_texture->currentskinframe->shirt != NULL && VectorLength2(rsurface_entity->colormap_shirtcolor) >= (1.0f / 1048576.0f);
if (dopants)
{
lightcolorpants[0] = lightcolorbase[0] * rsurface_entity->colormap_pantscolor[0];
switch (r_shadow_rendermode)
{
case R_SHADOW_RENDERMODE_VISIBLELIGHTING:
- R_Shadow_RenderSurfacesLighting_VisibleLighting(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->skin.pants, rsurface_texture->skin.shirt, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
+ GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST) && !r_showdisabledepthtest.integer);
+ R_Shadow_RenderSurfacesLighting_VisibleLighting(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
break;
case R_SHADOW_RENDERMODE_LIGHT_GLSL:
- R_Shadow_RenderSurfacesLighting_Light_GLSL(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->skin.pants, rsurface_texture->skin.shirt, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
+ R_Shadow_RenderSurfacesLighting_Light_GLSL(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
break;
case R_SHADOW_RENDERMODE_LIGHT_DOT3:
- R_Shadow_RenderSurfacesLighting_Light_Dot3(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->skin.pants, rsurface_texture->skin.shirt, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
+ R_Shadow_RenderSurfacesLighting_Light_Dot3(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
break;
case R_SHADOW_RENDERMODE_LIGHT_VERTEX:
- R_Shadow_RenderSurfacesLighting_Light_Vertex(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->skin.pants, rsurface_texture->skin.shirt, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
+ R_Shadow_RenderSurfacesLighting_Light_Vertex(numsurfaces, surfacelist, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, dopants, doshirt);
break;
default:
Con_Printf("R_Shadow_RenderSurfacesLighting: unknown r_shadow_rendermode %i\n", r_shadow_rendermode);
switch (r_shadow_rendermode)
{
case R_SHADOW_RENDERMODE_VISIBLELIGHTING:
- R_Shadow_RenderSurfacesLighting_VisibleLighting(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
+ GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST) && !r_showdisabledepthtest.integer);
+ R_Shadow_RenderSurfacesLighting_VisibleLighting(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
break;
case R_SHADOW_RENDERMODE_LIGHT_GLSL:
- R_Shadow_RenderSurfacesLighting_Light_GLSL(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
+ R_Shadow_RenderSurfacesLighting_Light_GLSL(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
break;
case R_SHADOW_RENDERMODE_LIGHT_DOT3:
- R_Shadow_RenderSurfacesLighting_Light_Dot3(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
+ R_Shadow_RenderSurfacesLighting_Light_Dot3(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
break;
case R_SHADOW_RENDERMODE_LIGHT_VERTEX:
- R_Shadow_RenderSurfacesLighting_Light_Vertex(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->skin.nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
+ R_Shadow_RenderSurfacesLighting_Light_Vertex(numsurfaces, surfacelist, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, r_shadow_rtlight->specularscale * rsurface_texture->specularscale, false, false);
break;
default:
Con_Printf("R_Shadow_RenderSurfacesLighting: unknown r_shadow_rendermode %i\n", r_shadow_rendermode);
void R_RTLight_Update(dlight_t *light, int isstatic)
{
- int j, k;
- float scale;
+ double scale;
rtlight_t *rtlight = &light->rtlight;
R_RTLight_Uncompile(rtlight);
memset(rtlight, 0, sizeof(*rtlight));
rtlight->cullmaxs[2] = rtlight->shadoworigin[2] + rtlight->radius;
rtlight->cubemapname[0] = 0;
if (light->cubemapname[0])
- strcpy(rtlight->cubemapname, light->cubemapname);
+ strlcpy(rtlight->cubemapname, light->cubemapname, sizeof(rtlight->cubemapname));
else if (light->cubemapnum > 0)
sprintf(rtlight->cubemapname, "cubemaps/%i", light->cubemapnum);
rtlight->shadow = light->shadow;
rtlight->specularscale = light->specularscale;
rtlight->flags = light->flags;
Matrix4x4_Invert_Simple(&rtlight->matrix_worldtolight, &light->matrix);
- // ConcatScale won't work here because this needs to scale rotate and
- // translate, not just rotate
- scale = 1.0f / rtlight->radius;
- for (k = 0;k < 3;k++)
- for (j = 0;j < 4;j++)
- rtlight->matrix_worldtolight.m[k][j] *= scale;
+ // this has to scale both rotate and translate because this is an already
+ // inverted matrix (it transforms from world to light space, not the other
+ // way around)
+ scale = 1.0 / rtlight->radius;
+ Matrix4x4_Scale(&rtlight->matrix_worldtolight, scale, scale);
}
// compiles rtlight geometry
if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCIL)
{
// decrement stencil if backface is behind depthbuffer
- qglCullFace(GL_BACK);CHECKGLERROR // quake is backwards, this culls front faces
+ GL_CullFace(GL_BACK); // quake is backwards, this culls front faces
qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);CHECKGLERROR
R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i);
// increment stencil if frontface is behind depthbuffer
- qglCullFace(GL_FRONT);CHECKGLERROR // quake is backwards, this culls back faces
+ GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);CHECKGLERROR
}
R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i);
&& (r_refdef.worldmodel == NULL || r_refdef.worldmodel->brush.BoxTouchingLeafPVS == NULL || r_refdef.worldmodel->brush.BoxTouchingLeafPVS(r_refdef.worldmodel, leafpvs, ent->mins, ent->maxs)))
{
// about the VectorDistance2 - light emitting entities should not cast their own shadow
- if ((ent->flags & RENDER_SHADOW) && model->DrawShadowVolume && VectorDistance2(ent->origin, rtlight->shadoworigin) > 0.1)
+ vec3_t org;
+ Matrix4x4_OriginFromMatrix(&ent->matrix, org);
+ if ((ent->flags & RENDER_SHADOW) && model->DrawShadowVolume && VectorDistance2(org, rtlight->shadoworigin) > 0.1)
shadowentities[numshadowentities++] = ent;
if (r_viewcache.entityvisible[i] && (ent->flags & RENDER_LIGHT) && model->DrawLight)
lightentities[numlightentities++] = ent;
if (i >= MAX_CUBEMAPS)
return r_texture_whitecube;
numcubemaps++;
- strcpy(cubemaps[i].basename, basename);
+ strlcpy(cubemaps[i].basename, basename, sizeof(cubemaps[i].basename));
cubemaps[i].texture = R_Shadow_LoadCubemap(cubemaps[i].basename);
if (!cubemaps[i].texture)
cubemaps[i].texture = r_texture_whitecube;
// remove quotes on cubemapname
if (cubemapname[0] == '"' && cubemapname[strlen(cubemapname) - 1] == '"')
{
- cubemapname[strlen(cubemapname)-1] = 0;
- strcpy(cubemapname, cubemapname + 1);
+ size_t namelen;
+ namelen = strlen(cubemapname) - 2;
+ memmove(cubemapname, cubemapname + 1, namelen);
+ cubemapname[namelen] = '\0';
}
if (a < 8)
{
if (com_token[0] == '}')
break; // end of entity
if (com_token[0] == '_')
- strcpy(key, com_token + 1);
+ strlcpy(key, com_token + 1, sizeof(key));
else
- strcpy(key, com_token);
+ strlcpy(key, com_token, sizeof(key));
while (key[strlen(key)-1] == ' ') // remove trailing spaces
key[strlen(key)-1] = 0;
if (!COM_ParseTokenConsole(&data))
break; // error
- strcpy(value, com_token);
+ strlcpy(value, com_token, sizeof(value));
// now that we have the key pair worked out...
if (!strcmp("light", key))
return;
}
if (Cmd_Argc() == 3)
- strcpy(cubemapname, Cmd_Argv(2));
+ strlcpy(cubemapname, Cmd_Argv(2), sizeof(cubemapname));
else
cubemapname[0] = 0;
}
r_shadow_bufferlight.radius = r_shadow_selectedlight->radius;
r_shadow_bufferlight.style = r_shadow_selectedlight->style;
if (r_shadow_selectedlight->cubemapname)
- strcpy(r_shadow_bufferlight.cubemapname, r_shadow_selectedlight->cubemapname);
+ strlcpy(r_shadow_bufferlight.cubemapname, r_shadow_selectedlight->cubemapname, sizeof(r_shadow_bufferlight.cubemapname));
else
r_shadow_bufferlight.cubemapname[0] = 0;
r_shadow_bufferlight.shadow = r_shadow_selectedlight->shadow;