]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_models.c
fixed animated textures in realtime lighting mode (now calls R_UpdateTextureInfo)
[xonotic/darkplaces.git] / gl_models.c
index c71dcf34c3576a899db43424b062edb2e07c8404..223be1b81b87af20c877d54b988831638ee23e9e 100644 (file)
@@ -161,7 +161,7 @@ aliasskin_t *R_FetchAliasSkin(const entity_render_t *ent, const aliasmesh_t *mes
 void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
 {
        int c, fullbright, layernum, firstpass;
-       float tint[3], fog, ifog, colorscale, ambientcolor4f[4];
+       float tint[3], fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3];
        vec3_t diff;
        qbyte *bcolor;
        rmeshstate_t m;
@@ -175,7 +175,7 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
        fog = 0;
        if (fogenabled)
        {
-               VectorSubtract(ent->origin, r_origin, diff);
+               VectorSubtract(ent->origin, r_vieworigin, diff);
                fog = DotProduct(diff,diff);
                if (fog < 0.01f)
                        fog = 0.01f;
@@ -200,7 +200,7 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                         || ((layer->flags & ALIASLAYER_NODRAW_IF_COLORMAPPED) && ent->colormap >= 0)
                         || ((layer->flags & ALIASLAYER_FOG) && !fogenabled)
                         ||  (layer->flags & ALIASLAYER_SPECULAR)
-                        || ((layer->flags & ALIASLAYER_DIFFUSE) && (r_shadow_realtime_world.integer && r_ambient.integer <= 0 && r_fullbright.integer == 0 && !(ent->effects & EF_FULLBRIGHT))))
+                        || ((layer->flags & ALIASLAYER_DIFFUSE) && (r_shadow_realtime_world.integer && r_shadow_realtime_world_lightmaps.value <= 0 && r_ambient.integer <= 0 && r_fullbright.integer == 0 && !(ent->effects & EF_FULLBRIGHT))))
                                continue;
                }
                if (!firstpass || (ent->effects & EF_ADDITIVE))
@@ -221,7 +221,7 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                GL_DepthTest(true);
                firstpass = false;
                expandaliasvert(mesh->num_vertices);
-               colorscale = r_colorscale;
+               colorscale = 1.0f;
 
                memset(&m, 0, sizeof(m));
                if (layer->texture != NULL)
@@ -234,10 +234,9 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                                m.texrgbscale[0] = 4;
                        }
                }
-               R_Mesh_State_Texture(&m);
+               m.pointer_vertex = varray_vertex3f;
 
                c_alias_polys += mesh->num_triangles;
-               GL_VertexPointer(varray_vertex3f);
                R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, varray_vertex3f);
                if (layer->flags & ALIASLAYER_FOG)
                {
@@ -247,11 +246,6 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                else
                {
                        fullbright = !(layer->flags & ALIASLAYER_DIFFUSE) || r_fullbright.integer || (ent->effects & EF_FULLBRIGHT);
-                       if (r_shadow_realtime_world.integer && !fullbright)
-                       {
-                               colorscale *= r_ambient.value * (2.0f / 128.0f);
-                               fullbright = true;
-                       }
                        if (layer->flags & (ALIASLAYER_COLORMAP_PANTS | ALIASLAYER_COLORMAP_SHIRT))
                        {
                                // 128-224 are backwards ranges
@@ -266,22 +260,27 @@ void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                        }
                        else
                                tint[0] = tint[1] = tint[2] = 1;
+                       if (r_shadow_realtime_world.integer && !fullbright)
+                               VectorScale(tint, r_shadow_realtime_world_lightmaps.value, tint);
                        colorscale *= ifog;
                        if (fullbright)
                                GL_Color(tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha);
                        else
                        {
-                               if (R_LightModel(ambientcolor4f, ent, tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha, false))
+                               if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, tint[0] * colorscale, tint[1] * colorscale, tint[2] * colorscale, ent->alpha, false))
                                {
-                                       GL_ColorPointer(varray_color4f);
+                                       m.pointer_color = varray_color4f;
                                        R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_NORMAL, varray_normal3f);
-                                       R_LightModel_CalcVertexColors(ambientcolor4f, mesh->num_vertices, varray_vertex3f, varray_normal3f, varray_color4f);
+                                       R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, varray_vertex3f, varray_normal3f, varray_color4f);
                                }
                                else
                                        GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
                        }
                }
+               R_Mesh_State(&m);
+               GL_LockArrays(0, mesh->num_vertices);
                R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
+               GL_LockArrays(0, 0);
        }
 }
 
@@ -303,68 +302,6 @@ void R_Model_Alias_Draw(entity_render_t *ent)
        }
 }
 
