]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_models.c
bmodel shadow volumes
[xonotic/darkplaces.git] / gl_models.c
index 87357618c28d89add98da700a27ab682abe19b28..4d5a876f82b293c75dcab11e9ddae36ecdf07e4b 100644 (file)
@@ -1,6 +1,7 @@
 
 #include "quakedef.h"
 #include "cl_collision.h"
+#include "r_shadow.h"
 
 cvar_t r_quickmodels = {0, "r_quickmodels", "1"};
 
@@ -291,7 +292,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
        colorscale = r_colorscale;
        if (gl_combine.integer)
                colorscale *= 0.25f;
-       
+
        if (!skinframe->base && !skinframe->pants && !skinframe->shirt && !skinframe->glow)
        {
                // untextured
@@ -312,6 +313,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false);
                aliasvert = aliasvertbuf;
                aliasvertcolor = aliasvertcolorbuf;
+               GL_UseColorArray();
                R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
                return;
        }
@@ -337,6 +339,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                R_LightModel(ent, model->numverts, colorscale, colorscale, colorscale, false);
                aliasvert = aliasvertbuf;
                aliasvertcolor = aliasvertcolorbuf;
+               GL_UseColorArray();
                R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
                return;
        }
@@ -379,6 +382,7 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                R_ModulateColors(aliasvertcolor, varray_color, model->numverts, colorscale, colorscale, colorscale);
                memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
                memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
+               GL_UseColorArray();
                R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
        }
 
@@ -401,9 +405,12 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                                blendfunc2 = GL_ONE;
                                c_alias_polys += model->numtris;
                                if (pantsfullbright)
-                                       R_FillColors(varray_color, model->numverts, pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale, ent->alpha);
+                                       GL_Color(pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale, ent->alpha);
                                else
+                               {
+                                       GL_UseColorArray();
                                        R_ModulateColors(aliasvertcolor, varray_color, model->numverts, pantscolor[0] * colorscale, pantscolor[1] * colorscale, pantscolor[2] * colorscale);
+                               }
                                memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
                                memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
                                R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
@@ -426,9 +433,12 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                                blendfunc2 = GL_ONE;
                                c_alias_polys += model->numtris;
                                if (shirtfullbright)
-                                       R_FillColors(varray_color, model->numverts, shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale, ent->alpha);
+                                       GL_Color(shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale, ent->alpha);
                                else
+                               {
+                                       GL_UseColorArray();
                                        R_ModulateColors(aliasvertcolor, varray_color, model->numverts, shirtcolor[0] * colorscale, shirtcolor[1] * colorscale, shirtcolor[2] * colorscale);
+                               }
                                memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
                                memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
                                R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
@@ -449,9 +459,9 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                        blendfunc1 = GL_SRC_ALPHA;
                        blendfunc2 = GL_ONE;
                        c_alias_polys += model->numtris;
-                       R_FillColors(varray_color, model->numverts, (1 - fog) * r_colorscale, (1 - fog) * r_colorscale, (1 - fog) * r_colorscale, ent->alpha);
                        memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
                        memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
+                       GL_Color((1 - fog) * r_colorscale, (1 - fog) * r_colorscale, (1 - fog) * r_colorscale, ent->alpha);
                        R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
                }
        }
@@ -464,19 +474,76 @@ void R_DrawQ1Q2AliasModelCallback (const void *calldata1, int calldata2)
                R_Mesh_State(&m);
 
                c_alias_polys += model->numtris;
-               R_FillColors(varray_color, model->numverts, fogcolor[0] * fog * r_colorscale, fogcolor[1] * fog * r_colorscale, fogcolor[2] * fog * r_colorscale, ent->alpha);
                memcpy(varray_vertex, aliasvert, model->numverts * sizeof(float[4]));
                memcpy(varray_texcoord[0], model->mdlmd2data_texcoords, model->numverts * sizeof(float[2]));
+               GL_Color(fogcolor[0] * fog * r_colorscale, fogcolor[1] * fog * r_colorscale, fogcolor[2] * fog * r_colorscale, ent->alpha);
                R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
        }
 }
 
