- mleaf_t *leaf;
- msurface_t *surf;
- VectorCopy(rtlight->shadoworigin, rtlight->cullmins);
- VectorCopy(rtlight->shadoworigin, rtlight->cullmaxs);
- i = CL_PointQ1Contents(rtlight->shadoworigin);
-
- for (i = 0, surf = cl.worldmodel->brushq1.surfaces + cl.worldmodel->brushq1.firstmodelsurface;i < cl.worldmodel->brushq1.nummodelsurfaces;i++, surf++)
- surf->lighttemp_castshadow = false;
-
- if (r_shadow_portallight.integer && i != CONTENTS_SOLID && i != CONTENTS_SKY)
- {
- qbyte *byteleafpvs;
- qbyte *bytesurfacepvs;
-
- byteleafpvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.num_leafs);
- bytesurfacepvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.numsurfaces);
-
- Portal_Visibility(cl.worldmodel, rtlight->shadoworigin, byteleafpvs, bytesurfacepvs, NULL, 0, true, mins, maxs, rtlight->cullmins, rtlight->cullmaxs);
-
- // make a pvs that only includes things within the box
- for (i = 0, leaf = cl.worldmodel->brushq1.data_leafs;i < cl.worldmodel->brushq1.num_leafs;i++, leaf++)
- {
- if (byteleafpvs[i] && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
- {
- SETPVSBIT(lightpvs, leaf->clusterindex);
- for (k = 0;k < 3;k++)
- {
- if (rtlight->cullmins[k] > leaf->mins[k]) rtlight->cullmins[k] = leaf->mins[k];
- if (rtlight->cullmaxs[k] < leaf->maxs[k]) rtlight->cullmaxs[k] = leaf->maxs[k];
- }
- }
- }
-
- for (i = 0, surf = cl.worldmodel->brushq1.surfaces;i < cl.worldmodel->brushq1.numsurfaces;i++, surf++)
- if (bytesurfacepvs[i] && BoxesOverlap(surf->poly_mins, surf->poly_maxs, mins, maxs))
- surf->lighttemp_castshadow = true;
-
- Mem_Free(byteleafpvs);
- Mem_Free(bytesurfacepvs);
-
- // make a cluster list for fast visibility checking during rendering
- for (i = 0, rtlight->static_numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
- if (CHECKPVSBIT(lightpvs, i))
- rtlight->static_numclusters++;
- rtlight->static_clusterindices = Mem_Alloc(r_shadow_mempool, rtlight->static_numclusters * sizeof(int));
- for (i = 0, rtlight->static_numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
- if (CHECKPVSBIT(lightpvs, i))
- rtlight->static_clusterindices[rtlight->static_numclusters++] = i;
- }
- else
- {
- for (i = 0, leaf = cl.worldmodel->brushq1.data_leafs;i < cl.worldmodel->brushq1.num_leafs;i++, leaf++)
- {
- if (CHECKPVSBIT(lightfullpvs, leaf->clusterindex) && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
- {
- // make a pvs that only includes things within the box
- SETPVSBIT(lightpvs, leaf->clusterindex);
- for (k = 0;k < 3;k++)
- {
- if (rtlight->cullmins[k] > leaf->mins[k]) rtlight->cullmins[k] = leaf->mins[k];
- if (rtlight->cullmaxs[k] < leaf->maxs[k]) rtlight->cullmaxs[k] = leaf->maxs[k];
- }
- for (j = 0;j < leaf->nummarksurfaces;j++)
- {
- surf = cl.worldmodel->brushq1.surfaces + leaf->firstmarksurface[j];
- if (!surf->lighttemp_castshadow && BoxesOverlap(surf->poly_mins, surf->poly_maxs, mins, maxs))
- surf->lighttemp_castshadow = true;
- }
- }
- }
-
- // make a pvs that only includes things within the box
- for (i = 0, leaf = cl.worldmodel->brushq1.data_leafs;i < cl.worldmodel->brushq1.num_leafs;i++, leaf++)
- if (CHECKPVSBIT(lightfullpvs, leaf->clusterindex) && BoxesOverlap(leaf->mins, leaf->maxs, mins, maxs))
- SETPVSBIT(lightpvs, leaf->clusterindex);
-
- // make a cluster list for fast visibility checking during rendering
- for (i = 0, rtlight->static_numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
- if (CHECKPVSBIT(lightpvs, i))
- rtlight->static_numclusters++;
- rtlight->static_clusterindices = Mem_Alloc(r_shadow_mempool, rtlight->static_numclusters * sizeof(int));
- for (i = 0, rtlight->static_numclusters = 0;i < cl.worldmodel->brush.num_pvsclusters;i++)
- if (CHECKPVSBIT(lightpvs, i))
- rtlight->static_clusterindices[rtlight->static_numclusters++] = i;
- }
-
- // add surfaces to shadow casting mesh and light mesh
- for (i = 0, surf = cl.worldmodel->brushq1.surfaces + cl.worldmodel->brushq1.firstmodelsurface;i < cl.worldmodel->brushq1.nummodelsurfaces;i++, surf++)
- {
- if (surf->lighttemp_castshadow)
- {
- surf->lighttemp_castshadow = false;
- if (rtlight->shadow && (surf->flags & SURF_SHADOWCAST))
- Mod_ShadowMesh_AddMesh(r_shadow_mempool, castmesh, NULL, NULL, NULL, surf->mesh.data_vertex3f, NULL, NULL, NULL, NULL, surf->mesh.num_triangles, surf->mesh.data_element3i);
- if (!(surf->flags & SURF_DRAWSKY))
- Mod_ShadowMesh_AddMesh(r_shadow_mempool, rtlight->static_meshchain_light, surf->texinfo->texture->skin.base, surf->texinfo->texture->skin.gloss, surf->texinfo->texture->skin.nmap, surf->mesh.data_vertex3f, surf->mesh.data_svector3f, surf->mesh.data_tvector3f, surf->mesh.data_normal3f, surf->mesh.data_texcoordtexture2f, surf->mesh.num_triangles, surf->mesh.data_element3i);
- }
- }
+ rtlight->static_meshchain_shadow = Mod_ShadowMesh_Begin(r_shadow_mempool, 32768, 32768, NULL, NULL, NULL, false, false, true);
+ model->DrawShadowVolume(ent, rtlight->shadoworigin, rtlight->radius, numsurfaces, r_shadow_buffer_surfacelist);
+ rtlight->static_meshchain_shadow = Mod_ShadowMesh_Finish(r_shadow_mempool, rtlight->static_meshchain_shadow, false, false);
+ }
+ if (model->DrawLight)
+ {
+ rtlight->static_meshchain_light = Mod_ShadowMesh_Begin(r_shadow_mempool, 32768, 32768, NULL, NULL, NULL, true, false, true);
+ model->DrawLight(ent, rtlight->shadoworigin, vec3_origin, rtlight->radius, vec3_origin, &r_identitymatrix, &r_identitymatrix, &r_identitymatrix, NULL, numsurfaces, r_shadow_buffer_surfacelist);
+ rtlight->static_meshchain_light = Mod_ShadowMesh_Finish(r_shadow_mempool, rtlight->static_meshchain_light, true, false);