]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
Tomaz's new water effect has been added and looks very nice
[xonotic/darkplaces.git] / model_shared.c
index 5c578e36c92f1e8f33fc6d6e3484ad30db883a78..ebcdc6a8cbff609c5e78b210eea68226ee9b8b8e 100644 (file)
@@ -37,7 +37,7 @@ static model_t mod_known[MAX_MOD_KNOWN];
 rtexturepool_t *mod_shared_texturepool;
 rtexture_t *r_notexture;
 rtexture_t *mod_shared_detailtextures[NUM_DETAILTEXTURES];
-rtexture_t *mod_shared_distorttexture;
+rtexture_t *mod_shared_distorttexture[64];
 
 void Mod_BuildDetailTextures (void)
 {
@@ -79,21 +79,55 @@ void Mod_BuildDetailTextures (void)
        }
 }
 
+qbyte Mod_MorphDistortTexture (double y0, double y1, double y2, double y3, double morph)
+{
+       int     value = (int)(((y1 + y3 - (y0 + y2)) * morph * morph * morph) +
+                               ((2 * (y0 - y1) + y2 - y3) * morph * morph) +
+                               ((y2 - y0) * morph) +
+                               (y1));
+
+       if (value > 255)
+               value = 255;
+       if (value < 0)
+               value = 0;
+
+       return (qbyte)value;
+}
+
 void Mod_BuildDistortTexture (void)
 {
-       int x, y;
+       int x, y, i, j;
 #define DISTORTRESOLUTION 32
-       qbyte data[DISTORTRESOLUTION][DISTORTRESOLUTION][2];
-       for (y=0; y<DISTORTRESOLUTION; y++)
+       qbyte data[5][DISTORTRESOLUTION][DISTORTRESOLUTION][2];
+
+       for (i=0; i<4; i++)
+       {
+               for (y=0; y<DISTORTRESOLUTION; y++)
+               {
+                       for (x=0; x<DISTORTRESOLUTION; x++)
+                       {
+                               data[i][y][x][0] = rand () & 255;
+                               data[i][y][x][1] = rand () & 255;
+                       }
+               }
+       }
+
+       for (i=0; i<4; i++)
        {
-               for (x=0; x<DISTORTRESOLUTION; x++)
+               for (j=0; j<16; j++)
                {
-                       data[y][x][0] = rand () & 255;
-                       data[y][x][1] = rand () & 255;
+                       for (y=0; y<DISTORTRESOLUTION; y++)
+                       {
+                               for (x=0; x<DISTORTRESOLUTION; x++)
+                               {
+                                       data[4][y][x][0] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][0], data[i][y][x][0], data[(i+1)&3][y][x][0], data[(i+2)&3][y][x][0], 0.0625*j);
+                                       data[4][y][x][1] = Mod_MorphDistortTexture (data[(i-1)&3][y][x][1], data[i][y][x][1], data[(i+1)&3][y][x][1], data[(i+2)&3][y][x][1], 0.0625*j);
+                               }
+                       }
+                       mod_shared_distorttexture[i*16+j] = R_LoadTexture2D(mod_shared_texturepool, va("distorttexture%i", i*16+j), DISTORTRESOLUTION, DISTORTRESOLUTION, &data[4][0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
                }
        }
 
-       mod_shared_distorttexture = R_LoadTexture2D(mod_shared_texturepool, "distorttexture", DISTORTRESOLUTION, DISTORTRESOLUTION, &data[0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
        return;
 }
 
@@ -655,7 +689,7 @@ void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numve
        /*
        int i, i1, i2, i3;
        float *v;
-       while (mesh->numverts + numverts > mesh->maxverts || mesh->numtriangles + (numverts - 2) > mesh->maxtriangles)
+       while (mesh->num_vertices + numverts > mesh->maxverts || mesh->num_triangles + (numverts - 2) > mesh->maxtriangles)
        {
                if (mesh->next == NULL)
                        mesh->next = Mod_ShadowMesh_Alloc(mempool, max(mesh->maxtriangles, numverts));
@@ -668,10 +702,10 @@ void Mod_ShadowMesh_AddPolygon(mempool_t *mempool, shadowmesh_t *mesh, int numve
        {
                i2 = i3;
                i3 = Mod_ShadowMesh_AddVertex(mesh, v);
-               mesh->elements[mesh->numtriangles * 3 + 0] = i1;
-               mesh->elements[mesh->numtriangles * 3 + 1] = i2;
-               mesh->elements[mesh->numtriangles * 3 + 2] = i3;
-               mesh->numtriangles++;
+               mesh->elements[mesh->num_triangles * 3 + 0] = i1;
+               mesh->elements[mesh->num_triangles * 3 + 1] = i2;
+               mesh->elements[mesh->num_triangles * 3 + 2] = i3;
+               mesh->num_triangles++;
        }
        */
 }
@@ -703,7 +737,7 @@ shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh)
                        newmesh->next = firstmesh;
                        firstmesh = newmesh;
                        //Con_Printf("mesh\n");
-                       //for (i = 0;i < newmesh->numtriangles;i++)
+                       //for (i = 0;i < newmesh->num_triangles;i++)
                        //      Con_Printf("tri %d %d %d\n", newmesh->elements[i * 3 + 0], newmesh->elements[i * 3 + 1], newmesh->elements[i * 3 + 2]);
                        Mod_ValidateElements(newmesh->element3i, newmesh->numtriangles, newmesh->numverts, __FILE__, __LINE__);
                        Mod_BuildTriangleNeighbors(newmesh->neighbor3i, newmesh->element3i, newmesh->numtriangles);
@@ -714,8 +748,8 @@ shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh)
        shadowmesh_t *mesh;
        for (mesh = firstmesh;mesh;mesh = mesh->next)
        {
-               Mod_ValidateElements(mesh->elements, mesh->numtriangles, mesh->numverts, __FILE__, __LINE__);
-               Mod_BuildTriangleNeighbors(mesh->neighbors, mesh->elements, mesh->numtriangles);
+               Mod_ValidateElements(mesh->elements, mesh->num_triangles, mesh->num_vertices, __FILE__, __LINE__);
+               Mod_BuildTriangleNeighbors(mesh->neighbors, mesh->elements, mesh->num_triangles);
        }
 #endif
        return firstmesh;