+extern cvar_t r_shadows;
 void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent)
 {
        int i;
        rmeshstate_t m;
        model_t *model;
        float *v, planenormal[3], planedist, dist, projection[3], floororigin[3], surfnormal[3], lightdirection[3], v2[3];
+       mlight_t *sl;
+       rdlight_t *rd;
+
+       if (r_shadows.integer > 1)
+       {
+               float f, lightscale, lightcolor[3];
+               vec3_t temp;
+               memset(&m, 0, sizeof(m));
+               m.blendfunc1 = GL_ONE;
+               m.blendfunc2 = GL_ONE;
+               R_Mesh_State(&m);
+               R_Mesh_Matrix(&ent->matrix);
+               for (i = 0, sl = cl.worldmodel->lights;i < cl.worldmodel->numlights;i++, sl++)
+               {
+                       if (d_lightstylevalue[sl->style] > 0)
+                       {
+                               VectorSubtract(ent->origin, sl->origin, temp);
+                               f = DotProduct(temp,temp);
+                               if (f < (ent->model->radius2 + sl->cullradius2))
+                               {
+                                       model = ent->model;
+                                       R_Mesh_ResizeCheck(model->numverts * 2);
+                                       R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
+                                       Matrix4x4_Transform(&ent->inversematrix, sl->origin, temp);
+                                       GL_Color(0.1 * r_colorscale, 0.025 * r_colorscale, 0.0125 * r_colorscale, 1);
+                                       R_Shadow_Volume(model->numverts, model->numtris, model->mdlmd2data_indices, model->mdlmd2data_triangleneighbors, temp, sl->cullradius + model->radius - sqrt(f), true);
+                                       GL_UseColorArray();
+                                       lightscale = d_lightstylevalue[sl->style] * (1.0f / 65536.0f);
+                                       VectorScale(sl->light, lightscale, lightcolor);
+                                       R_Shadow_VertexLight(model->numverts, aliasvertnorm, temp, sl->cullradius2, sl->distbias, sl->subtract, lightcolor);
+                                       R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
+                               }
+                       }
+               }
+               for (i = 0, rd = r_dlight;i < r_numdlights;i++, rd++)
+               {
+                       if (ent != rd->ent)
+                       {
+                               VectorSubtract(ent->origin, rd->origin, temp);
+                               f = DotProduct(temp,temp);
+                               if (f < (ent->model->radius2 + rd->cullradius2))
+                               {
+                                       model = ent->model;
+                                       R_Mesh_ResizeCheck(model->numverts * 2);
+                                       R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
+                                       Matrix4x4_Transform(&ent->inversematrix, rd->origin, temp);
+                                       GL_Color(0.1 * r_colorscale, 0.025 * r_colorscale, 0.0125 * r_colorscale, 1);
+                                       R_Shadow_Volume(model->numverts, model->numtris, model->mdlmd2data_indices, model->mdlmd2data_triangleneighbors, temp, rd->cullradius + model->radius - sqrt(f), true);
+                                       GL_UseColorArray();
+                                       R_Shadow_VertexLight(model->numverts, aliasvertnorm, temp, rd->cullradius2, LIGHTOFFSET, rd->subtract, rd->light);
+                                       R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
+                               }
+                       }
+               }
+               return;
+       }
 
        lightdirection[0] = 0.5;
        lightdirection[1] = 0.2;
@@ -499,7 +566,6 @@ void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent)
 
        c_alias_polys += model->numtris;
        R_LerpMDLMD2Vertices(ent, varray_vertex, aliasvertnorm);
-       R_FillColors(varray_color, model->numverts, 0, 0, 0, 0.5);
 
        // put a light direction in the entity's coordinate space
        Matrix4x4_Transform3x3(&ent->inversematrix, lightdirection, projection);
@@ -522,6 +588,7 @@ void R_DrawQ1Q2AliasModelFakeShadow (entity_render_t *ent)
                //if (i & 1)
                        VectorMA(v, dist, projection, v);
        }
+       GL_Color(0, 0, 0, 0.5);
        R_Mesh_Draw(model->numverts, model->numtris, model->mdlmd2data_indices);
 }
 
@@ -878,6 +945,7 @@ void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
        memcpy(varray_vertex, aliasvert, numverts * sizeof(float[4]));
        R_ModulateColors(aliasvertcolor, varray_color, numverts, colorscale, colorscale, colorscale);
        memcpy(varray_texcoord[0], (float *)(m->lump_texcoords.start + (int) m), numverts * sizeof(float[2]));
+       GL_UseColorArray();
        R_Mesh_Draw(numverts, numtriangles, elements);
 
        if (fog)
@@ -891,8 +959,8 @@ void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
 
                c_alias_polys += numtriangles;
                memcpy(varray_vertex, aliasvert, numverts * sizeof(float[4]));
-               R_FillColors(varray_color, numverts, fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, ent->alpha * fog);
                //memcpy(mesh_texcoord[0], (float *)(m->lump_texcoords.start + (int) m), numverts * sizeof(float[2]));
+               GL_Color(fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, ent->alpha * fog);
                R_Mesh_Draw(numverts, numtriangles, elements);
        }
 }