]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
Temporary workaround for tempstring offset console spam in Xonotic.
[xonotic/darkplaces.git] / gl_rmain.c
index 7de7a31884d02f476ad36edd51577cdd6cfac84a..2897c78f8e43f7997cc1c5627c4539c50ba25c2a 100644 (file)
@@ -190,6 +190,7 @@ cvar_t r_glsl_postprocess_uservec1_enable = {CVAR_CLIENT | CVAR_SAVE, "r_glsl_po
 cvar_t r_glsl_postprocess_uservec2_enable = {CVAR_CLIENT | CVAR_SAVE, "r_glsl_postprocess_uservec2_enable", "1", "enables postprocessing uservec2 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
 cvar_t r_glsl_postprocess_uservec3_enable = {CVAR_CLIENT | CVAR_SAVE, "r_glsl_postprocess_uservec3_enable", "1", "enables postprocessing uservec3 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
 cvar_t r_glsl_postprocess_uservec4_enable = {CVAR_CLIENT | CVAR_SAVE, "r_glsl_postprocess_uservec4_enable", "1", "enables postprocessing uservec4 usage, creates USERVEC1 define (only useful if default.glsl has been customized)"};
+cvar_t r_colorfringe = {CVAR_CLIENT | CVAR_SAVE, "r_colorfringe", "0", "Chromatic aberration. Values higher than 0.025 will noticeably distort the image"};
 
 cvar_t r_water = {CVAR_CLIENT | CVAR_SAVE, "r_water", "0", "whether to use reflections and refraction on water surfaces (note: r_wateralpha must be set below 1)"};
 cvar_t r_water_cameraentitiesonly = {CVAR_CLIENT | CVAR_SAVE, "r_water_cameraentitiesonly", "0", "whether to only show QC-defined reflections/refractions (typically used for camera- or portal-like effects)"};
@@ -198,7 +199,7 @@ cvar_t r_water_resolutionmultiplier = {CVAR_CLIENT | CVAR_SAVE, "r_water_resolut
 cvar_t r_water_refractdistort = {CVAR_CLIENT | CVAR_SAVE, "r_water_refractdistort", "0.01", "how much water refractions shimmer"};
 cvar_t r_water_reflectdistort = {CVAR_CLIENT | CVAR_SAVE, "r_water_reflectdistort", "0.01", "how much water reflections shimmer"};
 cvar_t r_water_scissormode = {CVAR_CLIENT, "r_water_scissormode", "3", "scissor (1) or cull (2) or both (3) water renders"};
-cvar_t r_water_lowquality = {CVAR_CLIENT, "r_water_lowquality", "0", "special option to accelerate water rendering, 1 disables shadows and particles, 2 disables all dynamic lights"};
+cvar_t r_water_lowquality = {CVAR_CLIENT, "r_water_lowquality", "0", "special option to accelerate water rendering: 1 disables all dynamic lights, 2 disables particles too"};
 cvar_t r_water_hideplayer = {CVAR_CLIENT | CVAR_SAVE, "r_water_hideplayer", "0", "if set to 1 then player will be hidden in refraction views, if set to 2 then player will also be hidden in reflection views, player is always visible in camera views"};
 
 cvar_t r_lerpsprites = {CVAR_CLIENT | CVAR_SAVE, "r_lerpsprites", "0", "enables animation smoothing on sprites"};
@@ -817,6 +818,7 @@ typedef struct r_glsl_permutation_s
        int loc_UserVec2;
        int loc_UserVec3;
        int loc_UserVec4;
+       int loc_ColorFringe;
        int loc_ViewTintColor;
        int loc_ViewToLight;
        int loc_ModelToLight;
@@ -1247,6 +1249,7 @@ static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode
                p->loc_UserVec2                   = qglGetUniformLocation(p->program, "UserVec2");
                p->loc_UserVec3                   = qglGetUniformLocation(p->program, "UserVec3");
                p->loc_UserVec4                   = qglGetUniformLocation(p->program, "UserVec4");
+               p->loc_ColorFringe                = qglGetUniformLocation(p->program, "ColorFringe");
                p->loc_ViewTintColor              = qglGetUniformLocation(p->program, "ViewTintColor");
                p->loc_ViewToLight                = qglGetUniformLocation(p->program, "ViewToLight");
                p->loc_ModelToLight               = qglGetUniformLocation(p->program, "ModelToLight");
@@ -1735,8 +1738,8 @@ void R_SetupShader_Surface(const float rtlightambient[3], const float rtlightdif
                        if (r_shadow_bouncegrid_state.directional)
                                permutation |= SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL;
                }
-               GL_BlendFunc(t->currentlayers[0].blendfunc1, t->currentlayers[0].blendfunc2);
-               blendfuncflags = R_BlendFuncFlags(t->currentlayers[0].blendfunc1, t->currentlayers[0].blendfunc2);
+               GL_BlendFunc(t->currentblendfunc[0], t->currentblendfunc[1]);
+               blendfuncflags = R_BlendFuncFlags(t->currentblendfunc[0], t->currentblendfunc[1]);
                // when using alphatocoverage, we don't need alphakill
                if (vid.allowalphatocoverage)
                {
@@ -1824,8 +1827,8 @@ void R_SetupShader_Surface(const float rtlightambient[3], const float rtlightdif
                        if (r_shadow_bouncegrid_state.directional)
                                permutation |= SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL;
                }
-               GL_BlendFunc(t->currentlayers[0].blendfunc1, t->currentlayers[0].blendfunc2);
-               blendfuncflags = R_BlendFuncFlags(t->currentlayers[0].blendfunc1, t->currentlayers[0].blendfunc2);
+               GL_BlendFunc(t->currentblendfunc[0], t->currentblendfunc[1]);
+               blendfuncflags = R_BlendFuncFlags(t->currentblendfunc[0], t->currentblendfunc[1]);
                // when using alphatocoverage, we don't need alphakill
                if (vid.allowalphatocoverage)
                {
@@ -3317,6 +3320,7 @@ void GL_Main_Init(void)
        Cvar_RegisterVariable(&r_lerplightstyles);
        Cvar_RegisterVariable(&r_waterscroll);
        Cvar_RegisterVariable(&r_bloom);
+       Cvar_RegisterVariable(&r_colorfringe);
        Cvar_RegisterVariable(&r_bloom_colorscale);
        Cvar_RegisterVariable(&r_bloom_brighten);
        Cvar_RegisterVariable(&r_bloom_blur);
@@ -5033,7 +5037,7 @@ finish:
 
 static void R_Bloom_StartFrame(void)
 {
-       int bloomtexturewidth, bloomtextureheight, screentexturewidth, screentextureheight;
+       int screentexturewidth, screentextureheight;
        int viewwidth, viewheight;
        textype_t textype = TEXTYPE_COLORBUFFER;
 
@@ -5083,8 +5087,6 @@ static void R_Bloom_StartFrame(void)
        // calculate desired texture sizes
        screentexturewidth = viewwidth;
        screentextureheight = viewheight;
-       bloomtexturewidth = r_fb.bloomwidth;
-       bloomtextureheight = r_fb.bloomheight;
 
        if ((r_bloom.integer || (!R_Stereo_Active() && (r_motionblur.value > 0 || r_damageblur.value > 0))) && ((r_bloom_resolution.integer < 4 || r_bloom_blur.value < 1 || r_bloom_blur.value >= 512) || r_refdef.view.width > (int)vid.maxtexturesize_2d || r_refdef.view.height > (int)vid.maxtexturesize_2d))
        {
@@ -5369,6 +5371,7 @@ static void R_BlendView(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *v
                if (r_glsl_permutation->loc_Saturation              >= 0) qglUniform1f(r_glsl_permutation->loc_Saturation        , r_glsl_saturation.value);
                if (r_glsl_permutation->loc_PixelToScreenTexCoord   >= 0) qglUniform2f(r_glsl_permutation->loc_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height);
                if (r_glsl_permutation->loc_BloomColorSubtract      >= 0) qglUniform4f(r_glsl_permutation->loc_BloomColorSubtract   , r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, r_bloom_colorsubtract.value, 0.0f);
+               if (r_glsl_permutation->loc_ColorFringe             >= 0) qglUniform1f(r_glsl_permutation->loc_ColorFringe, r_colorfringe.value );
                break;
        }
        R_Mesh_Draw(0, 4, 0, 2, polygonelement3i, NULL, 0, polygonelement3s, NULL, 0);
@@ -5793,7 +5796,6 @@ extern cvar_t cl_locs_show;
 static void R_DrawLocs(void);
 static void R_DrawEntityBBoxes(prvm_prog_t *prog);
 static void R_DrawModelDecals(void);
-extern cvar_t cl_decals_newsystem;
 extern qboolean r_shadow_usingdeferredprepass;
 extern int r_shadow_shadowmapatlas_modelshadows_size;
 void R_RenderScene(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewcolortexture, int viewx, int viewy, int viewwidth, int viewheight)
@@ -5920,18 +5922,9 @@ void R_RenderScene(int viewfbo, rtexture_t *viewdepthtexture, rtexture_t *viewco
 
        if (cl.csqc_vidvars.drawworld)
        {
-               if (cl_decals_newsystem.integer)
-               {
-                       R_DrawModelDecals();
-                       if (r_timereport_active)
-                               R_TimeReport("modeldecals");
-               }
-               else
-               {
-                       R_DrawDecals();
-                       if (r_timereport_active)
-                               R_TimeReport("decals");
-               }
+               R_DrawModelDecals();
+               if (r_timereport_active)
+                       R_TimeReport("modeldecals");
 
                R_DrawParticles();
                if (r_timereport_active)
@@ -6134,9 +6127,9 @@ static void R_DrawEntityBBoxes(prvm_prog_t *prog)
                if (edict->priv.server->free)
                        continue;
                // exclude the following for now, as they don't live in world coordinate space and can't be solid:
-               if (PRVM_serveredictedict(edict, tag_entity) != 0)
+               if (PRVM_gameedictedict(edict, tag_entity) != 0)
                        continue;
-               if (PRVM_serveredictedict(edict, viewmodelforclient) != 0)
+               if (prog == SVVM_prog && PRVM_serveredictedict(edict, viewmodelforclient) != 0)
                        continue;
                VectorLerp(edict->priv.server->areamins, 0.5f, edict->priv.server->areamaxs, center);
                R_MeshQueue_AddTransparent(TRANSPARENTSORT_DISTANCE, center, R_DrawEntityBBoxes_Callback, (entity_render_t *)NULL, i, (rtlight_t *)prog);
@@ -6396,22 +6389,6 @@ void R_Mesh_AddBrushMeshFromPlanes(rmesh_t *mesh, int numplanes, mplane_t *plane
        }
 }
 
-static void R_Texture_AddLayer(texture_t *t, qboolean depthmask, int blendfunc1, int blendfunc2, texturelayertype_t type, rtexture_t *texture, const matrix4x4_t *matrix, float r, float g, float b, float a)
-{
-       texturelayer_t *layer;
-       layer = t->currentlayers + t->currentnumlayers++;
-       layer->type = type;
-       layer->depthmask = depthmask;
-       layer->blendfunc1 = blendfunc1;
-       layer->blendfunc2 = blendfunc2;
-       layer->texture = texture;
-       layer->texmatrix = *matrix;
-       layer->color[0] = r;
-       layer->color[1] = g;
-       layer->color[2] = b;
-       layer->color[3] = a;
-}
-
 static qboolean R_TestQ3WaveFunc(q3wavefunc_t func, const float *parms)
 {
        if(parms[0] == 0 && parms[1] == 0)
@@ -6650,7 +6627,7 @@ texture_t *R_GetCurrentTexture(texture_t *t)
        if (t->currentmaterialflags & MATERIALFLAG_CUSTOMBLEND && !(R_BlendFuncFlags(t->customblendfunc[0], t->customblendfunc[1]) & BLENDFUNC_ALLOWS_COLORMOD))
        {
                // some CUSTOMBLEND blendfuncs are too weird, we have to ignore colormod and view colorscale
-               t->currentmaterialflags = t->currentmaterialflags | MATERIALFLAG_NORTLIGHT;
+               t->currentmaterialflags = t->currentmaterialflags | MATERIALFLAG_MODELLIGHT | MATERIALFLAG_NORTLIGHT;
                for (q = 0; q < 3; q++)
                {
                        t->render_glowmod[q] = rsurface.entity->glowmod[q];
@@ -6888,78 +6865,22 @@ texture_t *R_GetCurrentTexture(texture_t *t)
                }
        }
 
-       t->currentnumlayers = 0;
-       if (t->currentmaterialflags & MATERIALFLAG_WALL)
+       t->currentblendfunc[0] = GL_ONE;
+       t->currentblendfunc[1] = GL_ZERO;
+       if (t->currentmaterialflags & MATERIALFLAG_ADD)
        {
-               int blendfunc1, blendfunc2;
-               qboolean depthmask;
-               if (t->currentmaterialflags & MATERIALFLAG_ADD)
-               {
-                       blendfunc1 = GL_SRC_ALPHA;
-                       blendfunc2 = GL_ONE;
-               }
-               else if (t->currentmaterialflags & MATERIALFLAG_ALPHA)
-               {
-                       blendfunc1 = GL_SRC_ALPHA;
-                       blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
-               }
-               else if (t->currentmaterialflags & MATERIALFLAG_CUSTOMBLEND)
-               {
-                       blendfunc1 = t->customblendfunc[0];
-                       blendfunc2 = t->customblendfunc[1];
-               }
-               else
-               {
-                       blendfunc1 = GL_ONE;
-                       blendfunc2 = GL_ZERO;
-               }
-               depthmask = !(t->currentmaterialflags & MATERIALFLAG_BLENDED);
-               if (t->currentmaterialflags & MATERIALFLAG_MODELLIGHT)
-               {
-                       // basic lit geometry
-                       R_Texture_AddLayer(t, depthmask, blendfunc1, blendfunc2, TEXTURELAYERTYPE_LITTEXTURE, t->basetexture, &t->currenttexmatrix, 2, 2, 2, t->currentalpha);
-                       // add pants/shirt if needed
-                       if (VectorLength2(t->render_colormap_pants) >= (1.0f / 1048576.0f) && t->pantstexture)
-                               R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->pantstexture, &t->currenttexmatrix, 2 * t->render_colormap_pants[0], 2 * t->render_colormap_pants[1], 2 * t->render_colormap_pants[2], t->currentalpha);
-                       if (VectorLength2(t->render_colormap_shirt) >= (1.0f / 1048576.0f) && t->shirttexture)
-                               R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->shirttexture, &t->currenttexmatrix, 2 * t->render_colormap_shirt[0], 2 * t->render_colormap_shirt[1], 2 * t->render_colormap_shirt[2], t->currentalpha);
-               }
-               else
-               {
-                       // basic lit geometry
-                       R_Texture_AddLayer(t, depthmask, blendfunc1, blendfunc2, TEXTURELAYERTYPE_LITTEXTURE, t->basetexture, &t->currenttexmatrix, t->render_lightmap_diffuse[0], t->render_lightmap_diffuse[1], t->render_lightmap_diffuse[2], t->currentalpha);
-                       // add pants/shirt if needed
-                       if (VectorLength2(t->render_colormap_pants) >= (1.0f / 1048576.0f) && t->pantstexture)
-                               R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->pantstexture, &t->currenttexmatrix, t->render_colormap_pants[0] * t->render_lightmap_diffuse[0], t->render_colormap_pants[1] * t->render_lightmap_diffuse[1], t->render_colormap_pants[2]  * t->render_lightmap_diffuse[2], t->currentalpha);
-                       if (VectorLength2(t->render_colormap_shirt) >= (1.0f / 1048576.0f) && t->shirttexture)
-                               R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_LITTEXTURE, t->shirttexture, &t->currenttexmatrix, t->render_colormap_shirt[0] * t->render_lightmap_diffuse[0], t->render_colormap_shirt[1] * t->render_lightmap_diffuse[1], t->render_colormap_shirt[2] * t->render_lightmap_diffuse[2], t->currentalpha);
-                       // now add ambient passes if needed
-                       if (VectorLength2(t->render_lightmap_ambient) >= (1.0f/1048576.0f))
-                       {
-                               R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->basetexture, &t->currenttexmatrix, t->render_lightmap_ambient[0], t->render_lightmap_ambient[1], t->render_lightmap_ambient[2], t->currentalpha);
-                               if (VectorLength2(t->render_colormap_pants) >= (1.0f / 1048576.0f) && t->pantstexture)
-                                       R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->pantstexture, &t->currenttexmatrix, t->render_colormap_pants[0] * t->render_lightmap_ambient[0], t->render_colormap_pants[1] * t->render_lightmap_ambient[1], t->render_colormap_pants[2] * t->render_lightmap_ambient[2], t->currentalpha);
-                               if (VectorLength2(t->render_colormap_shirt) >= (1.0f / 1048576.0f) && t->shirttexture)
-                                       R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->shirttexture, &t->currenttexmatrix, t->render_colormap_shirt[0] * t->render_lightmap_ambient[0], t->render_colormap_shirt[1] * t->render_lightmap_ambient[1], t->render_colormap_shirt[2] * t->render_lightmap_ambient[2], t->currentalpha);
-                       }
-               }
-               if (t->glowtexture != NULL && !gl_lightmaps.integer)
-                       R_Texture_AddLayer(t, false, GL_SRC_ALPHA, GL_ONE, TEXTURELAYERTYPE_TEXTURE, t->glowtexture, &t->currenttexmatrix, t->render_glowmod[0], t->render_glowmod[1], t->render_glowmod[2], t->currentalpha);
-               if (r_refdef.fogenabled && !(t->currentmaterialflags & MATERIALFLAG_ADD))
-               {
-                       // if this is opaque use alpha blend which will darken the earlier
-                       // passes cheaply.
-                       //
-                       // if this is an alpha blended material, all the earlier passes
-                       // were darkened by fog already, so we only need to add the fog
-                       // color ontop through the fog mask texture
-                       //
-                       // if this is an additive blended material, all the earlier passes
-                       // were darkened by fog already, and we should not add fog color
-                       // (because the background was not darkened, there is no fog color
-                       // that was lost behind it).
-                       R_Texture_AddLayer(t, false, GL_SRC_ALPHA, (t->currentmaterialflags & MATERIALFLAG_BLENDED) ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA, TEXTURELAYERTYPE_FOG, t->fogtexture, &t->currenttexmatrix, r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2], t->currentalpha);
-               }
+               t->currentblendfunc[0] = GL_SRC_ALPHA;
+               t->currentblendfunc[1] = GL_ONE;
+       }
+       else if (t->currentmaterialflags & MATERIALFLAG_ALPHA)
+       {
+               t->currentblendfunc[0] = GL_SRC_ALPHA;
+               t->currentblendfunc[1] = GL_ONE_MINUS_SRC_ALPHA;
+       }
+       else if (t->currentmaterialflags & MATERIALFLAG_CUSTOMBLEND)
+       {
+               t->currentblendfunc[0] = t->customblendfunc[0];
+               t->currentblendfunc[1] = t->customblendfunc[1];
        }
 
        return t;
@@ -7195,6 +7116,24 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q
 void RSurf_ActiveCustomEntity(const matrix4x4_t *matrix, const matrix4x4_t *inversematrix, int entflags, double shadertime, float r, float g, float b, float a, int numvertices, const float *vertex3f, const float *texcoord2f, const float *normal3f, const float *svector3f, const float *tvector3f, const float *color4f, int numtriangles, const int *element3i, const unsigned short *element3s, qboolean wantnormals, qboolean wanttangents)
 {
        rsurface.entity = r_refdef.scene.worldentity;
+       if (r != 1.0f || g != 1.0f || b != 1.0f || a != 1.0f) {
+               // HACK to provide a valid entity with modded colors to R_GetCurrentTexture.
+               // A better approach could be making this copy only once per frame.
+               static entity_render_t custom_entity;
+               int q;
+               custom_entity = *rsurface.entity;
+               for (q = 0; q < 3; ++q) {
+                       float colormod = q == 0 ? r : q == 1 ? g : b;
+                       custom_entity.render_fullbright[q] *= colormod;
+                       custom_entity.render_modellight_ambient[q] *= colormod;
+                       custom_entity.render_modellight_diffuse[q] *= colormod;
+                       custom_entity.render_lightmap_ambient[q] *= colormod;
+                       custom_entity.render_lightmap_diffuse[q] *= colormod;
+                       custom_entity.render_rtlight_diffuse[q] *= colormod;
+               }
+               custom_entity.alpha *= a;
+               rsurface.entity = &custom_entity;
+       }
        rsurface.skeleton = NULL;
        rsurface.ent_skinnum = 0;
        rsurface.ent_qwskin = -1;
@@ -8966,7 +8905,7 @@ static void R_ProcessModelTextureSurfaceList(int texturenumsurfaces, const msurf
                R_DrawTextureSurfaceList_DepthOnly(texturenumsurfaces, texturesurfacelist);
        else if (prepass)
        {
-               if (!rsurface.texture->currentnumlayers)
+               if (!(rsurface.texture->currentmaterialflags & MATERIALFLAG_WALL))
                        return;
                if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
                        R_ProcessTransparentTextureSurfaceList(texturenumsurfaces, texturesurfacelist);
@@ -8975,7 +8914,7 @@ static void R_ProcessModelTextureSurfaceList(int texturenumsurfaces, const msurf
        }
        else if ((rsurface.texture->currentmaterialflags & MATERIALFLAG_SKY) && (!r_showsurfaces.integer || r_showsurfaces.integer == 3))
                R_DrawTextureSurfaceList_Sky(texturenumsurfaces, texturesurfacelist);
-       else if (!rsurface.texture->currentnumlayers)
+       else if (!(rsurface.texture->currentmaterialflags & MATERIALFLAG_WALL))
                return;
        else if (((rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED) || (r_showsurfaces.integer == 3 && (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST))))
        {
@@ -9461,9 +9400,6 @@ static void R_DecalSystem_ApplySplatEntities(const vec3_t worldorigin, const vec
        float worldmaxs[3];
        entity_render_t *ent;
 
-       if (!cl_decals_newsystem.integer)
-               return;
-
        worldmins[0] = worldorigin[0] - worldsize;
        worldmins[1] = worldorigin[1] - worldsize;
        worldmins[2] = worldorigin[2] - worldsize;
@@ -9501,7 +9437,7 @@ void R_DecalSystem_SplatEntities(const vec3_t worldorigin, const vec3_t worldnor
 {
        r_decalsystem_splatqueue_t *queue;
 
-       if (!cl_decals_newsystem.integer || r_decalsystem_numqueued == MAX_DECALSYSTEM_QUEUE)
+       if (r_decalsystem_numqueued == MAX_DECALSYSTEM_QUEUE)
                return;
 
        queue = &r_decalsystem_queue[r_decalsystem_numqueued++];
@@ -9745,7 +9681,7 @@ static void R_DrawModelDecals(void)
 
        r_refdef.stats[r_stat_totaldecals] += numdecals;
 
-       if (r_showsurfaces.integer)
+       if (r_showsurfaces.integer || !r_drawdecals.integer)
                return;
 
        R_DrawModelDecals_Entity(r_refdef.scene.worldentity);
@@ -9788,7 +9724,7 @@ static void R_DrawDebugModel(void)
                        {
                                RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_NOGAPS, 1, &surface);
                                GL_CullFace((rsurface.texture->currentmaterialflags & MATERIALFLAG_NOCULLFACE) ? GL_NONE : r_refdef.view.cullface_back);
-                               if (!rsurface.texture->currentlayers->depthmask)
+                               if ((rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED))
                                        GL_Color(c, 0, 0, 1.0f);
                                else if (ent == r_refdef.scene.worldentity)
                                        GL_Color(c, c, c, 1.0f);
@@ -9881,7 +9817,7 @@ static void R_DrawDebugModel(void)
                        if ((rsurface.texture->currentmaterialflags & flagsmask) && surface->num_triangles)
                        {
                                RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ARRAY_NORMAL | BATCHNEED_ARRAY_VECTOR | BATCHNEED_NOGAPS, 1, &surface);
-                               if (!rsurface.texture->currentlayers->depthmask)
+                               if ((rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED))
                                        GL_Color(r_refdef.view.colorscale, 0, 0, r_showtris.value);
                                else if (ent == r_refdef.scene.worldentity)
                                        GL_Color(r_refdef.view.colorscale, r_refdef.view.colorscale, r_refdef.view.colorscale, r_showtris.value);
@@ -10144,10 +10080,7 @@ void R_DebugLine(vec3_t start, vec3_t end)
 
 void R_DrawCustomSurface(skinframe_t *skinframe, const matrix4x4_t *texmatrix, int materialflags, int firstvertex, int numvertices, int firsttriangle, int numtriangles, qboolean writedepth, qboolean prepass, qboolean ui)
 {
-       int q;
        static texture_t texture;
-       static msurface_t surface;
-       const msurface_t *surfacelist = &surface;
 
        // fake enough texture and surface state to render this geometry
 
@@ -10161,36 +10094,8 @@ void R_DrawCustomSurface(skinframe_t *skinframe, const matrix4x4_t *texmatrix, i
        texture.specularscalemod = 1;
        texture.specularpowermod = 1;
        texture.transparentsort = TRANSPARENTSORT_DISTANCE;
-       // WHEN ADDING DEFAULTS HERE, REMEMBER TO PUT DEFAULTS IN ALL LOADERS
-       // JUST GREP FOR "specularscalemod = 1".
 
-       for (q = 0; q < 3; q++)
-       {
-               texture.render_glowmod[q] = r_refdef.view.colorscale * r_hdr_glowintensity.value;
-               texture.render_modellight_lightdir[q] = q == 2;
-               texture.render_modellight_ambient[q] = r_refdef.view.colorscale * r_refdef.scene.ambientintensity;
-               texture.render_modellight_diffuse[q] = r_refdef.view.colorscale;
-               texture.render_modellight_specular[q] = r_refdef.view.colorscale;
-               texture.render_lightmap_ambient[q] = r_refdef.view.colorscale * r_refdef.scene.ambientintensity;
-               texture.render_lightmap_diffuse[q] = r_refdef.view.colorscale * r_refdef.scene.lightmapintensity;
-               texture.render_lightmap_specular[q] = r_refdef.view.colorscale;
-               texture.render_rtlight_diffuse[q] = r_refdef.view.colorscale;
-               texture.render_rtlight_specular[q] = r_refdef.view.colorscale;
-       }
-       texture.currentalpha = 1.0f;
-
-       surface.texture = &texture;
-       surface.num_triangles = numtriangles;
-       surface.num_firsttriangle = firsttriangle;
-       surface.num_vertices = numvertices;
-       surface.num_firstvertex = firstvertex;
-
-       // now render it
-       rsurface.texture = R_GetCurrentTexture(surface.texture);
-       rsurface.lightmaptexture = NULL;
-       rsurface.deluxemaptexture = NULL;
-       rsurface.uselightmaptexture = false;
-       R_DrawModelTextureSurfaceList(1, &surfacelist, writedepth, prepass, ui);
+       R_DrawCustomSurface_Texture(&texture, texmatrix, materialflags, firstvertex, numvertices, firsttriangle, numtriangles, writedepth, prepass, ui);
 }
 
 void R_DrawCustomSurface_Texture(texture_t *texture, const matrix4x4_t *texmatrix, int materialflags, int firstvertex, int numvertices, int firsttriangle, int numtriangles, qboolean writedepth, qboolean prepass, qboolean ui)