]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_shared.c
turn "z value discarded" into VM_Warnings so one can backtrace them
[xonotic/darkplaces.git] / model_shared.c
index 0fc772824c4a23e4da119883ab14376c9a31c09c..653e0c8a723c510c45ec6efc5bfc734ed335153a 100644 (file)
@@ -228,17 +228,18 @@ void Mod_UnloadModel (dp_model_t *mod)
        mod->loaded = false;
 }
 
-void R_Model_Null_Draw(entity_render_t *ent)
+static void R_Model_Null_Draw(entity_render_t *ent)
 {
        return;
 }
 
 
-typedef void (*mod_framegroupify_parsegroups_t) (unsigned int i, int start, int len, float fps, qboolean loop, void *pass);
+typedef void (*mod_framegroupify_parsegroups_t) (unsigned int i, int start, int len, float fps, qboolean loop, const char *name, void *pass);
 
-int Mod_FrameGroupify_ParseGroups(const char *buf, mod_framegroupify_parsegroups_t cb, void *pass)
+static int Mod_FrameGroupify_ParseGroups(const char *buf, mod_framegroupify_parsegroups_t cb, void *pass)
 {
        const char *bufptr;
+       const char *name;
        int start, len;
        float fps;
        unsigned int i;
@@ -249,12 +250,12 @@ int Mod_FrameGroupify_ParseGroups(const char *buf, mod_framegroupify_parsegroups
        for(;;)
        {
                // an anim scene!
-               if (!COM_ParseToken_Simple(&bufptr, true, false))
+               if (!COM_ParseToken_Simple(&bufptr, true, false, false))
                        break;
                if (!strcmp(com_token, "\n"))
                        continue; // empty line
                start = atoi(com_token);
-               if (!COM_ParseToken_Simple(&bufptr, true, false))
+               if (!COM_ParseToken_Simple(&bufptr, true, false, false))
                        break;
                if (!strcmp(com_token, "\n"))
                {
@@ -262,15 +263,15 @@ int Mod_FrameGroupify_ParseGroups(const char *buf, mod_framegroupify_parsegroups
                        continue;
                }
                len = atoi(com_token);
-               if (!COM_ParseToken_Simple(&bufptr, true, false))
+               if (!COM_ParseToken_Simple(&bufptr, true, false, false))
                        break;
                // we default to looping as it's usually wanted, so to NOT loop you append a 0
-               if (strcmp(com_token, "\n"))
+               if (strcmp(com_token, "\n") && strcmp(com_token, "//"))
                {
                        fps = atof(com_token);
-                       if (!COM_ParseToken_Simple(&bufptr, true, false))
+                       if (!COM_ParseToken_Simple(&bufptr, true, false, false))
                                break;
-                       if (strcmp(com_token, "\n"))
+                       if (strcmp(com_token, "\n") && strcmp(com_token, "//"))
                                loop = atoi(com_token) != 0;
                        else
                                loop = true;
@@ -281,25 +282,37 @@ int Mod_FrameGroupify_ParseGroups(const char *buf, mod_framegroupify_parsegroups
                        loop = true;
                }
 
+               name = NULL;
+               if(!strcmp(com_token, "//"))
+               {
+                       if (COM_ParseToken_Simple(&bufptr, true, false, false))
+                       {
+                               if(strcmp(com_token, "\n"))
+                               {
+                                       name = com_token;
+                                       // skip to EOL
+                                       while (*bufptr && *bufptr != '\n' && *bufptr != '\r')
+                                               bufptr++;
+                               }
+                       }
+               }
+
                if(cb)
-                       cb(i, start, len, fps, loop, pass);
+                       cb(i, start, len, fps, loop, name, pass);
                ++i;
        }
 
        return i;
 }
 
-void Mod_FrameGroupify_ParseGroups_Count (unsigned int i, int start, int len, float fps, qboolean loop, void *pass)
-{
-       unsigned int *cnt = (unsigned int *) pass;
-       ++*cnt;
-}
-
-void Mod_FrameGroupify_ParseGroups_Store (unsigned int i, int start, int len, float fps, qboolean loop, void *pass)
+static void Mod_FrameGroupify_ParseGroups_Store (unsigned int i, int start, int len, float fps, qboolean loop, const char *name, void *pass)
 {
        dp_model_t *mod = (dp_model_t *) pass;
        animscene_t *anim = &mod->animscenes[i];
-       dpsnprintf(anim->name, sizeof(anim[i].name), "groupified_%d_anim", i);
+       if(name)
+               strlcpy(anim->name, name, sizeof(anim[i].name));
+       else
+               dpsnprintf(anim->name, sizeof(anim[i].name), "groupified_%d_anim", i);
        anim->firstframe = bound(0, start, mod->num_poses - 1);
        anim->framecount = bound(1, len, mod->num_poses - anim->firstframe);
        anim->framerate = max(1, fps);
@@ -307,7 +320,7 @@ void Mod_FrameGroupify_ParseGroups_Store (unsigned int i, int start, int len, fl
        //Con_Printf("frame group %d is %d %d %f %d\n", i, start, len, fps, loop);
 }
 
-void Mod_FrameGroupify(dp_model_t *mod, const char *buf)
+static void Mod_FrameGroupify(dp_model_t *mod, const char *buf)
 {
        unsigned int cnt;
 
@@ -328,7 +341,7 @@ void Mod_FrameGroupify(dp_model_t *mod, const char *buf)
        Mod_FrameGroupify_ParseGroups(buf, Mod_FrameGroupify_ParseGroups_Store, mod);
 }
 
-void Mod_FindPotentialDeforms(dp_model_t *mod)
+static void Mod_FindPotentialDeforms(dp_model_t *mod)
 {
        int i, j;
        texture_t *texture;
@@ -366,6 +379,7 @@ dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk)
        unsigned int crc;
        void *buf;
        fs_offset_t filesize = 0;
+       char vabuf[1024];
 
        mod->used = true;
 
@@ -491,8 +505,8 @@ dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk)
                Mem_Free(buf);
 
                Mod_FindPotentialDeforms(mod);
-                                       
-               buf = FS_LoadFile (va("%s.framegroups", mod->name), tempmempool, false, &filesize);
+
+               buf = FS_LoadFile(va(vabuf, sizeof(vabuf), "%s.framegroups", mod->name), tempmempool, false, &filesize);
                if(buf)
                {
                        Mod_FrameGroupify(mod, (const char *)buf);
@@ -856,7 +870,8 @@ void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const
                VectorNormalize(vectorNormal);
 }
 
-void Mod_BuildBumpVectors(const float *v0, const float *v1, const float *v2, const float *tc0, const float *tc1, const float *tc2, float *svector3f, float *tvector3f, float *normal3f)
+#if 0
+static void Mod_BuildBumpVectors(const float *v0, const float *v1, const float *v2, const float *tc0, const float *tc1, const float *tc2, float *svector3f, float *tvector3f, float *normal3f)
 {
        float f, tangentcross[3], v10[3], v20[3], tc10[2], tc20[2];
        // 79 add/sub/negate/multiply (1 cycle), 1 compare (3 cycle?), total cycles not counting load/store/exchange roughly 82 cycles
@@ -899,6 +914,7 @@ void Mod_BuildBumpVectors(const float *v0, const float *v1, const float *v2, con
                VectorNegate(tvector3f, tvector3f);
        }
 }
+#endif
 
 // warning: this is a very expensive function!
 void Mod_BuildTextureVectorsFromNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const float *texcoord2f, const float *normal3f, const int *elements, float *svector3f, float *tvector3f, qboolean areaweighting)
@@ -1394,7 +1410,8 @@ void Mod_CreateCollisionMesh(dp_model_t *mod)
        mod->brush.collisionmesh = Mod_ShadowMesh_Finish(mempool, mod->brush.collisionmesh, false, false, false);
 }
 
-void Mod_GetTerrainVertex3fTexCoord2fFromBGRA(const unsigned char *imagepixels, int imagewidth, int imageheight, int ix, int iy, float *vertex3f, float *texcoord2f, matrix4x4_t *pixelstepmatrix, matrix4x4_t *pixeltexturestepmatrix)
+#if 0
+static void Mod_GetTerrainVertex3fTexCoord2fFromBGRA(const unsigned char *imagepixels, int imagewidth, int imageheight, int ix, int iy, float *vertex3f, float *texcoord2f, matrix4x4_t *pixelstepmatrix, matrix4x4_t *pixeltexturestepmatrix)
 {
        float v[3], tc[3];
        v[0] = ix;
@@ -1409,7 +1426,7 @@ void Mod_GetTerrainVertex3fTexCoord2fFromBGRA(const unsigned char *imagepixels,
        texcoord2f[1] = tc[1];
 }
 
-void Mod_GetTerrainVertexFromBGRA(const unsigned char *imagepixels, int imagewidth, int imageheight, int ix, int iy, float *vertex3f, float *svector3f, float *tvector3f, float *normal3f, float *texcoord2f, matrix4x4_t *pixelstepmatrix, matrix4x4_t *pixeltexturestepmatrix)
+static void Mod_GetTerrainVertexFromBGRA(const unsigned char *imagepixels, int imagewidth, int imageheight, int ix, int iy, float *vertex3f, float *svector3f, float *tvector3f, float *normal3f, float *texcoord2f, matrix4x4_t *pixelstepmatrix, matrix4x4_t *pixeltexturestepmatrix)
 {
        float vup[3], vdown[3], vleft[3], vright[3];
        float tcup[3], tcdown[3], tcleft[3], tcright[3];
@@ -1434,7 +1451,7 @@ void Mod_GetTerrainVertexFromBGRA(const unsigned char *imagepixels, int imagewid
        VectorAdd(normal3f, nl, normal3f);
 }
 
-void Mod_ConstructTerrainPatchFromBGRA(const unsigned char *imagepixels, int imagewidth, int imageheight, int x1, int y1, int width, int height, int *element3i, int *neighbor3i, float *vertex3f, float *svector3f, float *tvector3f, float *normal3f, float *texcoord2f, matrix4x4_t *pixelstepmatrix, matrix4x4_t *pixeltexturestepmatrix)
+static void Mod_ConstructTerrainPatchFromBGRA(const unsigned char *imagepixels, int imagewidth, int imageheight, int x1, int y1, int width, int height, int *element3i, int *neighbor3i, float *vertex3f, float *svector3f, float *tvector3f, float *normal3f, float *texcoord2f, matrix4x4_t *pixelstepmatrix, matrix4x4_t *pixeltexturestepmatrix)
 {
        int x, y, ix, iy, *e;
        e = element3i;
@@ -1456,6 +1473,7 @@ void Mod_ConstructTerrainPatchFromBGRA(const unsigned char *imagepixels, int ima
                for (x = 0, ix = x1;x < width + 1;x++, ix++, vertex3f += 3, texcoord2f += 2, svector3f += 3, tvector3f += 3, normal3f += 3)
                        Mod_GetTerrainVertexFromBGRA(imagepixels, imagewidth, imageheight, ix, iy, vertex3f, texcoord2f, svector3f, tvector3f, normal3f, pixelstepmatrix, pixeltexturestepmatrix);
 }
+#endif
 
 #if 0
 void Mod_Terrain_SurfaceRecurseChunk(dp_model_t *model, int stepsize, int x, int y)
@@ -1537,7 +1555,7 @@ void Mod_Terrain_UpdateSurfacesForViewOrigin(dp_model_t *model)
 }
 #endif
 
-int Mod_LoadQ3Shaders_EnumerateWaveFunc(const char *s)
+static int Mod_LoadQ3Shaders_EnumerateWaveFunc(const char *s)
 {
        int offset = 0;
        if (!strncasecmp(s, "user", 4)) // parse stuff like "user1sin", always user<n>func
@@ -1573,15 +1591,31 @@ static void Q3Shader_AddToHash (q3shaderinfo_t* shader)
        {
                if (strcasecmp (entry->shader.name, shader->name) == 0)
                {
-                       unsigned char *start, *end, *start2;
-                       start = (unsigned char *) (&shader->Q3SHADERINFO_COMPARE_START);
-                       end = ((unsigned char *) (&shader->Q3SHADERINFO_COMPARE_END)) + sizeof(shader->Q3SHADERINFO_COMPARE_END);
-                       start2 = (unsigned char *) (&entry->shader.Q3SHADERINFO_COMPARE_START);
-                       if(memcmp(start, start2, end - start))
-                               Con_DPrintf("Shader '%s' already defined, ignoring mismatching redeclaration\n", shader->name);
+                       // redeclaration
+                       if(shader->dpshaderkill)
+                       {
+                               // killed shader is a redeclarion? we can safely ignore it
+                               return;
+                       }
+                       else if(entry->shader.dpshaderkill)
+                       {
+                               // replace the old shader!
+                               // this will skip the entry allocating part
+                               // below and just replace the shader
+                               break;
+                       }
                        else
-                               Con_DPrintf("Shader '%s' already defined\n", shader->name);
-                       return;
+                       {
+                               unsigned char *start, *end, *start2;
+                               start = (unsigned char *) (&shader->Q3SHADERINFO_COMPARE_START);
+                               end = ((unsigned char *) (&shader->Q3SHADERINFO_COMPARE_END)) + sizeof(shader->Q3SHADERINFO_COMPARE_END);
+                               start2 = (unsigned char *) (&entry->shader.Q3SHADERINFO_COMPARE_START);
+                               if(memcmp(start, start2, end - start))
+                                       Con_DPrintf("Shader '%s' already defined, ignoring mismatching redeclaration\n", shader->name);
+                               else
+                                       Con_DPrintf("Shader '%s' already defined\n", shader->name);
+                               return;
+                       }
                }
                lastEntry = entry;
                entry = entry->chain;
@@ -1607,8 +1641,11 @@ static void Q3Shader_AddToHash (q3shaderinfo_t* shader)
 
 extern cvar_t mod_noshader_default_offsetmapping;
 extern cvar_t mod_q3shader_default_offsetmapping;
+extern cvar_t mod_q3shader_default_offsetmapping_scale;
+extern cvar_t mod_q3shader_default_offsetmapping_bias;
 extern cvar_t mod_q3shader_default_polygonoffset;
 extern cvar_t mod_q3shader_default_polygonfactor;
+extern cvar_t mod_q3shader_force_addalpha;
 void Mod_LoadQ3Shaders(void)
 {
        int j;
@@ -1623,6 +1660,7 @@ void Mod_LoadQ3Shaders(void)
        char *custsurfaceparmnames[256]; // VorteX: q3map2 has 64 but well, someone will need more
        unsigned long custsurfaceparms[256]; 
        int numcustsurfaceparms;
+       qboolean dpshaderkill;
 
        Mod_FreeQ3Shaders();
 
@@ -1696,7 +1734,8 @@ void Mod_LoadQ3Shaders(void)
                        Vector4Set(shader.reflectcolor4f, 1, 1, 1, 1);
                        shader.r_water_wateralpha = 1;
                        shader.offsetmapping = (mod_q3shader_default_offsetmapping.value) ? OFFSETMAPPING_DEFAULT : OFFSETMAPPING_OFF;
-                       shader.offsetscale = 1;
+                       shader.offsetscale = mod_q3shader_default_offsetmapping_scale.value;
+                       shader.offsetbias = mod_q3shader_default_offsetmapping_bias.value;
                        shader.specularscalemod = 1;
                        shader.specularpowermod = 1;
                        shader.biaspolygonoffset = mod_q3shader_default_polygonoffset.value;
@@ -1769,6 +1808,11 @@ void Mod_LoadQ3Shaders(void)
                                                                        layer->blendfunc[0] = GL_ONE;
                                                                        layer->blendfunc[1] = GL_ONE;
                                                                }
+                                                               else if (!strcasecmp(parameter[1], "addalpha"))
+                                                               {
+                                                                       layer->blendfunc[0] = GL_SRC_ALPHA;
+                                                                       layer->blendfunc[1] = GL_ONE;
+                                                               }
                                                                else if (!strcasecmp(parameter[1], "filter"))
                                                                {
                                                                        layer->blendfunc[0] = GL_DST_COLOR;
@@ -1796,7 +1840,7 @@ void Mod_LoadQ3Shaders(void)
                                                                        else if (!strcasecmp(parameter[k+1], "GL_DST_COLOR"))
                                                                                layer->blendfunc[k] = GL_DST_COLOR;
                                                                        else if (!strcasecmp(parameter[k+1], "GL_DST_ALPHA"))
-                                                                               layer->blendfunc[k] = GL_ONE_MINUS_DST_ALPHA;
+                                                                               layer->blendfunc[k] = GL_DST_ALPHA;
                                                                        else if (!strcasecmp(parameter[k+1], "GL_ONE_MINUS_SRC_COLOR"))
                                                                                layer->blendfunc[k] = GL_ONE_MINUS_SRC_COLOR;
                                                                        else if (!strcasecmp(parameter[k+1], "GL_ONE_MINUS_SRC_ALPHA"))
@@ -1950,7 +1994,32 @@ void Mod_LoadQ3Shaders(void)
                                                        shader.textureblendalpha = true;
                                                }
                                        }
-                                       layer->texflags = TEXF_ALPHA;
+
+                                       if(mod_q3shader_force_addalpha.integer)
+                                       {
+                                               // for a long while, DP treated GL_ONE GL_ONE as GL_SRC_ALPHA GL_ONE
+                                               // this cvar brings back this behaviour
+                                               if(layer->blendfunc[0] == GL_ONE && layer->blendfunc[1] == GL_ONE)
+                                                       layer->blendfunc[0] = GL_SRC_ALPHA;
+                                       }
+
+                                       layer->texflags = 0;
+                                       if (layer->alphatest)
+                                               layer->texflags |= TEXF_ALPHA;
+                                       switch(layer->blendfunc[0])
+                                       {
+                                               case GL_SRC_ALPHA:
+                                               case GL_ONE_MINUS_SRC_ALPHA:
+                                                       layer->texflags |= TEXF_ALPHA;
+                                                       break;
+                                       }
+                                       switch(layer->blendfunc[1])
+                                       {
+                                               case GL_SRC_ALPHA:
+                                               case GL_ONE_MINUS_SRC_ALPHA:
+                                                       layer->texflags |= TEXF_ALPHA;
+                                                       break;
+                                       }
                                        if (!(shader.surfaceparms & Q3SURFACEPARM_NOMIPMAPS))
                                                layer->texflags |= TEXF_MIPMAP;
                                        if (!(shader.textureflags & Q3TEXTUREFLAG_NOPICMIP))
@@ -2079,6 +2148,58 @@ void Mod_LoadQ3Shaders(void)
                                        strlcpy(shader.dpreflectcube, parameter[1], sizeof(shader.dpreflectcube));
                                else if (!strcasecmp(parameter[0], "dpmeshcollisions"))
                                        shader.dpmeshcollisions = true;
+                               // this sets dpshaderkill to true if dpshaderkillifcvarzero was used, and to false if dpnoshaderkillifcvarzero was used
+                               else if (((dpshaderkill = !strcasecmp(parameter[0], "dpshaderkillifcvarzero")) || !strcasecmp(parameter[0], "dpnoshaderkillifcvarzero")) && numparameters >= 2)
+                               {
+                                       if (Cvar_VariableValue(parameter[1]) == 0.0f)
+                                               shader.dpshaderkill = dpshaderkill;
+                               }
+                               // this sets dpshaderkill to true if dpshaderkillifcvar was used, and to false if dpnoshaderkillifcvar was used
+                               else if (((dpshaderkill = !strcasecmp(parameter[0], "dpshaderkillifcvar")) || !strcasecmp(parameter[0], "dpnoshaderkillifcvar")) && numparameters >= 2)
+                               {
+                                       const char *op = NULL;
+                                       if (numparameters >= 3)
+                                               op = parameter[2];
+                                       if(!op)
+                                       {
+                                               if (Cvar_VariableValue(parameter[1]) != 0.0f)
+                                                       shader.dpshaderkill = dpshaderkill;
+                                       }
+                                       else if (numparameters >= 4 && !strcmp(op, "=="))
+                                       {
+                                               if (Cvar_VariableValue(parameter[1]) == atof(parameter[3]))
+                                                       shader.dpshaderkill = dpshaderkill;
+                                       }
+                                       else if (numparameters >= 4 && !strcmp(op, "!="))
+                                       {
+                                               if (Cvar_VariableValue(parameter[1]) != atof(parameter[3]))
+                                                       shader.dpshaderkill = dpshaderkill;
+                                       }
+                                       else if (numparameters >= 4 && !strcmp(op, ">"))
+                                       {
+                                               if (Cvar_VariableValue(parameter[1]) > atof(parameter[3]))
+                                                       shader.dpshaderkill = dpshaderkill;
+                                       }
+                                       else if (numparameters >= 4 && !strcmp(op, "<"))
+                                       {
+                                               if (Cvar_VariableValue(parameter[1]) < atof(parameter[3]))
+                                                       shader.dpshaderkill = dpshaderkill;
+                                       }
+                                       else if (numparameters >= 4 && !strcmp(op, ">="))
+                                       {
+                                               if (Cvar_VariableValue(parameter[1]) >= atof(parameter[3]))
+                                                       shader.dpshaderkill = dpshaderkill;
+                                       }
+                                       else if (numparameters >= 4 && !strcmp(op, "<="))
+                                       {
+                                               if (Cvar_VariableValue(parameter[1]) <= atof(parameter[3]))
+                                                       shader.dpshaderkill = dpshaderkill;
+                                       }
+                                       else
+                                       {
+                                               Con_DPrintf("%s parsing warning: unknown dpshaderkillifcvar op \"%s\", or not enough arguments\n", search->filenames[fileindex], op);
+                                       }
+                               }
                                else if (!strcasecmp(parameter[0], "sky") && numparameters >= 2)
                                {
                                        // some q3 skies don't have the sky parm set
@@ -2159,17 +2280,29 @@ void Mod_LoadQ3Shaders(void)
                                {
                                        shader.rtlightambient = atof(parameter[1]);
                                }
-                               else if (!strcasecmp(parameter[0], "dpoffsetmapping") && numparameters >= 3)
+                               else if (!strcasecmp(parameter[0], "dpoffsetmapping") && numparameters >= 2)
                                {
                                        if (!strcasecmp(parameter[1], "disable") || !strcasecmp(parameter[1], "none") || !strcasecmp(parameter[1], "off"))
                                                shader.offsetmapping = OFFSETMAPPING_OFF;
-                                       else if (!strcasecmp(parameter[1], "default"))
+                                       else if (!strcasecmp(parameter[1], "default") || !strcasecmp(parameter[1], "normal"))
                                                shader.offsetmapping = OFFSETMAPPING_DEFAULT;
                                        else if (!strcasecmp(parameter[1], "linear"))
                                                shader.offsetmapping = OFFSETMAPPING_LINEAR;
                                        else if (!strcasecmp(parameter[1], "relief"))
                                                shader.offsetmapping = OFFSETMAPPING_RELIEF;
-                                       shader.offsetscale = atof(parameter[2]);
+                                       if (numparameters >= 3)
+                                               shader.offsetscale = atof(parameter[2]);
+                                       if (numparameters >= 5)
+                                       {
+                                               if(!strcasecmp(parameter[3], "bias"))
+                                                       shader.offsetbias = atof(parameter[4]);
+                                               else if(!strcasecmp(parameter[3], "match"))
+                                                       shader.offsetbias = 1.0f - atof(parameter[4]);
+                                               else if(!strcasecmp(parameter[3], "match8"))
+                                                       shader.offsetbias = 1.0f - atof(parameter[4]) / 255.0f;
+                                               else if(!strcasecmp(parameter[3], "match16"))
+                                                       shader.offsetbias = 1.0f - atof(parameter[4]) / 65535.0f;
+                                       }
                                }
                                else if (!strcasecmp(parameter[0], "deformvertexes") && numparameters >= 2)
                                {
@@ -2211,6 +2344,9 @@ void Mod_LoadQ3Shaders(void)
                                        }
                                }
                        }
+                       // hide this shader if a cvar said it should be killed
+                       if (shader.dpshaderkill)
+                               shader.numlayers = 0;
                        // pick the primary layer to render with
                        if (shader.numlayers)
                        {
@@ -2290,8 +2426,10 @@ qboolean Mod_LoadTextureFromQ3Shader(texture_t *texture, const char *name, qbool
        // unless later loaded from the shader
        texture->offsetmapping = (mod_noshader_default_offsetmapping.value) ? OFFSETMAPPING_DEFAULT : OFFSETMAPPING_OFF;
        texture->offsetscale = 1;
+       texture->offsetbias = 0;
        texture->specularscalemod = 1;
        texture->specularpowermod = 1; 
+       texture->rtlightambient = 0;
        // WHEN ADDING DEFAULTS HERE, REMEMBER TO SYNC TO SHADER LOADING ABOVE
        // HERE, AND Q1BSP LOADING
        // JUST GREP FOR "specularscalemod = 1".
@@ -2439,6 +2577,7 @@ nothing                GL_ZERO GL_ONE
                Vector2Copy(shader->r_water_waterscroll, texture->r_water_waterscroll);
                texture->offsetmapping = shader->offsetmapping;
                texture->offsetscale = shader->offsetscale;
+               texture->offsetbias = shader->offsetbias;
                texture->specularscalemod = shader->specularscalemod;
                texture->specularpowermod = shader->specularpowermod;
                texture->rtlightambient = shader->rtlightambient;
@@ -2490,6 +2629,8 @@ nothing                GL_ZERO GL_ONE
 
                if (shader->dpmeshcollisions)
                        texture->basematerialflags |= MATERIALFLAG_MESHCOLLISIONS;
+               if (shader->dpshaderkill && developer_extra.integer)
+                       Con_DPrintf("^1%s:^7 killing shader ^3\"%s\" because of cvar\n", loadmodel->name, name);
        }
        else if (!strcmp(texture->name, "noshader") || !texture->name[0])
        {
@@ -2569,6 +2710,7 @@ skinfile_t *Mod_LoadSkinFiles(void)
        skinfile_t *skinfile = NULL, *first = NULL;
        skinfileitem_t *skinfileitem;
        char word[10][MAX_QPATH];
+       char vabuf[1024];
 
 /*
 sample file:
@@ -2586,7 +2728,7 @@ tag_weapon,
 tag_torso,
 */
        memset(word, 0, sizeof(word));
-       for (i = 0;i < 256 && (data = text = (char *)FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), tempmempool, true, NULL));i++)
+       for (i = 0;i < 256 && (data = text = (char *)FS_LoadFile(va(vabuf, sizeof(vabuf), "%s_%i.skin", loadmodel->name, i), tempmempool, true, NULL));i++)
        {
                // If it's the first file we parse
                if (skinfile == NULL)
@@ -3157,6 +3299,7 @@ static void Mod_Decompile_f(void)
        int zymtextsize = 0;
        int dpmtextsize = 0;
        int framegroupstextsize = 0;
+       char vabuf[1024];
 
        if (Cmd_Argc() != 2)
        {
@@ -3263,11 +3406,11 @@ static void Mod_Decompile_f(void)
                        }
                }
                if (zymtextsize)
-                       FS_WriteFile(va("%s_decompiled/out_zym.txt", basename), zymtextbuffer, (fs_offset_t)zymtextsize);
+                       FS_WriteFile(va(vabuf, sizeof(vabuf), "%s_decompiled/out_zym.txt", basename), zymtextbuffer, (fs_offset_t)zymtextsize);
                if (dpmtextsize)
-                       FS_WriteFile(va("%s_decompiled/out_dpm.txt", basename), dpmtextbuffer, (fs_offset_t)dpmtextsize);
+                       FS_WriteFile(va(vabuf, sizeof(vabuf), "%s_decompiled/out_dpm.txt", basename), dpmtextbuffer, (fs_offset_t)dpmtextsize);
                if (framegroupstextsize)
-                       FS_WriteFile(va("%s_decompiled.framegroups", basename), framegroupstextbuffer, (fs_offset_t)framegroupstextsize);
+                       FS_WriteFile(va(vabuf, sizeof(vabuf), "%s_decompiled.framegroups", basename), framegroupstextbuffer, (fs_offset_t)framegroupstextsize);
        }
 }
 
@@ -3401,7 +3544,6 @@ static float mod_generatelightmaps_offsets[3][MAX_LIGHTMAPSAMPLES][3];
 static int mod_generatelightmaps_numlights;
 static lightmaplight_t *mod_generatelightmaps_lightinfo;
 
-extern int R_Shadow_GetRTLightInfo(unsigned int lightindex, float *origin, float *radius, float *color);
 extern cvar_t r_shadow_lightattenuationdividebias;
 extern cvar_t r_shadow_lightattenuationlinearscale;
 
@@ -3982,6 +4124,7 @@ static void Mod_GenerateLightmaps_CreateLightmaps(dp_model_t *model)
        unsigned char *lightmappixels;
        unsigned char *deluxemappixels;
        mod_alloclightmap_state_t lmstate;
+       char vabuf[1024];
 
        // generate lightmap projection information for all triangles
        if (model->texturepool == NULL)
@@ -4164,8 +4307,8 @@ static void Mod_GenerateLightmaps_CreateLightmaps(dp_model_t *model)
 
        for (lightmapindex = 0;lightmapindex < model->brushq3.num_mergedlightmaps;lightmapindex++)
        {
-               model->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(model->texturepool, va("lightmap%i", lightmapindex), lm_texturesize, lm_texturesize, lightmappixels + lightmapindex * lm_texturesize * lm_texturesize * 4, TEXTYPE_BGRA, TEXF_FORCELINEAR, -1, NULL);
-               model->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(model->texturepool, va("deluxemap%i", lightmapindex), lm_texturesize, lm_texturesize, deluxemappixels + lightmapindex * lm_texturesize * lm_texturesize * 4, TEXTYPE_BGRA, TEXF_FORCELINEAR, -1, NULL);
+               model->brushq3.data_lightmaps[lightmapindex] = R_LoadTexture2D(model->texturepool, va(vabuf, sizeof(vabuf), "lightmap%i", lightmapindex), lm_texturesize, lm_texturesize, lightmappixels + lightmapindex * lm_texturesize * lm_texturesize * 4, TEXTYPE_BGRA, TEXF_FORCELINEAR, -1, NULL);
+               model->brushq3.data_deluxemaps[lightmapindex] = R_LoadTexture2D(model->texturepool, va(vabuf, sizeof(vabuf), "deluxemap%i", lightmapindex), lm_texturesize, lm_texturesize, deluxemappixels + lightmapindex * lm_texturesize * lm_texturesize * 4, TEXTYPE_BGRA, TEXF_FORCELINEAR, -1, NULL);
        }
 
        if (lightmappixels)