]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
removed detail texturing (it only worked in q1bsp and hlbsp maps, did not work proper...
[xonotic/darkplaces.git] / gl_rmain.c
index 0a1dbd8472eea49295e2541878b8b2f79750b903..bde443b49ad032deb5b011ec42cc76feda3535b3 100644 (file)
@@ -97,7 +97,6 @@ cvar_t r_textureunits = {0, "r_textureunits", "32"};
 cvar_t r_lerpsprites = {CVAR_SAVE, "r_lerpsprites", "1"};
 cvar_t r_lerpmodels = {CVAR_SAVE, "r_lerpmodels", "1"};
 cvar_t r_waterscroll = {CVAR_SAVE, "r_waterscroll", "1"};
-cvar_t r_watershader = {CVAR_SAVE, "r_watershader", "1"};
 
 cvar_t r_bloom = {CVAR_SAVE, "r_bloom", "0"};
 cvar_t r_bloom_intensity = {CVAR_SAVE, "r_bloom_intensity", "2"};
@@ -120,8 +119,6 @@ rtexture_t *r_texture_black;
 rtexture_t *r_texture_notexture;
 rtexture_t *r_texture_whitecube;
 rtexture_t *r_texture_normalizationcube;
-rtexture_t *r_texture_detailtextures[NUM_DETAILTEXTURES];
-rtexture_t *r_texture_distorttexture[64];
 
 void R_ModulateColors(float *in, float *out, int verts, float r, float g, float b)
 {
@@ -221,103 +218,6 @@ void FOG_registercvars(void)
        }
 }
 
