]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
Added multiplayer maps to -did2 mode
[xonotic/darkplaces.git] / gl_rmain.c
index 8d5a193f024de9aec01c063aa6adc6b7428381b9..0a1dbd8472eea49295e2541878b8b2f79750b903 100644 (file)
@@ -105,7 +105,9 @@ 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 developer_texturelogging = {0, "developer_texturelogging", "1"};
+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"};
 
@@ -473,7 +475,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");
@@ -513,6 +515,7 @@ void GL_Main_Init(void)
        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 +582,6 @@ void Render_Init(void)
 {
        gl_backend_init();
        R_Textures_Init();
-       Mod_RenderInit();
        R_MeshQueue_Init();
        GL_Main_Init();
        GL_Draw_Init();
@@ -593,6 +595,7 @@ void Render_Init(void)
        UI_Init();
        Sbar_Init();
        R_LightningBeams_Init();
+       Mod_RenderInit();
 }
 
 /*
@@ -606,7 +609,7 @@ void GL_Init (void)
        VID_CheckExtensions();
 
        // LordHavoc: report supported extensions
-       Con_DPrintf("\nengine extensions: %s\n", ENGINE_EXTENSIONS);
+       Con_DPrintf("\nengine extensions: %s\n", vm_sv_extensions );
 
        // clear to black (loading plaque will be seen over this)
        qglClearColor(0,0,0,1);
@@ -814,8 +817,8 @@ static void R_BlendView(void)
                // set the (poorly named) screenwidth and screenheight variables to
                // a power of 2 at least as large as the screen, these will define the
                // size of the texture to allocate
-               for (screenwidth = 1;screenwidth < vid.realwidth;screenwidth *= 2);
-               for (screenheight = 1;screenheight < vid.realheight;screenheight *= 2);
+               for (screenwidth = 1;screenwidth < vid.width;screenwidth *= 2);
+               for (screenheight = 1;screenheight < vid.height;screenheight *= 2);
                // allocate textures as needed
                if (!r_bloom_texture_screen)
                        r_bloom_texture_screen = R_LoadTexture2D(r_main_texturepool, "screen", screenwidth, screenheight, NULL, TEXTYPE_RGBA, TEXF_FORCENEAREST | TEXF_CLAMP | TEXF_ALWAYSPRECACHE, NULL);
@@ -852,14 +855,14 @@ static void R_BlendView(void)
                R_Mesh_State(&m);
                // copy view into the full resolution screen image texture
                GL_ActiveTexture(0);
-               qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.realheight - (r_view_y + r_view_height), r_view_width, r_view_height);
+               qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.height - (r_view_y + r_view_height), r_view_width, r_view_height);
                c_bloomcopies++;
                c_bloomcopypixels += r_view_width * r_view_height;
                // now scale it down to the bloom size and raise to a power of itself
                // to darken it (this leaves the really bright stuff bright, and
                // everything else becomes very dark)
                // TODO: optimize with multitexture or GLSL
-               qglViewport(r_view_x, vid.realheight - (r_view_y + bloomheight), bloomwidth, bloomheight);
+               qglViewport(r_view_x, vid.height - (r_view_y + bloomheight), bloomwidth, bloomheight);
                GL_BlendFunc(GL_ONE, GL_ZERO);
                GL_Color(1, 1, 1, 1);
                R_Mesh_Draw(0, 4, 2, polygonelements);
@@ -881,7 +884,7 @@ static void R_BlendView(void)
                m.pointer_texcoord[0] = varray_texcoord2f[2];
                R_Mesh_State(&m);
                GL_ActiveTexture(0);
-               qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.realheight - (r_view_y + bloomheight), bloomwidth, bloomheight);
+               qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.height - (r_view_y + bloomheight), bloomwidth, bloomheight);
                c_bloomcopies++;
                c_bloomcopypixels += bloomwidth * bloomheight;
                // blend on at multiple vertical offsets to achieve a vertical blur
@@ -915,7 +918,7 @@ static void R_BlendView(void)
                }
                // copy the vertically blurred bloom view to a texture
                GL_ActiveTexture(0);
-               qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.realheight - (r_view_y + bloomheight), bloomwidth, bloomheight);
+               qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.height - (r_view_y + bloomheight), bloomwidth, bloomheight);
                c_bloomcopies++;
                c_bloomcopypixels += bloomwidth * bloomheight;
                // blend the vertically blurred image at multiple offsets horizontally
@@ -950,11 +953,11 @@ static void R_BlendView(void)
                }
                // copy the blurred bloom view to a texture
                GL_ActiveTexture(0);
-               qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.realheight - (r_view_y + bloomheight), bloomwidth, bloomheight);
+               qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_view_x, vid.height - (r_view_y + bloomheight), bloomwidth, bloomheight);
                c_bloomcopies++;
                c_bloomcopypixels += bloomwidth * bloomheight;
                // go back to full view area
-               qglViewport(r_view_x, vid.realheight - (r_view_y + r_view_height), r_view_width, r_view_height);
+               qglViewport(r_view_x, vid.height - (r_view_y + r_view_height), r_view_width, r_view_height);
                // put the original screen image back in place and blend the bloom
                // texture on it
                memset(&m, 0, sizeof(m));
@@ -1022,11 +1025,11 @@ void R_RenderView(void)
        if (!r_refdef.entities/* || !r_refdef.worldmodel*/)
                return; //Host_Error ("R_RenderView: NULL worldmodel");
 
