]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rsurf.c
split model->DrawShadowVolume into CompileShadowVolume and DrawShadowVolume to simpli...
[xonotic/darkplaces.git] / gl_rsurf.c
index c2c822618c944ae525e2d71bc6471347ec02cec1..b41e061efa6c0f0cf6d9ac40f47b34774435e946 100644 (file)
@@ -663,6 +663,29 @@ extern float *rsurface_tvector3f;
 extern float *rsurface_normal3f;
 extern void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t modelorg);
 
+void R_Q1BSP_CompileShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
+{
+       model_t *model = ent->model;
+       msurface_t *surface;
+       int surfacelistindex;
+       float projectdistance = lightradius + model->radius*2 + r_shadow_projectdistance.value;
+       texture_t *texture;
+       r_shadow_compilingrtlight->static_meshchain_shadow = Mod_ShadowMesh_Begin(r_shadow_mempool, 32768, 32768, NULL, NULL, NULL, false, false, true);
+       R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
+       for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
+       {
+               surface = model->data_surfaces + surfacelist[surfacelistindex];
+               texture = surface->texture;
+               if ((texture->basematerialflags & (MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT | MATERIALFLAG_WALL)) != MATERIALFLAG_WALL)
+                       continue;
+               if (texture->textureflags & (Q3TEXTUREFLAG_TWOSIDED | Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
+                       continue;
+               R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, r_shadow_compilingrtlight->cullmins, r_shadow_compilingrtlight->cullmaxs, surface->mins, surface->maxs);
+       }
+       R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + projectdistance, numshadowmark, shadowmarklist);
+       r_shadow_compilingrtlight->static_meshchain_shadow = Mod_ShadowMesh_Finish(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_shadow, false, false);
+}
+
 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;
@@ -676,36 +699,19 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
                return;
        if (r_drawcollisionbrushes.integer >= 2)
                return;