-static void R_BuildDetailTextures (void)
-{
-       int i, x, y, light;
-       float vc[3], vx[3], vy[3], vn[3], lightdir[3];
-#define DETAILRESOLUTION 256
-       qbyte (*data)[DETAILRESOLUTION][4];
-       qbyte (*noise)[DETAILRESOLUTION];
-
-       // Allocate the buffers dynamically to avoid having such big guys on the stack
-       data = Mem_Alloc(tempmempool, DETAILRESOLUTION * sizeof(*data));
-       noise = Mem_Alloc(tempmempool, DETAILRESOLUTION * sizeof(*noise));
-
-       lightdir[0] = 0.5;
-       lightdir[1] = 1;
-       lightdir[2] = -0.25;
-       VectorNormalize(lightdir);
-       for (i = 0;i < NUM_DETAILTEXTURES;i++)
-       {
-               fractalnoise(&noise[0][0], DETAILRESOLUTION, DETAILRESOLUTION >> 4);
-               for (y = 0;y < DETAILRESOLUTION;y++)
-               {
-                       for (x = 0;x < DETAILRESOLUTION;x++)
-                       {
-                               vc[0] = x;
-                               vc[1] = y;
-                               vc[2] = noise[y][x] * (1.0f / 32.0f);
-                               vx[0] = x + 1;
-                               vx[1] = y;
-                               vx[2] = noise[y][(x + 1) % DETAILRESOLUTION] * (1.0f / 32.0f);
-                               vy[0] = x;
-                               vy[1] = y + 1;
-                               vy[2] = noise[(y + 1) % DETAILRESOLUTION][x] * (1.0f / 32.0f);
-                               VectorSubtract(vx, vc, vx);
-                               VectorSubtract(vy, vc, vy);
-                               CrossProduct(vx, vy, vn);
-                               VectorNormalize(vn);
-                               light = 128 - DotProduct(vn, lightdir) * 128;
-                               light = bound(0, light, 255);
-                               data[y][x][0] = data[y][x][1] = data[y][x][2] = light;
-                               data[y][x][3] = 255;
-                       }
-               }
-               r_texture_detailtextures[i] = R_LoadTexture2D(r_main_texturepool, va("detailtexture%i", i), DETAILRESOLUTION, DETAILRESOLUTION, &data[0][0][0], TEXTYPE_RGBA, TEXF_MIPMAP | TEXF_PRECACHE, NULL);
-       }
-
-       Mem_Free(noise);
-       Mem_Free(data);
-}
-
-static qbyte R_MorphDistortTexture (double y0, double y1, double y2, double y3, double morph)
-{
-       int m = (int)(((y1 + y3 - (y0 + y2)) * morph * morph * morph) +
-                       ((2 * (y0 - y1) + y2 - y3) * morph * morph) +
-                       ((y2 - y0) * morph) +
-                       (y1));
-       return (qbyte)bound(0, m, 255);
-}
-
-static void R_BuildDistortTexture (void)
-{
-       int x, y, i, j;
-#define DISTORTRESOLUTION 32
-       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 (j=0; j<16; j++)
-               {
-                       r_texture_distorttexture[i*16+j] = NULL;
-                       if (gl_textureshader)
-                       {
-                               for (y=0; y<DISTORTRESOLUTION; y++)
-                               {
-                                       for (x=0; x<DISTORTRESOLUTION; x++)
-                                       {
-                                               data[4][y][x][0] = R_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] = R_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);
-                                       }
-                               }
-                               r_texture_distorttexture[i*16+j] = R_LoadTexture2D(r_main_texturepool, va("distorttexture%i", i*16+j), DISTORTRESOLUTION, DISTORTRESOLUTION, &data[4][0][0][0], TEXTYPE_DSDT, TEXF_PRECACHE, NULL);
-                       }
-               }
-       }
-}
-
 static void R_BuildBlankTextures(void)
 {
        qbyte data[4];
@@ -444,8 +344,6 @@ void gl_main_start(void)
        r_bloom_texture_bloom = NULL;
        R_BuildBlankTextures();
        R_BuildNoTexture();
-       R_BuildDetailTextures();
-       R_BuildDistortTexture();
        if (gl_texturecubemap)
        {
                R_BuildWhiteCube();
@@ -508,7 +406,6 @@ void GL_Main_Init(void)
        Cvar_RegisterVariable(&r_lerpsprites);
        Cvar_RegisterVariable(&r_lerpmodels);
        Cvar_RegisterVariable(&r_waterscroll);
-       Cvar_RegisterVariable(&r_watershader);
        Cvar_RegisterVariable(&r_drawcollisionbrushes);
        Cvar_RegisterVariable(&r_bloom);
        Cvar_RegisterVariable(&r_bloom_intensity);
@@ -1487,6 +1384,10 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                t->currentmaterialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_TRANSPARENT;
        if (ent->effects & EF_NODEPTHTEST)
                t->currentmaterialflags |= MATERIALFLAG_NODEPTHTEST;
+       if (t->currentmaterialflags & MATERIALFLAG_WATER && r_waterscroll.value != 0)
+               t->currenttexmatrix = r_waterscrollmatrix;
+       else
+               t->currenttexmatrix = r_identitymatrix;
 }
 
 void R_UpdateAllTextureInfo(entity_render_t *ent)
@@ -1721,11 +1622,9 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
        const msurface_t *surface;
        qboolean dolightmap;
        qboolean doambient;
-       qboolean dodetail;
        qboolean doglow;
        qboolean dofogpass;
        qboolean fogallpasses;
-       qboolean waterscrolling;
        qboolean dopants;
        qboolean doshirt;
        qboolean dofullbrightpants;
@@ -1772,8 +1671,6 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        else
                GL_BlendFunc(GL_ONE, GL_ZERO);
-       // water waterscrolling in texture matrix
-       waterscrolling = (texture->currentmaterialflags & MATERIALFLAG_WATER) && r_waterscroll.value != 0;
        if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
                qglDisable(GL_CULL_FACE);
        if (texture->currentmaterialflags & MATERIALFLAG_SKY)
@@ -1817,49 +1714,11 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
                }
        }
-       else if ((texture->currentmaterialflags & MATERIALFLAG_WATER) && r_watershader.value && gl_textureshader && !texture->skin.glow && !fogenabled && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
-       {
-               // NVIDIA Geforce3 distortion texture shader on water
-               float args[4] = {0.05f,0,0,0.04f};
-               memset(&m, 0, sizeof(m));
-               m.tex[0] = R_GetTexture(r_texture_distorttexture[(int)(r_refdef.time * 16)&63]);
-               m.tex[1] = R_GetTexture(texture->skin.base);
-               m.texcombinergb[0] = GL_REPLACE;
-               m.texcombinergb[1] = GL_REPLACE;
-               Matrix4x4_CreateFromQuakeEntity(&m.texmatrix[0], 0, 0, 0, 0, 0, 0, r_watershader.value);
-               m.texmatrix[1] = r_waterscrollmatrix;
-               R_Mesh_State(&m);
-
-               GL_Color(1, 1, 1, texture->currentalpha);
-               GL_ActiveTexture(0);
-               qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
-               GL_ActiveTexture(1);
-               qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
-               qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
-               qglTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, &args[0]);
-               qglEnable(GL_TEXTURE_SHADER_NV);
-
-               for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
-               {
-                       surface = texturesurfacelist[texturesurfaceindex];
-                       RSurf_SetVertexPointer(ent, texture, surface, modelorg);
-                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                       R_Mesh_TexCoordPointer(1, 2, surface->groupmesh->data_texcoordtexture2f);
-                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
-                       GL_LockArrays(0, 0);
-               }
-
-               qglDisable(GL_TEXTURE_SHADER_NV);
-               qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
-               GL_ActiveTexture(0);
-       }
        else if (texture->currentmaterialflags & (MATERIALFLAG_WATER | MATERIALFLAG_WALL))
        {
                // normal surface (wall or water)
                dolightmap = !(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT);
                doambient = r_ambient.value >= (1/64.0f);
-               dodetail = r_detailtextures.integer && texture->skin.detail != NULL && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT);
                doglow = texture->skin.glow != NULL;
                dofogpass = fogenabled && !(texture->currentmaterialflags & MATERIALFLAG_ADD);
                fogallpasses = fogenabled && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT);
