some initial changes to support terrain texture blending someday
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 14 Feb 2007 21:09:55 +0000 (21:09 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 14 Feb 2007 21:09:55 +0000 (21:09 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6839 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
model_brush.c
model_brush.h
model_shared.h

index c4ecf91..dd4cfb3 100644 (file)
@@ -2620,6 +2620,8 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
        // pick a new currentskinframe if the material is animated
        if (t->numskinframes >= 2)
                t->currentskinframe = t->skinframes + ((int)(t->skinframerate * (cl.time - ent->frame2time)) % t->numskinframes);
+       if (t->backgroundnumskinframes >= 2)
+               t->backgroundcurrentskinframe = t->backgroundskinframes + ((int)(t->backgroundskinframerate * (cl.time - ent->frame2time)) % t->backgroundnumskinframes);
 
        t->currentmaterialflags = t->basematerialflags;
        t->currentalpha = ent->alpha;
@@ -2639,19 +2641,24 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
                t->currenttexmatrix = r_waterscrollmatrix;
        else
                t->currenttexmatrix = identitymatrix;
+       if (t->backgroundnumskinframes && !(t->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+               t->currentmaterialflags |= MATERIALFLAG_VERTEXTEXTUREBLEND;
 
        t->colormapping = VectorLength2(ent->colormap_pantscolor) + VectorLength2(ent->colormap_shirtcolor) >= (1.0f / 1048576.0f);
        t->basetexture = (!t->colormapping && t->currentskinframe->merged) ? t->currentskinframe->merged : t->currentskinframe->base;
        t->glosstexture = r_texture_white;
+       t->backgroundbasetexture = t->backgroundnumskinframes ? ((!t->colormapping && t->backgroundcurrentskinframe->merged) ? t->backgroundcurrentskinframe->merged : t->backgroundcurrentskinframe->base) : r_texture_white;
+       t->backgroundglosstexture = r_texture_white;
        t->specularpower = r_shadow_glossexponent.value;
        t->specularscale = 0;
        if (r_shadow_gloss.integer > 0)
        {
-               if (t->currentskinframe->gloss)
+               if (t->currentskinframe->gloss || (t->backgroundcurrentskinframe && t->backgroundcurrentskinframe->gloss))
                {
                        if (r_shadow_glossintensity.value > 0)
                        {
-                               t->glosstexture = t->currentskinframe->gloss;
+                               t->glosstexture = t->currentskinframe->gloss ? t->currentskinframe->gloss : r_texture_black;
+                               t->backgroundglosstexture = (t->backgroundcurrentskinframe && t->backgroundcurrentskinframe->gloss) ? t->backgroundcurrentskinframe->gloss : r_texture_black;
                                t->specularscale = r_shadow_glossintensity.value;
                        }
                }
@@ -3367,6 +3374,9 @@ static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, msurface_t **t
                        R_Mesh_TexBind(8, R_GetTexture(texturesurfacelist[0]->deluxemaptexture));
        }
        RSurf_DrawBatch_Simple(texturenumsurfaces, texturesurfacelist);
+       if (rsurface_texture->backgroundnumskinframes && !(rsurface_texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+       {
+       }
 }
 
 static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, msurface_t **texturesurfacelist)
index ff4b692..e7673ad 100644 (file)
@@ -1268,6 +1268,7 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                tx->skinframerate = 1;
                tx->currentskinframe = tx->skinframes;
                tx->skinframes[0].base = r_texture_notexture;
+               tx->backgroundcurrentskinframe = tx->backgroundskinframes;
                tx->basematerialflags = 0;
                if (i == loadmodel->num_textures - 1)
                {
@@ -4425,6 +4426,15 @@ Q3 shader blendfuncs actually used in the game (* = supported by DP)
                                        if (!Mod_LoadSkinFrame(&out->skinframes[j], shader->primarylayer->texturename[j], ((shader->surfaceparms & Q3SURFACEPARM_NOMIPMAPS) ? 0 : TEXF_MIPMAP) | TEXF_ALPHA | TEXF_PRECACHE | (shader->textureflags & Q3TEXTUREFLAG_NOPICMIP ? 0 : TEXF_PICMIP) | (shader->primarylayer->clampmap ? TEXF_CLAMP : 0), false, true))
                                                Con_Printf("%s: could not load texture \"%s\" (frame %i) for shader \"%s\"\n", loadmodel->name, shader->primarylayer->texturename[j], j, out->name);
                        }
+                       if (shader->backgroundlayer && cls.state != ca_dedicated)
+                       {
+                               int j;
+                               out->backgroundnumskinframes = shader->backgroundlayer->numframes;
+                               out->backgroundskinframerate = shader->backgroundlayer->framerate;
+                               for (j = 0;j < shader->backgroundlayer->numframes;j++)
+                                       if (!Mod_LoadSkinFrame(&out->backgroundskinframes[j], shader->backgroundlayer->texturename[j], ((shader->surfaceparms & Q3SURFACEPARM_NOMIPMAPS) ? 0 : TEXF_MIPMAP) | TEXF_ALPHA | TEXF_PRECACHE | (shader->textureflags & Q3TEXTUREFLAG_NOPICMIP ? 0 : TEXF_PICMIP) | (shader->backgroundlayer->clampmap ? TEXF_CLAMP : 0), false, true))
+                                               Con_Printf("%s: could not load texture \"%s\" (frame %i) for shader \"%s\"\n", loadmodel->name, shader->backgroundlayer->texturename[j], j, out->name);
+                       }
                }
                else
                {
@@ -4452,6 +4462,7 @@ Q3 shader blendfuncs actually used in the game (* = supported by DP)
                // init the animation variables
                out->currentframe = out;
                out->currentskinframe = &out->skinframes[0];
+               out->backgroundcurrentskinframe = &out->backgroundskinframes[0];
        }
        if (c)
                Con_DPrintf("%s: %i textures missing shaders\n", loadmodel->name, c);
index c5eb9f8..1b5b195 100644 (file)
@@ -95,6 +95,8 @@ mplane_t;
 #define MATERIALFLAG_CUSTOMBLEND 8192
 // do not cast shadows from this material
 #define MATERIALFLAG_NOSHADOW 16384
+// render using vertex alpha (q3bsp) as texture blend parameter between foreground (normal) skinframe and background skinframe
+#define MATERIALFLAG_VERTEXTEXTUREBLEND 32768
 
 typedef struct medge_s
 {
index 8b0af27..8a2deeb 100644 (file)
@@ -195,6 +195,11 @@ typedef struct texture_s
        int numskinframes;
        float skinframerate;
        skinframe_t skinframes[TEXTURE_MAXFRAMES];
+       // background layer (for terrain texture blending)
+       skinframe_t *backgroundcurrentskinframe;
+       int backgroundnumskinframes;
+       float backgroundskinframerate;
+       skinframe_t backgroundskinframes[TEXTURE_MAXFRAMES];
 
        // total frames in sequence and alternate sequence
        int anim_total[2];
@@ -215,6 +220,8 @@ typedef struct texture_s
        qboolean colormapping;
        rtexture_t *basetexture;
        rtexture_t *glosstexture;
+       rtexture_t *backgroundbasetexture;
+       rtexture_t *backgroundglosstexture;
        float specularscale;
        float specularpower;