-void R_Model_Alias_DrawFakeShadow (entity_render_t *ent)
-{
-       int i, meshnum;
-       aliasmesh_t *mesh;
-       aliasskin_t *skin;
-       rmeshstate_t m;
-       float *v, plane[4], dist, projection[3], floororigin[3], surfnormal[3], lightdirection[3], v2[3];
-
-       if ((ent->effects & EF_ADDITIVE) || ent->alpha < 1)
-               return;
-
-       lightdirection[0] = 0.5;
-       lightdirection[1] = 0.2;
-       lightdirection[2] = -1;
-       VectorNormalizeFast(lightdirection);
-
-       VectorMA(ent->origin, 65536.0f, lightdirection, v2);
-       if (CL_TraceLine(ent->origin, v2, floororigin, surfnormal, 0, false, NULL) == 1)
-               return;
-
-       R_Mesh_Matrix(&ent->matrix);
-
-       memset(&m, 0, sizeof(m));
-       R_Mesh_State_Texture(&m);
-
-       GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-       GL_DepthMask(false);
-       GL_DepthTest(true);
-       GL_VertexPointer(varray_vertex3f);
-       GL_Color(0, 0, 0, 0.5);
-
-       // put a light direction in the entity's coordinate space
-       Matrix4x4_Transform3x3(&ent->inversematrix, lightdirection, projection);
-       VectorNormalizeFast(projection);
-
-       // put the plane's normal in the entity's coordinate space
-       Matrix4x4_Transform3x3(&ent->inversematrix, surfnormal, plane);
-       VectorNormalizeFast(plane);
-
-       // put the plane's distance in the entity's coordinate space
-       VectorSubtract(floororigin, ent->origin, floororigin);
-       plane[3] = DotProduct(floororigin, surfnormal) + 2;
-
-       dist = -1.0f / DotProduct(projection, plane);
-       VectorScale(projection, dist, projection);
-       for (meshnum = 0, mesh = ent->model->alias.aliasdata_meshes;meshnum < ent->model->alias.aliasnum_meshes;meshnum++)
-       {
-               skin = R_FetchAliasSkin(ent, mesh);
-               if (skin->flags & ALIASSKIN_TRANSPARENT)
-                       continue;
-               R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, varray_vertex3f);
-               for (i = 0, v = varray_vertex3f;i < mesh->num_vertices;i++, v += 3)
-               {
-                       dist = DotProduct(v, plane) - plane[3];
-                       if (dist > 0)
-                               VectorMA(v, dist, projection, v);
-               }
-               c_alias_polys += mesh->num_triangles;
-               R_Mesh_Draw(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i);
-       }
-}
-
 void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
 {
        int meshnum;
@@ -373,7 +310,7 @@ void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightor
        float projectdistance;
        if (ent->effects & EF_ADDITIVE || ent->alpha < 1)
                return;
-       projectdistance = lightradius + ent->model->radius - sqrt(DotProduct(relativelightorigin, relativelightorigin));
+       projectdistance = lightradius + ent->model->radius;// - sqrt(DotProduct(relativelightorigin, relativelightorigin));
        if (projectdistance > 0.1)
        {
                R_Mesh_Matrix(&ent->matrix);
@@ -383,12 +320,12 @@ void R_Model_Alias_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightor
                        if (skin->flags & ALIASSKIN_TRANSPARENT)
                                continue;
                        R_Model_Alias_GetMesh_Array3f(ent, mesh, MODELARRAY_VERTEX, varray_vertex3f);
-                       R_Shadow_Volume(mesh->num_vertices, mesh->num_triangles, varray_vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, lightradius, projectdistance);
+                       R_Shadow_VolumeFromSphere(mesh->num_vertices, mesh->num_triangles, varray_vertex3f, mesh->data_element3i, mesh->data_neighbor3i, relativelightorigin, projectdistance, lightradius);
                }
        }
 }
 
-void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltofilter, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz)
+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)
 {
        int c, meshnum, layernum;
        float fog, ifog, lightcolor2[3];
@@ -406,7 +343,7 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
        fog = 0;
        if (fogenabled)
        {
-               VectorSubtract(ent->origin, r_origin, diff);
+               VectorSubtract(ent->origin, r_vieworigin, diff);
                fog = DotProduct(diff,diff);
                if (fog < 0.01f)
                        fog = 0.01f;
@@ -443,7 +380,7 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
                        if (layer->flags & ALIASLAYER_SPECULAR)
                        {
                                c_alias_polys += mesh->num_triangles;
-                               R_Shadow_SpecularLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, aliasvert_vertex3f, aliasvert_svector3f, aliasvert_tvector3f, aliasvert_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightradius, lightcolor2, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, NULL);
+                               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, aliasvert_vertex3f, aliasvert_svector3f, aliasvert_tvector3f, aliasvert_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_SPECULAR);
                        }
                        else if (layer->flags & ALIASLAYER_DIFFUSE)
                        {
@@ -472,7 +409,7 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
                                        lightcolor2[2] *= bcolor[2] * (1.0f / 255.0f);
                                }
                                c_alias_polys += mesh->num_triangles;
-                               R_Shadow_DiffuseLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, aliasvert_vertex3f, aliasvert_svector3f, aliasvert_tvector3f, aliasvert_normal3f, mesh->data_texcoord2f, relativelightorigin, lightradius, lightcolor2, matrix_modeltofilter, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, NULL);
+                               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, aliasvert_vertex3f, aliasvert_svector3f, aliasvert_tvector3f, aliasvert_normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, layer->texture, layer->nmap, layer->texture, lightcubemap, LIGHTING_DIFFUSE);
                        }
                }
        }