-       r_view_width = bound(0, r_refdef.width, vid.realwidth);
-       r_view_height = bound(0, r_refdef.height, vid.realheight);
+       r_view_width = bound(0, r_refdef.width, vid.width);
+       r_view_height = bound(0, r_refdef.height, vid.height);
        r_view_depth = 1;
-       r_view_x = bound(0, r_refdef.x, vid.realwidth - r_refdef.width);
-       r_view_y = bound(0, r_refdef.y, vid.realheight - r_refdef.height);
+       r_view_x = bound(0, r_refdef.x, vid.width - r_refdef.width);
+       r_view_y = bound(0, r_refdef.y, vid.height - r_refdef.height);
        r_view_z = 0;
        r_view_fov_x = bound(1, r_refdef.fov_x, 170);
        r_view_fov_y = bound(1, r_refdef.fov_y, 170);
@@ -1039,7 +1042,7 @@ void R_RenderView(void)
        r_lightmapintensity = r_rtworld ? r_shadow_realtime_world_lightmaps.value : 1;
 
        // GL is weird because it's bottom to top, r_view_y is top to bottom
-       qglViewport(r_view_x, vid.realheight - (r_view_y + r_view_height), r_view_width, r_view_height);
+       qglViewport(r_view_x, vid.height - (r_view_y + r_view_height), r_view_width, r_view_height);
        GL_Scissor(r_view_x, r_view_y, r_view_width, r_view_height);
        GL_ScissorTest(true);
        GL_DepthMask(true);
@@ -1061,7 +1064,7 @@ void R_RenderView(void)
        R_BlendView();
        R_TimeReport("blendview");
 
-       GL_Scissor(0, 0, vid.realwidth, vid.realheight);
+       GL_Scissor(0, 0, vid.width, vid.height);
        GL_ScissorTest(false);
 }
 
@@ -1453,6 +1456,7 @@ void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *plane
 
 void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
 {
+       texture_t *texture = t;
        model_t *model = ent->model;
        int s = ent->skinnum;
        if ((unsigned int)s >= (unsigned int)model->numskins)
@@ -1467,9 +1471,10 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                        s = model->skinscenes[s].firstframe;
        }
        if (s > 0)
-               t = t->currentframe = t + s * model->num_surfaces;
+               t = t + s * model->num_surfaces;
        if (t->animated)
-               t = t->currentframe = t->anim_frames[ent->frame != 0][(t->anim_total[ent->frame != 0] >= 2) ? ((int)(r_refdef.time * 5.0f) % t->anim_total[ent->frame != 0]) : 0];
+               t = t->anim_frames[ent->frame != 0][(t->anim_total[ent->frame != 0] >= 2) ? ((int)(r_refdef.time * 5.0f) % t->anim_total[ent->frame != 0]) : 0];
+       texture->currentframe = t;
        t->currentmaterialflags = t->basematerialflags;
        t->currentalpha = ent->alpha;
        if (t->basematerialflags & MATERIALFLAG_WATERALPHA)
@@ -1480,6 +1485,8 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                t->currentmaterialflags |= MATERIALFLAG_ADD | MATERIALFLAG_TRANSPARENT;
        else if (t->currentalpha < 1)
                t->currentmaterialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_TRANSPARENT;
+       if (ent->effects & EF_NODEPTHTEST)
+               t->currentmaterialflags |= MATERIALFLAG_NODEPTHTEST;
 }
 
 void R_UpdateAllTextureInfo(entity_render_t *ent)
@@ -1523,7 +1530,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);
@@ -1560,7 +1567,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);
@@ -1588,24 +1595,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;
@@ -1623,7 +1630,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)
                {
@@ -1710,7 +1717,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
        float *c;
        float diff[3];
        float colorpants[3], colorshirt[3];
-       float f, r, g, b, a, base, colorscale;
+       float f, r, g, b, a, colorscale;
        const msurface_t *surface;
        qboolean dolightmap;
        qboolean doambient;
@@ -1724,16 +1731,15 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
        qboolean dofullbrightpants;
        qboolean dofullbrightshirt;
        qboolean applycolor;
-       qboolean lightmodel = false;
+       qboolean lightmode = 0;
        rtexture_t *basetexture;
        rmeshstate_t m;
-       texture = texture->currentframe;
        if (texture->currentmaterialflags & MATERIALFLAG_NODRAW)
                return;
        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)
        {
@@ -1750,7 +1756,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);
@@ -1883,7 +1889,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        dofullbrightshirt = false;
                        dofullbrightpants = false;
                }
