rendering lighting everywhere but shadow.
In our case we use a biased stencil clear of 128 to avoid requiring the
-stencil wrap extension (but probably should support it).
+stencil wrap extension (but probably should support it), and to address
+Creative's patent on this sort of technology we also draw the frontfaces
+first, and backfaces second (decrement, increment).
+
+Patent warning:
+This algorithm may be covered by Creative's patent (US Patent #6384822)
+on Carmack's Reverse paper (which I have not read), however that patent
+seems to be about drawing a stencil shadow from a model in an otherwise
+unshadowed scene, where as realtime lighting technology draws light where
+shadows do not lie.
GL_VertexPointer(varray_vertex3f2);
if (r_shadowstage == SHADOWSTAGE_STENCIL)
{
- // increment stencil if backface is behind depthbuffer
- qglCullFace(GL_BACK); // quake is backwards, this culls front faces
- qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
- R_Mesh_Draw(outverts, tris, shadowelements);
- c_rt_shadowmeshes++;
- c_rt_shadowtris += numtris;
// decrement stencil if frontface is behind depthbuffer
qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
+ R_Mesh_Draw(outverts, tris, shadowelements);
+ c_rt_shadowmeshes++;
+ c_rt_shadowtris += numtris;
+ // increment stencil if backface is behind depthbuffer
+ qglCullFace(GL_BACK); // quake is backwards, this culls front faces
+ qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
}
R_Mesh_Draw(outverts, tris, shadowelements);
c_rt_shadowmeshes++;
shadowmesh_t *mesh;
if (r_shadowstage == SHADOWSTAGE_STENCIL)
{
- // increment stencil if backface is behind depthbuffer
- qglCullFace(GL_BACK); // quake is backwards, this culls front faces
- qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
+ // decrement stencil if frontface is behind depthbuffer
+ qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
+ qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
for (mesh = firstmesh;mesh;mesh = mesh->next)
{
GL_VertexPointer(mesh->vertex3f);
c_rtcached_shadowmeshes++;
c_rtcached_shadowtris += mesh->numtriangles;
}
- // decrement stencil if frontface is behind depthbuffer
- qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
- qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
+ // increment stencil if backface is behind depthbuffer
+ qglCullFace(GL_BACK); // quake is backwards, this culls front faces
+ qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
}
for (mesh = firstmesh;mesh;mesh = mesh->next)
{
GL_DepthTest(true);
R_Mesh_State_Texture(&m);
GL_Color(0, 0, 0, 1);
+ qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
qglDisable(GL_SCISSOR_TEST);
r_shadowstage = SHADOWSTAGE_NONE;
else
qglDisable(GL_POLYGON_OFFSET_FILL);
qglDepthFunc(GL_LESS);
+ qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
qglEnable(GL_STENCIL_TEST);
qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
qglStencilFunc(GL_ALWAYS, 128, 0xFF);
GL_Color(1, 1, 1, 1);
qglColorMask(1, 1, 1, 1);
qglDepthFunc(GL_EQUAL);
+ qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
qglDisable(GL_STENCIL_TEST);
qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
qglStencilFunc(GL_EQUAL, 128, 0xFF);
GL_Color(1, 1, 1, 1);
qglColorMask(1, 1, 1, 1);
qglDepthFunc(GL_EQUAL);
+ qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
qglEnable(GL_STENCIL_TEST);
qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// only draw light where this geometry was already rendered AND the
qglColorMask(1, 1, 1, 1);
qglDisable(GL_SCISSOR_TEST);
qglDepthFunc(GL_LEQUAL);
+ qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
qglDisable(GL_STENCIL_TEST);
qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
qglStencilFunc(GL_ALWAYS, 128, 0xFF);
if (face->lighttemp_castshadow)
{
face->lighttemp_castshadow = false;
- if (!(face->texture->renderflags & (Q3MTEXTURERENDERFLAGS_NODRAW | Q3MTEXTURERENDERFLAGS_SKY)))
+ if (!(face->texture->surfaceflags & (Q3SURFACEFLAG_NODRAW | Q3SURFACEFLAG_SKY)))
{
if (e->castshadows)
if (!(face->texture->nativecontents & CONTENTSQ3_TRANSLUCENT))
Mod_ShadowMesh_AddMesh(r_shadow_mempool, castmesh, NULL, NULL, NULL, face->data_vertex3f, NULL, NULL, NULL, NULL, face->num_triangles, face->data_element3i);
- if (!(face->texture->renderflags & (Q3MTEXTURERENDERFLAGS_SKY)))
+ if (!(face->texture->surfaceflags & Q3SURFACEFLAG_SKY))
Mod_ShadowMesh_AddMesh(r_shadow_mempool, e->meshchain_light, face->texture->skin.base, face->texture->skin.gloss, face->texture->skin.nmap, face->data_vertex3f, face->data_svector3f, face->data_tvector3f, face->data_normal3f, face->data_texcoordtexture2f, face->num_triangles, face->data_element3i);
}
}