@@ -740,7 +677,7 @@ void ZymoticCalcNormal3f(int vertcount, float *vertex3f, float *normal3f, int sh
 
 void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
 {
-       float fog, ifog, colorscale, ambientcolor4f[4];
+       float fog, ifog, colorscale, ambientcolor4f[4], diffusecolor[3], diffusenormal[3];
        vec3_t diff;
        int i, *renderlist, *elements;
        rtexture_t *texture;
@@ -766,7 +703,7 @@ void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
        fog = 0;
        if (fogenabled)
        {
-               VectorSubtract(ent->origin, r_origin, diff);
+               VectorSubtract(ent->origin, r_vieworigin, diff);
                fog = DotProduct(diff,diff);
                if (fog < 0.01f)
                        fog = 0.01f;
@@ -797,10 +734,9 @@ void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
                GL_DepthMask(true);
        }
        GL_DepthTest(true);
-       GL_VertexPointer(varray_vertex3f);
 
        memset(&mstate, 0, sizeof(mstate));
-       colorscale = r_colorscale;
+       colorscale = 1.0f;
        if (gl_combine.integer)
        {
                mstate.texrgbscale[0] = 4;
@@ -808,20 +744,23 @@ void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
        }
        mstate.tex[0] = R_GetTexture(texture);
        mstate.pointer_texcoord[0] = ent->model->alias.zymdata_texcoords;
-       R_Mesh_State_Texture(&mstate);
+       mstate.pointer_vertex = varray_vertex3f;
 
        ZymoticLerpBones(ent->model->alias.zymnum_bones, (zymbonematrix *) ent->model->alias.zymdata_poses, ent->frameblend, ent->model->alias.zymdata_bones);
 
        ZymoticTransformVerts(numverts, varray_vertex3f, ent->model->alias.zymdata_vertbonecounts, ent->model->alias.zymdata_verts);
        ZymoticCalcNormal3f(numverts, varray_vertex3f, aliasvert_normal3f, ent->model->alias.zymnum_shaders, ent->model->alias.zymdata_renderlist);
-       if (R_LightModel(ambientcolor4f, ent, ifog * colorscale, ifog * colorscale, ifog * colorscale, ent->alpha, false))
+       if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, ifog * colorscale, ifog * colorscale, ifog * colorscale, ent->alpha, false))
        {
-               GL_ColorPointer(varray_color4f);
-               R_LightModel_CalcVertexColors(ambientcolor4f, numverts, varray_vertex3f, aliasvert_normal3f, varray_color4f);
+               mstate.pointer_color = varray_color4f;
+               R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, numverts, varray_vertex3f, aliasvert_normal3f, varray_color4f);
        }
        else
                GL_Color(ambientcolor4f[0], ambientcolor4f[1], ambientcolor4f[2], ambientcolor4f[3]);
+       R_Mesh_State(&mstate);
+       GL_LockArrays(0, numverts);
        R_Mesh_Draw(numverts, numtriangles, elements);
+       GL_LockArrays(0, 0);
        c_alias_polys += numtriangles;
 
        if (fog)
@@ -829,17 +768,20 @@ void R_DrawZymoticModelMeshCallback (const void *calldata1, int calldata2)
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                GL_DepthMask(false);
                GL_DepthTest(true);
-               GL_VertexPointer(varray_vertex3f);
 
                memset(&mstate, 0, sizeof(mstate));
                // FIXME: need alpha mask for fogging...
                //mstate.tex[0] = R_GetTexture(texture);
                //mstate.pointer_texcoord = ent->model->alias.zymdata_texcoords;
-               R_Mesh_State_Texture(&mstate);
+               mstate.pointer_vertex = varray_vertex3f;
+               R_Mesh_State(&mstate);
 
-               GL_Color(fogcolor[0] * r_colorscale, fogcolor[1] * r_colorscale, fogcolor[2] * r_colorscale, ent->alpha * fog);
+               GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], ent->alpha * fog);
                ZymoticTransformVerts(numverts, varray_vertex3f, ent->model->alias.zymdata_vertbonecounts, ent->model->alias.zymdata_verts);
+               R_Mesh_State(&mstate);
+               GL_LockArrays(0, numverts);
                R_Mesh_Draw(numverts, numtriangles, elements);
+               GL_LockArrays(0, 0);
                c_alias_polys += numtriangles;
        }
 }
@@ -862,17 +804,12 @@ void R_Model_Zymotic_Draw(entity_render_t *ent)
        }
 }
 
-void R_Model_Zymotic_DrawFakeShadow(entity_render_t *ent)
-{
-       // FIXME
-}
-
-void R_Model_Zymotic_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, float lightradius2, float lightdistbias, float lightsubtract, float *lightcolor)
+void R_Model_Zymotic_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius)
 {
        // FIXME
 }
 
-void R_Model_Zymotic_DrawOntoLight(entity_render_t *ent)
+void R_Model_Zymotic_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)
 {
        // FIXME
 }