}
}
-void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
+void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs)
{
int meshnum;
- vec3_t lightmins, lightmaxs;
aliasmesh_t *mesh;
aliasskin_t *skin;
float projectdistance, *vertex3f;
if (!(ent->flags & RENDER_SHADOW))
return;
- lightmins[0] = relativelightorigin[0] - lightradius;
- lightmins[1] = relativelightorigin[1] - lightradius;
- lightmins[2] = relativelightorigin[2] - lightradius;
- lightmaxs[0] = relativelightorigin[0] + lightradius;
- lightmaxs[1] = relativelightorigin[1] + lightradius;
- lightmaxs[2] = relativelightorigin[2] + lightradius;
// check the box in modelspace, it was already checked in worldspace
if (!BoxesOverlap(ent->model->normalmins, ent->model->normalmaxs, lightmins, lightmaxs))
return;
*outnumsurfacespointer = outnumsurfaces;
}
-void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
+void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs)
{
model_t *model = ent->model;
- vec3_t lightmins, lightmaxs;
msurface_t *surface;
int surfacelistindex;
if (r_drawcollisionbrushes.integer < 2)
{
- lightmins[0] = relativelightorigin[0] - lightradius;
- lightmins[1] = relativelightorigin[1] - lightradius;
- lightmins[2] = relativelightorigin[2] - lightradius;
- lightmaxs[0] = relativelightorigin[0] + lightradius;
- lightmaxs[1] = relativelightorigin[1] + lightradius;
- lightmaxs[2] = relativelightorigin[2] + lightradius;
R_Mesh_Matrix(&ent->matrix);
R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist)
{
model_t *model = ent->model;
- vec3_t lightmins, lightmaxs, modelorg;
msurface_t *surface;
texture_t *t;
int surfacelistindex;
if (r_drawcollisionbrushes.integer < 2)
{
- lightmins[0] = relativelightorigin[0] - lightradius;
- lightmins[1] = relativelightorigin[1] - lightradius;
- lightmins[2] = relativelightorigin[2] - lightradius;
- lightmaxs[0] = relativelightorigin[0] + lightradius;
- lightmaxs[1] = relativelightorigin[1] + lightradius;
- lightmaxs[2] = relativelightorigin[2] + lightradius;
R_Mesh_Matrix(&ent->matrix);
- Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
R_UpdateTextureInfo(ent);
for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
{
*outnumsurfacespointer = outnumsurfaces;
}
-void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
+void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs)
{
model_t *model = ent->model;
- vec3_t lightmins, lightmaxs;
msurface_t *surface;
int surfacelistindex;
if (r_drawcollisionbrushes.integer < 2)
{
- lightmins[0] = relativelightorigin[0] - lightradius;
- lightmins[1] = relativelightorigin[1] - lightradius;
- lightmins[2] = relativelightorigin[2] - lightradius;
- lightmaxs[0] = relativelightorigin[0] + lightradius;
- lightmaxs[1] = relativelightorigin[1] + lightradius;
- lightmaxs[2] = relativelightorigin[2] + lightradius;
R_Mesh_Matrix(&ent->matrix);
R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
out[0] += v->origin[0] * matrix[0] + v->origin[1] * matrix[1] + v->origin[2] * matrix[ 2] + v->origin[3] * matrix[ 3];
out[1] += v->origin[0] * matrix[4] + v->origin[1] * matrix[5] + v->origin[2] * matrix[ 6] + v->origin[3] * matrix[ 7];
out[2] += v->origin[0] * matrix[8] + v->origin[1] * matrix[9] + v->origin[2] * matrix[10] + v->origin[3] * matrix[11];
- }
+ }
}
else
{
#define BOUNDI(VALUE,MIN,MAX) if (VALUE < MIN || VALUE >= MAX) Host_Error("model %s has an invalid ##VALUE (%d exceeds %d - %d)\n", loadmodel->name, VALUE, MIN, MAX);
#define BOUNDF(VALUE,MIN,MAX) if (VALUE < MIN || VALUE >= MAX) Host_Error("model %s has an invalid ##VALUE (%f exceeds %f - %f)\n", loadmodel->name, VALUE, MIN, MAX);
extern void R_Model_Alias_Draw(entity_render_t *ent);
-extern void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist);
+extern void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs);
extern void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist);
void Mod_IDP0_Load(model_t *mod, void *buffer)
{
extern void R_Q1BSP_DrawSky(entity_render_t *ent);
extern void R_Q1BSP_Draw(entity_render_t *ent);
extern void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer);
-extern void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist);
+extern void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs);
extern void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist);
void Mod_Q1BSP_Load(model_t *mod, void *buffer)
{
extern void R_Q3BSP_DrawSky(struct entity_render_s *ent);
extern void R_Q3BSP_Draw(struct entity_render_s *ent);
extern void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer);
-extern void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist);
+extern void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs);
extern void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist);
void Mod_Q3BSP_Load(model_t *mod, void *buffer)
{
// gathers info on which clusters and surfaces are lit by light, as well as calculating a bounding box
void(*GetLightInfo)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer);
// draw a shadow volume for the model based on light source
- void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist);
+ void(*DrawShadowVolume)(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs);
// draw the lighting on a model (through stencil)
void(*DrawLight)(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist);
// trace a box against this model
R_Shadow_RenderVolume(outverts, tris, varray_vertex3f2, shadowelements);
}
-void R_Shadow_MarkVolumeFromBox(int firsttriangle, int numtris, const float *invertex3f, const int *elements, const vec3_t projectorigin, vec3_t lightmins, vec3_t lightmaxs, vec3_t surfacemins, vec3_t surfacemaxs)
+void R_Shadow_MarkVolumeFromBox(int firsttriangle, int numtris, const float *invertex3f, const int *elements, const vec3_t projectorigin, const vec3_t lightmins, const vec3_t lightmaxs, const vec3_t surfacemins, const vec3_t surfacemaxs)
{
int t, tend;
const int *e;
void R_RTLight_Compile(rtlight_t *rtlight)
{
int shadowmeshes, shadowtris, lightmeshes, lighttris, numclusters, numsurfaces;
- entity_render_t *ent = &cl_entities[0].render;
- model_t *model = ent->model;
+ entity_render_t *ent = r_refdef.worldentity;
+ model_t *model = r_refdef.worldmodel;
// compile the light
rtlight->compiled = true;
if (model->DrawShadowVolume && rtlight->shadow)
{
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);
+ model->DrawShadowVolume(ent, rtlight->shadoworigin, rtlight->radius, numsurfaces, r_shadow_buffer_surfacelist, rtlight->cullmins, rtlight->cullmaxs);
rtlight->static_meshchain_shadow = Mod_ShadowMesh_Finish(r_shadow_mempool, rtlight->static_meshchain_shadow, false, false);
}
if (model->DrawLight)
int numclusters, numsurfaces;
int *clusterlist, *surfacelist;
qbyte *clusterpvs;
- vec3_t cullmins, cullmaxs;
+ vec3_t cullmins, cullmaxs, relativelightmins, relativelightmaxs;
shadowmesh_t *mesh;
rmeshstate_t m;
else if (numsurfaces)
{
Matrix4x4_Transform(&ent->inversematrix, rtlight->shadoworigin, relativelightorigin);
- ent->model->DrawShadowVolume(ent, relativelightorigin, rtlight->radius, numsurfaces, surfacelist);
+ ent->model->DrawShadowVolume(ent, relativelightorigin, rtlight->radius, numsurfaces, surfacelist, rtlight->cullmins, rtlight->cullmaxs);
}
if (r_drawentities.integer)
{
// light emitting entities should not cast their own shadow
if (VectorLength2(relativelightorigin) < 0.1)
continue;
- ent->model->DrawShadowVolume(ent, relativelightorigin, rtlight->radius, ent->model->nummodelsurfaces, ent->model->surfacelist);
+ relativelightmins[0] = relativelightorigin[0] - rtlight->radius;
+ relativelightmins[1] = relativelightorigin[1] - rtlight->radius;
+ relativelightmins[2] = relativelightorigin[2] - rtlight->radius;
+ relativelightmaxs[0] = relativelightorigin[0] + rtlight->radius;
+ relativelightmaxs[1] = relativelightorigin[1] + rtlight->radius;
+ relativelightmaxs[2] = relativelightorigin[2] + rtlight->radius;
+ ent->model->DrawShadowVolume(ent, relativelightorigin, rtlight->radius, ent->model->nummodelsurfaces, ent->model->surfacelist, relativelightmins, relativelightmaxs);
}
}
}
void R_Shadow_Init(void);
void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f, const int *elements, const int *neighbors, const vec3_t projectorigin, float projectdistance, int nummarktris, const int *marktris);
-void R_Shadow_MarkVolumeFromBox(int firsttriangle, int numtris, const float *invertex3f, const int *elements, const vec3_t projectorigin, vec3_t lightmins, vec3_t lightmaxs, vec3_t surfacemins, vec3_t surfacemaxs);
+void R_Shadow_MarkVolumeFromBox(int firsttriangle, int numtris, const float *invertex3f, const int *elements, const vec3_t projectorigin, const vec3_t lightmins, const vec3_t lightmaxs, const vec3_t surfacemins, const vec3_t surfacemaxs);
void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *texcoord2f, const float *relativelightorigin, const float *relativeeyeorigin, const float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *basetexture, rtexture_t *bumptexture, rtexture_t *glosstexture, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale);
void R_Shadow_ClearStencil(void);