]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
removed distortion textures formerly used by GF3 water shader, this frees up 128K...
[xonotic/darkplaces.git] / gl_rmain.c
index b1f71307787e95d86947e79c241d23cb20ccf15e..33f58d2626bd8fdefb2322c76a873538fe6c4e0c 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"};
@@ -105,6 +104,8 @@ cvar_t r_bloom_blur = {CVAR_SAVE, "r_bloom_blur", "8"};
 cvar_t r_bloom_resolution = {CVAR_SAVE, "r_bloom_resolution", "320"};
 cvar_t r_bloom_power = {CVAR_SAVE, "r_bloom_power", "4"};
 
+cvar_t r_smoothnormals_areaweighting = {0, "r_smoothnormals_areaweighting", "1"};
+
 cvar_t developer_texturelogging = {0, "developer_texturelogging", "0"};
 
 cvar_t gl_lightmaps = {0, "gl_lightmaps", "0"};
@@ -119,7 +120,6 @@ 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)
 {
@@ -268,54 +268,6 @@ static void R_BuildDetailTextures (void)
        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];
@@ -443,7 +395,6 @@ void gl_main_start(void)
        R_BuildBlankTextures();
        R_BuildNoTexture();
        R_BuildDetailTextures();
-       R_BuildDistortTexture();
        if (gl_texturecubemap)
        {
                R_BuildWhiteCube();
@@ -473,7 +424,7 @@ void gl_main_newmap(void)
        if (cl.worldmodel)
        {
                strlcpy(entname, cl.worldmodel->name, sizeof(entname));
-               l = strlen(entname) - 4;
+               l = (int)strlen(entname) - 4;
                if (l >= 0 && !strcmp(entname + l, ".bsp"))
                {
                        strcpy(entname + l, ".ent");
@@ -506,13 +457,13 @@ 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);
        Cvar_RegisterVariable(&r_bloom_blur);
        Cvar_RegisterVariable(&r_bloom_resolution);
        Cvar_RegisterVariable(&r_bloom_power);
+       Cvar_RegisterVariable(&r_smoothnormals_areaweighting);
        Cvar_RegisterVariable(&developer_texturelogging);
        Cvar_RegisterVariable(&gl_lightmaps);
        if (gamemode == GAME_NEHAHRA || gamemode == GAME_NEXUIZ || gamemode == GAME_TENEBRAE)
@@ -579,7 +530,6 @@ void Render_Init(void)
 {
        gl_backend_init();
        R_Textures_Init();
-       Mod_RenderInit();
        R_MeshQueue_Init();
        GL_Main_Init();
        GL_Draw_Init();
@@ -593,6 +543,7 @@ void Render_Init(void)
        UI_Init();
        Sbar_Init();
        R_LightningBeams_Init();
+       Mod_RenderInit();
 }
 
 /*
@@ -1484,6 +1435,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)
@@ -1527,7 +1482,7 @@ void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture
                        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);
+                       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);
                }
                // a single autosprite surface can contain multiple sprites...
                VectorClear(forward);
@@ -1564,7 +1519,7 @@ void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture
                        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);
+                       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);
                }
                Matrix4x4_Transform(&ent->inversematrix, r_viewforward, forward);
                Matrix4x4_Transform(&ent->inversematrix, r_viewright, right);
@@ -1592,24 +1547,24 @@ void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture
        R_Mesh_VertexPointer(rsurface_vertex3f);
 }
 
-void RSurf_SetColorPointer(const entity_render_t *ent, const msurface_t *surface, const vec3_t modelorg, float r, float g, float b, float a, qboolean lightmodel, qboolean vertexlight, qboolean applycolor, qboolean applyfog)
+void RSurf_SetColorPointer(const entity_render_t *ent, const msurface_t *surface, const vec3_t modelorg, float r, float g, float b, float a, int lightmode, qboolean applycolor, qboolean applyfog)
 {
        int i;
        float f;
        float *v, *c, *c2;
        vec3_t diff;
-       if (lightmodel)
+       if (lightmode >= 2)
        {
                vec4_t ambientcolor4f;
                vec3_t diffusecolor;
                vec3_t diffusenormal;
-               if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, r, g, b, a, false))
+               if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, r*0.5f, g*0.5f, b*0.5f, a, false))
                {
                        rsurface_lightmapcolor4f = varray_color4f;
                        if (rsurface_normal3f == NULL)
                        {
                                rsurface_normal3f = varray_normal3f;
-                               Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle, rsurface_normal3f);
+                               Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
                        }
                        R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, surface->groupmesh->num_vertices, rsurface_vertex3f + 3 * surface->num_firstvertex, rsurface_normal3f + 3 * surface->num_firstvertex, rsurface_lightmapcolor4f + 4 * surface->num_firstvertex);
                        r = 1;
@@ -1627,7 +1582,7 @@ void RSurf_SetColorPointer(const entity_render_t *ent, const msurface_t *surface
                        rsurface_lightmapcolor4f = NULL;
                }
        }
-       else if (vertexlight)
+       else if (lightmode >= 1)
        {
                if (surface->lightmapinfo)
                {
@@ -1722,13 +1677,12 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
        qboolean doglow;
        qboolean dofogpass;
        qboolean fogallpasses;
-       qboolean waterscrolling;
        qboolean dopants;
        qboolean doshirt;
        qboolean dofullbrightpants;
        qboolean dofullbrightshirt;
        qboolean applycolor;
-       qboolean lightmodel = false;
+       qboolean lightmode = 0;
        rtexture_t *basetexture;
        rmeshstate_t m;
        if (texture->currentmaterialflags & MATERIALFLAG_NODRAW)
@@ -1736,7 +1690,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
        c_faces += texturenumsurfaces;
        // FIXME: identify models using a better check than ent->model->shadowmesh
        if (!(ent->effects & EF_FULLBRIGHT) && !ent->model->brush.shadowmesh)
-               lightmodel = true;
+               lightmode = 2;
        // gl_lightmaps debugging mode skips normal texturing
        if (gl_lightmaps.integer)
        {
@@ -1753,7 +1707,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
                        R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
                        RSurf_SetVertexPointer(ent, texture, surface, modelorg);
-                       RSurf_SetColorPointer(ent, surface, modelorg, 1, 1, 1, 1, lightmodel, !surface->lightmaptexture, false, false);
+                       RSurf_SetColorPointer(ent, surface, modelorg, 1, 1, 1, 1, lightmode ? lightmode : !surface->lightmaptexture, false, false);
                        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);
@@ -1769,8 +1723,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)
@@ -1814,43 +1766,6 @@ 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)
@@ -1890,8 +1805,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);
@@ -1900,20 +1814,15 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                colorscale = r_lightmapintensity;
                        else
                                colorscale = 1;
+                       // q3bsp has no lightmap updates, so the lightstylevalue that
+                       // would normally be baked into the lightmaptexture must be
+                       // applied to the color
+                       if (ent->model->type == mod_brushq3)
+                               colorscale *= d_lightstylevalue[0] * (1.0f / 128.0f);
                        r = ent->colormod[0] * colorscale;
                        g = ent->colormod[1] * colorscale;
                        b = ent->colormod[2] * colorscale;
                        a = texture->currentalpha;
-                       // q3bsp has no lightmap updates, so the lightstylevalue that
-                       // would normally be baked into the lightmaptexture must be
-                       // applied to the color
-                       if (ent->model->brushq3.data_lightmaps)
-                       {
-                               float scale = d_lightstylevalue[0] * (1.0f / 128.0f);
-                               r *= scale;
-                               g *= scale;
-                               b *= scale;
-                       }
                        applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
@@ -1925,13 +1834,13 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
                                else
                                        R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
-                               RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, lightmodel, !surface->lightmaptexture, applycolor, fogallpasses);
+                               RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, lightmode ? lightmode : !surface->lightmaptexture, applycolor, fogallpasses);
                                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);
                        }
                }
-               else if (dolightmap && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT) && !lightmodel)
+               else if (dolightmap && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT) && !lightmode)
                {
                        // single texture
                        GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -1963,8 +1872,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++)
                        {
@@ -1980,8 +1888,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)
@@ -1992,30 +1899,25 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        // transparent is not affected by r_lightmapintensity
                        if (!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                colorscale *= r_lightmapintensity;
+                       // q3bsp has no lightmap updates, so the lightstylevalue that
+                       // would normally be baked into the lightmaptexture must be
+                       // applied to the color
+                       if (dolightmap && ent->model->type == mod_brushq3)
+                               colorscale *= d_lightstylevalue[0] * (1.0f / 128.0f);
                        R_Mesh_State(&m);
                        r = ent->colormod[0] * colorscale;
                        g = ent->colormod[1] * colorscale;
                        b = ent->colormod[2] * colorscale;
                        a = texture->currentalpha;
+                       applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                        if (dolightmap)
                        {
-                               // q3bsp has no lightmap updates, so the lightstylevalue that
-                               // would normally be baked into the lightmaptexture must be
-                               // applied to the color
-                               if (ent->model->brushq3.data_lightmaps)
-                               {
-                                       float scale = d_lightstylevalue[0] * (1.0f / 128.0f);
-                                       r *= scale;
-                                       g *= scale;
-                                       b *= scale;
-                               }
-                               applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, lightmodel, true, applycolor, fogallpasses);
+                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, lightmode, applycolor, fogallpasses);
                                        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);
@@ -2023,13 +1925,12 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        }
                        else
                        {
-                               applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, false, false, applycolor, fogallpasses);
+                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, 0, applycolor, fogallpasses);
                                        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);
@@ -2041,42 +1942,36 @@ 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 = 1;
+                       colorscale = 2;
                        if (gl_combine.integer)
                        {
                                m.texrgbscale[0] = 2;
-                               colorscale *= 0.5f;
+                               colorscale = 1;
                        }
                        // transparent is not affected by r_lightmapintensity
                        if (!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                colorscale *= r_lightmapintensity;
+                       // q3bsp has no lightmap updates, so the lightstylevalue that
+                       // would normally be baked into the lightmaptexture must be
+                       // applied to the color
+                       if (dolightmap && !dofullbrightpants && ent->model->type == mod_brushq3)
+                               colorscale *= d_lightstylevalue[0] * (1.0f / 128.0f);
                        R_Mesh_State(&m);
                        r = ent->colormod[0] * colorpants[0] * colorscale;
                        g = ent->colormod[1] * colorpants[1] * colorscale;
                        b = ent->colormod[2] * colorpants[2] * colorscale;
                        a = texture->currentalpha;
+                       applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                        if (dolightmap && !dofullbrightpants)
                        {
-                               // q3bsp has no lightmap updates, so the lightstylevalue that
-                               // would normally be baked into the lightmaptexture must be
-                               // applied to the color
-                               if (ent->model->brushq3.data_lightmaps)
-                               {
-                                       float scale = d_lightstylevalue[0] * (1.0f / 128.0f);
-                                       r *= scale;
-                                       g *= scale;
-                                       b *= scale;
-                               }
-                               applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, lightmodel, true, applycolor, fogallpasses);
+                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, lightmode, applycolor, fogallpasses);
                                        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);
@@ -2084,13 +1979,12 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        }
                        else
                        {
-                               applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, false, false, applycolor, fogallpasses);
+                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, 0, applycolor, fogallpasses);
                                        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);
@@ -2102,42 +1996,36 @@ 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 = 1;
+                       colorscale = 2;
                        if (gl_combine.integer)
                        {
                                m.texrgbscale[0] = 2;
-                               colorscale *= 0.5f;
+                               colorscale *= 1;
                        }
                        // transparent is not affected by r_lightmapintensity
                        if (!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                colorscale *= r_lightmapintensity;
+                       // q3bsp has no lightmap updates, so the lightstylevalue that
+                       // would normally be baked into the lightmaptexture must be
+                       // applied to the color
+                       if (dolightmap && !dofullbrightshirt && ent->model->type == mod_brushq3)
+                               colorscale *= d_lightstylevalue[0] * (1.0f / 128.0f);
                        R_Mesh_State(&m);
                        r = ent->colormod[0] * colorshirt[0] * colorscale;
                        g = ent->colormod[1] * colorshirt[1] * colorscale;
                        b = ent->colormod[2] * colorshirt[2] * colorscale;
                        a = texture->currentalpha;
+                       applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                        if (dolightmap && !dofullbrightshirt)
                        {
-                               // q3bsp has no lightmap updates, so the lightstylevalue that
-                               // would normally be baked into the lightmaptexture must be
-                               // applied to the color
-                               if (ent->model->brushq3.data_lightmaps)
-                               {
-                                       float scale = d_lightstylevalue[0] * (1.0f / 128.0f);
-                                       r *= scale;
-                                       g *= scale;
-                                       b *= scale;
-                               }
-                               applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, lightmodel, true, applycolor, fogallpasses);
+                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, lightmode, applycolor, fogallpasses);
                                        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);
@@ -2145,13 +2033,12 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        }
                        else
                        {
-                               applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        RSurf_SetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, false, false, applycolor, fogallpasses);
+                                       RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, 0, applycolor, fogallpasses);
                                        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);
@@ -2165,14 +2052,13 @@ 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)
+                       if (gl_combine.integer && (ent->colormod[0] > 1 || ent->colormod[1] > 1 || ent->colormod[2] > 1))
                        {
-                               m.texrgbscale[0] = 2;
-                               colorscale *= 0.5f;
+                               m.texrgbscale[0] = 4;
+                               colorscale = 0.25f;
                        }
                        R_Mesh_State(&m);
                        colorscale *= r_ambient.value * (1.0f / 64.0f);
@@ -2186,7 +2072,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                surface = texturesurfacelist[texturesurfaceindex];
                                RSurf_SetVertexPointer(ent, texture, surface, modelorg);
                                R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                               RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, false, false, applycolor, fogallpasses);
+                               RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, 0, applycolor, fogallpasses);
                                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);
@@ -2217,14 +2103,12 @@ 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);
-                       colorscale = 1;
-                       r = ent->colormod[0] * colorscale;
-                       g = ent->colormod[1] * colorscale;
-                       b = ent->colormod[2] * colorscale;
+                       r = 1;
+                       g = 1;
+                       b = 1;
                        a = texture->currentalpha;
                        applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
@@ -2232,7 +2116,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                surface = texturesurfacelist[texturesurfaceindex];
                                RSurf_SetVertexPointer(ent, texture, surface, modelorg);
                                R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
-                               RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, false, false, applycolor, fogallpasses);
+                               RSurf_SetColorPointer(ent, surface, modelorg, r, g, b, a, 0, applycolor, fogallpasses);
                                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);
@@ -2258,8 +2142,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];