@@ -1893,8 +1752,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                {
                        memset(&m, 0, sizeof(m));
                        m.tex[1] = R_GetTexture(basetexture);
-                       if (waterscrolling)
-                               m.texmatrix[1] = r_waterscrollmatrix;
+                       m.texmatrix[1] = texture->currenttexmatrix;
                        m.texrgbscale[1] = 2;
                        m.pointer_color = varray_color4f;
                        R_Mesh_State(&m);
@@ -1961,8 +1819,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(basetexture);
-                       if (waterscrolling)
-                               m.texmatrix[0] = r_waterscrollmatrix;
+                       m.texmatrix[0] = texture->currenttexmatrix;
                        R_Mesh_State(&m);
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
@@ -1978,8 +1835,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                {
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(basetexture);
-                       if (waterscrolling)
-                               m.texmatrix[0] = r_waterscrollmatrix;
+                       m.texmatrix[0] = texture->currenttexmatrix;
                        m.pointer_color = varray_color4f;
                        colorscale = 2;
                        if (gl_combine.integer)
@@ -2033,8 +1889,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(texture->skin.pants);
-                       if (waterscrolling)
-                               m.texmatrix[0] = r_waterscrollmatrix;
+                       m.texmatrix[0] = texture->currenttexmatrix;
                        m.pointer_color = varray_color4f;
                        colorscale = 2;
                        if (gl_combine.integer)
@@ -2088,8 +1943,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(texture->skin.shirt);
-                       if (waterscrolling)
-                               m.texmatrix[0] = r_waterscrollmatrix;
+                       m.texmatrix[0] = texture->currenttexmatrix;
                        m.pointer_color = varray_color4f;
                        colorscale = 2;
                        if (gl_combine.integer)
@@ -2145,8 +1999,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        GL_DepthMask(false);
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(texture->skin.base);
-                       if (waterscrolling)
-                               m.texmatrix[0] = r_waterscrollmatrix;
+                       m.texmatrix[0] = texture->currenttexmatrix;
                        m.pointer_color = varray_color4f;
                        colorscale = 1;
                        if (gl_combine.integer && (ent->colormod[0] > 1 || ent->colormod[1] > 1 || ent->colormod[2] > 1))
@@ -2172,24 +2025,6 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                GL_LockArrays(0, 0);
                        }
                }
-               if (dodetail)
-               {
-                       GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
-                       GL_DepthMask(false);
-                       GL_Color(1, 1, 1, 1);
-                       memset(&m, 0, sizeof(m));
-                       m.tex[0] = R_GetTexture(texture->skin.detail);
-                       R_Mesh_State(&m);
-                       for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
-                       {
-                               surface = texturesurfacelist[texturesurfaceindex];
-                               RSurf_SetVertexPointer(ent, texture, surface, modelorg);
-                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoorddetail2f);
-                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
-                               GL_LockArrays(0, 0);
-                       }
-               }
                if (doglow)
                {
                        // if glow was not already done using multitexture, do it now.
@@ -2197,8 +2032,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        GL_DepthMask(false);
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(texture->skin.glow);
-                       if (waterscrolling)
-                               m.texmatrix[0] = r_waterscrollmatrix;
+                       m.texmatrix[0] = texture->currenttexmatrix;
                        m.pointer_color = varray_color4f;
                        R_Mesh_State(&m);
                        r = 1;
@@ -2237,8 +2071,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        GL_DepthMask(false);
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(texture->skin.fog);
-                       if (waterscrolling)
-                               m.texmatrix[0] = r_waterscrollmatrix;
+                       m.texmatrix[0] = texture->currenttexmatrix;
                        R_Mesh_State(&m);
                        r = fogcolor[0];
                        g = fogcolor[1];