-               if (dolightmap && gl_combine.integer)
+               if (dolightmap && r_textureunits.integer >= 2 && gl_combine.integer)
                {
                        memset(&m, 0, sizeof(m));
                        m.tex[1] = R_GetTexture(basetexture);
@@ -1892,22 +1898,20 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        m.texrgbscale[1] = 2;
                        m.pointer_color = varray_color4f;
                        R_Mesh_State(&m);
-                       colorscale = 1;
+                       // transparent is not affected by r_lightmapintensity
+                       if (!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                               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;
-                       base = r_ambient.value * (1.0f / 64.0f);
-                       // 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++)
                        {
@@ -1919,13 +1923,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))
+               else if (dolightmap && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT) && !lightmode)
                {
                        // single texture
                        GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -1943,7 +1947,7 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
                                        R_Mesh_ColorPointer(NULL);
                                }
-                               else //if (r == 1 && g == 1 && b == 1)
+                               else
                                {
                                        R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                        R_Mesh_ColorPointer(surface->groupmesh->data_lightmapcolor4f);
@@ -1977,36 +1981,34 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        if (waterscrolling)
                                m.texmatrix[0] = r_waterscrollmatrix;
                        m.pointer_color = varray_color4f;
-                       colorscale = 1;
+                       colorscale = 2;
                        if (gl_combine.integer)
                        {
-                               m.texrgbscale[0] = 4;
-                               colorscale *= 0.25f;
+                               m.texrgbscale[0] = 2;
+                               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 && 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);
@@ -2014,13 +2016,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);
@@ -2035,36 +2036,34 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        if (waterscrolling)
                                m.texmatrix[0] = r_waterscrollmatrix;
                        m.pointer_color = varray_color4f;
-                       colorscale = 1;
+                       colorscale = 2;
                        if (gl_combine.integer)
                        {
-                               m.texrgbscale[0] = 4;
-                               colorscale *= 0.25f;
+                               m.texrgbscale[0] = 2;
+                               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);
@@ -2072,13 +2071,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);
@@ -2093,36 +2091,34 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        if (waterscrolling)
                                m.texmatrix[0] = r_waterscrollmatrix;
                        m.pointer_color = varray_color4f;
-                       colorscale = 1;
+                       colorscale = 2;
                        if (gl_combine.integer)
                        {
-                               m.texrgbscale[0] = 4;
-                               colorscale *= 0.25f;
+                               m.texrgbscale[0] = 2;
+                               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);
@@ -2130,13 +2126,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);
@@ -2154,16 +2149,16 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                m.texmatrix[0] = r_waterscrollmatrix;
                        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] = 4;
-                               colorscale *= 0.25f;
+                               colorscale = 0.25f;
                        }
                        R_Mesh_State(&m);
-                       base = r_ambient.value * (1.0f / 64.0f);
-                       r = ent->colormod[0] * colorscale * base;
-                       g = ent->colormod[1] * colorscale * base;
-                       b = ent->colormod[2] * colorscale * base;
+                       colorscale *= r_ambient.value * (1.0f / 64.0f);
+                       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;
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
@@ -2171,7 +2166,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);
@@ -2206,10 +2201,9 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                m.texmatrix[0] = r_waterscrollmatrix;
                        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++)
@@ -2217,7 +2211,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);
@@ -2326,7 +2320,7 @@ void R_QueueTextureSurfaceList(entity_render_t *ent, texture_t *texture, int tex
                                tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
                                tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
                                Matrix4x4_Transform(&ent->matrix, tempcenter, center);
-                               R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->data_surfaces);
+                               R_MeshQueue_AddTransparent(texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->data_surfaces);
                        }
                }
        }
@@ -2385,8 +2379,8 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                                        numsurfacelist = 0;
                                }
                                t = surface->texture;
-                               f = t->currentmaterialflags & flagsmask;
                                texture = t->currentframe;
+                               f = texture->currentmaterialflags & flagsmask;
                        }
                        if (f && surface->num_triangles)
                        {
@@ -2415,8 +2409,8 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                                        numsurfacelist = 0;
                                }
                                t = surface->texture;
-                               f = t->currentmaterialflags & flagsmask;
                                texture = t->currentframe;
+                               f = texture->currentmaterialflags & flagsmask;
                        }
                        if (f && surface->num_triangles)
                        {