+ vec3_t relativeshadoworigin, relativeshadowmins, relativeshadowmaxs;
+ vec_t relativeshadowradius;
+ if (ent == r_refdef.worldentity)
+ {
+ if (rtlight->compiled && r_shadow_realtime_world_compile.integer && r_shadow_realtime_world_compileshadow.integer)
+ {
+ shadowmesh_t *mesh;
+ R_Mesh_Matrix(&ent->matrix);
+ for (mesh = rtlight->static_meshchain_shadow;mesh;mesh = mesh->next)
+ {
+ R_Mesh_VertexPointer(mesh->vertex3f);
+ GL_LockArrays(0, mesh->numverts);
+ if (r_shadowstage == R_SHADOWSTAGE_STENCIL)
+ {
+ // decrement stencil if backface is behind depthbuffer
+ qglCullFace(GL_BACK); // quake is backwards, this culls front faces
+ qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
+ R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i);
+ c_rtcached_shadowmeshes++;
+ c_rtcached_shadowtris += mesh->numtriangles;
+ // increment stencil if frontface is behind depthbuffer
+ qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
+ qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
+ }
+ R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i);
+ c_rtcached_shadowmeshes++;
+ c_rtcached_shadowtris += mesh->numtriangles;
+ GL_LockArrays(0, 0);
+ }
+ }
+ else if (numsurfaces)
+ {
+ R_Mesh_Matrix(&ent->matrix);
+ ent->model->DrawShadowVolume(ent, rtlight->shadoworigin, rtlight->radius, numsurfaces, surfacelist, rtlight->cullmins, rtlight->cullmaxs);
+ }
+ }
+ else
+ {
+ Matrix4x4_Transform(&ent->inversematrix, rtlight->shadoworigin, relativeshadoworigin);
+ relativeshadowradius = rtlight->radius / ent->scale;
+ relativeshadowmins[0] = relativeshadoworigin[0] - relativeshadowradius;
+ relativeshadowmins[1] = relativeshadoworigin[1] - relativeshadowradius;
+ relativeshadowmins[2] = relativeshadoworigin[2] - relativeshadowradius;
+ relativeshadowmaxs[0] = relativeshadoworigin[0] + relativeshadowradius;
+ relativeshadowmaxs[1] = relativeshadoworigin[1] + relativeshadowradius;
+ relativeshadowmaxs[2] = relativeshadoworigin[2] + relativeshadowradius;
+ R_Mesh_Matrix(&ent->matrix);
+ ent->model->DrawShadowVolume(ent, relativeshadoworigin, relativeshadowradius, ent->model->nummodelsurfaces, ent->model->surfacelist, relativeshadowmins, relativeshadowmaxs);
+ }
+}
+
+void R_Shadow_DrawEntityLight(entity_render_t *ent, rtlight_t *rtlight, vec3_t lightcolorbase, int numsurfaces, int *surfacelist)
+{
+ shadowmesh_t *mesh;
+ // set up properties for rendering light onto this entity
+ r_shadow_entitylightcolor[0] = lightcolorbase[0] * ent->colormod[0] * ent->alpha;
+ r_shadow_entitylightcolor[1] = lightcolorbase[1] * ent->colormod[1] * ent->alpha;
+ r_shadow_entitylightcolor[2] = lightcolorbase[2] * ent->colormod[2] * ent->alpha;
+ Matrix4x4_Concat(&r_shadow_entitytolight, &rtlight->matrix_worldtolight, &ent->matrix);
+ Matrix4x4_Concat(&r_shadow_entitytoattenuationxyz, &matrix_attenuationxyz, &r_shadow_entitytolight);
+ Matrix4x4_Concat(&r_shadow_entitytoattenuationz, &matrix_attenuationz, &r_shadow_entitytolight);
+ Matrix4x4_Transform(&ent->inversematrix, rtlight->shadoworigin, r_shadow_entitylightorigin);
+ Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, r_shadow_entityeyeorigin);
+ R_Mesh_Matrix(&ent->matrix);
+ if (r_shadowstage == R_SHADOWSTAGE_LIGHT_GLSL)
+ {
+ R_Mesh_TexBindCubeMap(3, R_GetTexture(r_shadow_lightcubemap));
+ R_Mesh_TexMatrix(3, &r_shadow_entitytolight);
+ qglUniform3fARB(qglGetUniformLocationARB(r_shadow_lightprog, "LightPosition"), r_shadow_entitylightorigin[0], r_shadow_entitylightorigin[1], r_shadow_entitylightorigin[2]);CHECKGLERROR
+ if (r_shadow_lightpermutation & (SHADERPERMUTATION_SPECULAR | SHADERPERMUTATION_FOG | SHADERPERMUTATION_OFFSETMAPPING))
+ {
+ qglUniform3fARB(qglGetUniformLocationARB(r_shadow_lightprog, "EyePosition"), r_shadow_entityeyeorigin[0], r_shadow_entityeyeorigin[1], r_shadow_entityeyeorigin[2]);CHECKGLERROR
+ }
+ }
+ if (ent == r_refdef.worldentity)
+ {
+ if (rtlight->compiled && r_shadow_realtime_world_compile.integer && r_shadow_realtime_world_compilelight.integer)
+ {
+ for (mesh = rtlight->static_meshchain_light;mesh;mesh = mesh->next)
+ {
+ rtexture_t *glosstexture = r_texture_black;
+ float specularscale = 0;
+ if (mesh->map_specular)
+ {
+ if (r_shadow_gloss.integer >= 1 && r_shadow_glossintensity.value > 0 && r_shadow_rtlight->specularscale > 0)
+ {
+ glosstexture = mesh->map_specular;
+ specularscale = r_shadow_rtlight->specularscale * r_shadow_glossintensity.value;
+ }
+ }
+ else
+ {
+ if (r_shadow_gloss.integer >= 2 && r_shadow_gloss2intensity.value > 0 && r_shadow_glossintensity.value > 0 && r_shadow_rtlight->specularscale > 0)
+ {
+ glosstexture = r_texture_white;
+ specularscale = r_shadow_rtlight->specularscale * r_shadow_gloss2intensity.value;
+ }
+ }
+ if ((r_shadow_rtlight->ambientscale + r_shadow_rtlight->diffusescale) * VectorLength2(lightcolorbase) + specularscale * VectorLength2(lightcolorbase) < (1.0f / 1048576.0f))
+ continue;
+ R_Shadow_RenderLighting(0, mesh->numverts, mesh->numtriangles, mesh->element3i, mesh->vertex3f, mesh->svector3f, mesh->tvector3f, mesh->normal3f, mesh->texcoord2f, r_shadow_entitylightcolor, vec3_origin, vec3_origin, mesh->map_diffuse, r_texture_black, r_texture_black, mesh->map_normal, glosstexture);
+ }
+ }
+ else
+ ent->model->DrawLight(ent, r_shadow_entitylightcolor, numsurfaces, surfacelist);
+ }
+ else
+ ent->model->DrawLight(ent, r_shadow_entitylightcolor, ent->model->nummodelsurfaces, ent->model->surfacelist);
+}
+
+void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
+{
+ int i, usestencil;