-       if (!r_shadow_compilingrtlight)
-               R_UpdateAllTextureInfo(ent);
+       R_UpdateAllTextureInfo(ent);
        if (model->brush.shadowmesh)
        {
                R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
-               if (r_shadow_compilingrtlight)
-               {
-                       for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
-                       {
-                               surface = model->data_surfaces + surfacelist[surfacelistindex];
-                               texture = surface->texture;
-                               if ((texture->basematerialflags & (MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT | MATERIALFLAG_WALL)) != MATERIALFLAG_WALL)
-                                       continue;
-                               if (texture->textureflags & (Q3TEXTUREFLAG_TWOSIDED | Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
-                                       continue;
-                               R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
-                       }
-               }
-               else
+               for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
                {
-                       for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
-                       {
-                               surface = model->data_surfaces + surfacelist[surfacelistindex];
-                               texture = surface->texture->currentframe;
-                               if ((texture->currentmaterialflags & (MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT | MATERIALFLAG_WALL)) != MATERIALFLAG_WALL)
-                                       continue;
-                               if (texture->textureflags & (Q3TEXTUREFLAG_TWOSIDED | Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
-                                       continue;
-                               R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
-                       }
+                       surface = model->data_surfaces + surfacelist[surfacelistindex];
+                       texture = surface->texture->currentframe;
+                       if ((texture->currentmaterialflags & (MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT | MATERIALFLAG_WALL)) != MATERIALFLAG_WALL)
+                               continue;
+                       if (texture->textureflags & (Q3TEXTUREFLAG_TWOSIDED | Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
+                               continue;
+                       R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
                }
                R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + projectdistance, numshadowmark, shadowmarklist);
        }
@@ -736,123 +742,94 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, float *lightcolorbase, int numsurfa
        texture_t *texture;
        int surfacelistindex;
        vec3_t modelorg;
+       texture_t *tex;
+       vec3_t lightcolorpants, lightcolorshirt;
+       rtexture_t *basetexture = NULL;
+       rtexture_t *glosstexture = NULL;
+       float specularscale = 0;
+       qboolean skip;
        if (r_drawcollisionbrushes.integer >= 2)
                return;
-       if (r_shadow_compilingrtlight)
+       R_UpdateAllTextureInfo(ent);
+       Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
+       tex = NULL;
+       texture = NULL;
+       skip = false;
+       for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
-               // if compiling an rtlight, capture the meshes
-               int tri;
-               int *e;
-               float *lightmins, *lightmaxs, *v[3], *vertex3f;
-               for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
+               if ((ent == r_refdef.worldentity && !r_worldsurfacevisible[surfacelist[surfacelistindex]]))
+                       continue;
+               surface = model->data_surfaces + surfacelist[surfacelistindex];
+               if (tex != surface->texture)
                {
-                       surface = model->data_surfaces + surfacelist[surfacelistindex];
-                       texture = surface->texture;
-                       if ((texture->basematerialflags & (MATERIALFLAG_WALL | MATERIALFLAG_TRANSPARENT)) != MATERIALFLAG_WALL || !surface->num_triangles)
+                       tex = surface->texture;
+                       texture = surface->texture->currentframe;
+                       // FIXME: transparent surfaces need to be lit later
+                       skip = (texture->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_TRANSPARENT)) != MATERIALFLAG_WALL;
+                       if (skip)
                                continue;
-                       e = surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle;
-                       vertex3f = surface->groupmesh->data_vertex3f;
-                       lightmins = r_shadow_compilingrtlight->cullmins;
-                       lightmaxs = r_shadow_compilingrtlight->cullmaxs;
-                       for (tri = 0;tri < surface->num_triangles;tri++, e += 3)
+                       if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
+                               qglDisable(GL_CULL_FACE);
+                       else
+                               qglEnable(GL_CULL_FACE);
+                       glosstexture = r_texture_black;
+                       specularscale = 0;
+                       if (texture->skin.gloss)
                        {
-                               v[0] = vertex3f + e[0] * 3;
-                               v[1] = vertex3f + e[1] * 3;
-                               v[2] = vertex3f + e[2] * 3;
-                               if (PointInfrontOfTriangle(r_shadow_compilingrtlight->shadoworigin, v[0], v[1], v[2]) && lightmaxs[0] > min(v[0][0], min(v[1][0], v[2][0])) && lightmins[0] < max(v[0][0], max(v[1][0], v[2][0])) && lightmaxs[1] > min(v[0][1], min(v[1][1], v[2][1])) && lightmins[1] < max(v[0][1], max(v[1][1], v[2][1])) && lightmaxs[2] > min(v[0][2], min(v[1][2], v[2][2])) && lightmins[2] < max(v[0][2], max(v[1][2], v[2][2])))
-                                       Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texture->skin.base, surface->texture->skin.gloss, surface->texture->skin.nmap, surface->groupmesh->data_vertex3f, surface->groupmesh->data_svector3f, surface->groupmesh->data_tvector3f, surface->groupmesh->data_normal3f, surface->groupmesh->data_texcoordtexture2f, 1, e);
+                               if (r_shadow_gloss.integer >= 1 && r_shadow_glossintensity.value > 0 && r_shadow_rtlight->specularscale > 0)
+                               {
+                                       glosstexture = texture->skin.gloss;
+                                       specularscale = r_shadow_rtlight->specularscale * r_shadow_glossintensity.value;
+                               }
                        }
-               }
-       }
-       else
-       {
-               texture_t *tex;
-               vec3_t lightcolorpants, lightcolorshirt;
-               rtexture_t *basetexture = NULL;
-               rtexture_t *glosstexture = NULL;
-               float specularscale = 0;
-               qboolean skip;
-               R_UpdateAllTextureInfo(ent);
-               Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
-               tex = NULL;
-               texture = NULL;
-               skip = false;
-               for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
-               {
-                       if ((ent == r_refdef.worldentity && !r_worldsurfacevisible[surfacelist[surfacelistindex]]))
-                               continue;
-                       surface = model->data_surfaces + surfacelist[surfacelistindex];
-                       if (tex != surface->texture)
+                       else
                        {
-                               tex = surface->texture;
-                               texture = surface->texture->currentframe;
-                               // FIXME: transparent surfaces need to be lit later
-                               skip = (texture->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_TRANSPARENT)) != MATERIALFLAG_WALL;
-                               if (skip)
-                                       continue;
-                               if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
-                                       qglDisable(GL_CULL_FACE);
-                               else
-                                       qglEnable(GL_CULL_FACE);
-                               glosstexture = r_texture_black;
-                               specularscale = 0;
-                               if (texture->skin.gloss)
+                               if (r_shadow_gloss.integer >= 2 && r_shadow_gloss2intensity.value > 0 && r_shadow_glossintensity.value > 0 && r_shadow_rtlight->specularscale > 0)
                                {
-                                       if (r_shadow_gloss.integer >= 1 && r_shadow_glossintensity.value > 0 && r_shadow_rtlight->specularscale > 0)
-                                       {
-                                               glosstexture = texture->skin.gloss;
-                                               specularscale = r_shadow_rtlight->specularscale * r_shadow_glossintensity.value;
-                                       }
+                                       glosstexture = r_texture_white;
+                                       specularscale = r_shadow_rtlight->specularscale * r_shadow_gloss2intensity.value;
                                }
-                               else
+                       }
+                       VectorClear(lightcolorpants);
+                       VectorClear(lightcolorshirt);
+                       if (ent->colormap >= 0)
+                       {
+                               // 128-224 are backwards ranges
+                               int b = (ent->colormap & 0xF) << 4;b += (b >= 128 && b < 224) ? 4 : 12;
+                               if (texture->skin.pants && b < 224)
                                {
-                                       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;
-                                       }
+                                       qbyte *bcolor = (qbyte *) (&palette_complete[b]);
+                                       lightcolorpants[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
+                                       lightcolorpants[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
+                                       lightcolorpants[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
                                }
-                               VectorClear(lightcolorpants);
-                               VectorClear(lightcolorshirt);
-                               if (ent->colormap >= 0)
+                               // 128-224 are backwards ranges
+                               b = (ent->colormap & 0xF0);b += (b >= 128 && b < 224) ? 4 : 12;
+                               if (texture->skin.shirt && b < 224)
                                {
-                                       // 128-224 are backwards ranges
-                                       int b = (ent->colormap & 0xF) << 4;b += (b >= 128 && b < 224) ? 4 : 12;
-                                       if (texture->skin.pants && b < 224)
-                                       {
-                                               qbyte *bcolor = (qbyte *) (&palette_complete[b]);
-                                               lightcolorpants[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
-                                               lightcolorpants[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
-                                               lightcolorpants[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
-                                       }
-                                       // 128-224 are backwards ranges
-                                       b = (ent->colormap & 0xF0);b += (b >= 128 && b < 224) ? 4 : 12;
-                                       if (texture->skin.shirt && b < 224)
-                                       {
-                                               qbyte *bcolor = (qbyte *) (&palette_complete[b]);
-                                               lightcolorshirt[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
-                                               lightcolorshirt[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
-                                               lightcolorshirt[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
-                                       }
-                                       basetexture = texture->skin.base;
+                                       qbyte *bcolor = (qbyte *) (&palette_complete[b]);
+                                       lightcolorshirt[0] = lightcolorbase[0] * bcolor[0] * (1.0f / 255.0f);
+                                       lightcolorshirt[1] = lightcolorbase[1] * bcolor[1] * (1.0f / 255.0f);
+                                       lightcolorshirt[2] = lightcolorbase[2] * bcolor[2] * (1.0f / 255.0f);
                                }
-                               else
-                                       basetexture = texture->skin.merged ? texture->skin.merged : texture->skin.base;
-                               if ((r_shadow_rtlight->ambientscale + r_shadow_rtlight->diffusescale) * (VectorLength2(lightcolorbase) + VectorLength2(lightcolorpants) + VectorLength2(lightcolorshirt)) + specularscale * VectorLength2(lightcolorbase) < (1.0f / 1048576.0f))
-                                       skip = true;
+                               basetexture = texture->skin.base;
                        }
-                       if (skip || !surface->num_triangles)
-                               continue;
-                       RSurf_SetVertexPointer(ent, texture, surface, modelorg);
-                       if (!rsurface_svector3f)
-                       {
-                               rsurface_svector3f = varray_svector3f;
-                               rsurface_tvector3f = varray_tvector3f;
-                               rsurface_normal3f = varray_normal3f;
-                               Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
-                       }
-                       R_Shadow_RenderLighting(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), rsurface_vertex3f, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, surface->groupmesh->data_texcoordtexture2f, lightcolorbase, lightcolorpants, lightcolorshirt, basetexture, texture->skin.pants, texture->skin.shirt, texture->skin.nmap, texture->skin.gloss);
+                       else
+                               basetexture = texture->skin.merged ? texture->skin.merged : texture->skin.base;
+                       if ((r_shadow_rtlight->ambientscale + r_shadow_rtlight->diffusescale) * (VectorLength2(lightcolorbase) + VectorLength2(lightcolorpants) + VectorLength2(lightcolorshirt)) + specularscale * VectorLength2(lightcolorbase) < (1.0f / 1048576.0f))
+                               skip = true;
+               }
+               if (skip || !surface->num_triangles)
+                       continue;
+               RSurf_SetVertexPointer(ent, texture, surface, modelorg);
+               if (!rsurface_svector3f)
+               {
+                       rsurface_svector3f = varray_svector3f;
+                       rsurface_tvector3f = varray_tvector3f;
+                       rsurface_normal3f = varray_normal3f;
+                       Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
                }
+               R_Shadow_RenderLighting(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), rsurface_vertex3f, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, surface->groupmesh->data_texcoordtexture2f, lightcolorbase, lightcolorpants, lightcolorshirt, basetexture, texture->skin.pants, texture->skin.shirt, texture->skin.nmap, texture->skin.gloss, specularscale);
        }
        qglEnable(GL_CULL_FACE);
 }