MH Transparent Water Detection
Posted: Fri Aug 13, 2010 4:23 pm
Because r_wateralpha 0.5 looks really bad when the map isn't vised for transparent water.
Code: Select all
#define ISTELETEX(name) ((name)[0] == '*' && (name)[1] == 't' && (name)[2] == 'e' && (name)[3] == 'l' && (name)[4] == 'e')
/*
=================
Mod_DetectWaterTrans
detect if a model has been vised for translucent water
=================
*/
qboolean Mod_DetectWaterTrans (model_t *mod)
{
int i, j;
byte *vis;
mleaf_t *leaf;
msurface_t **surf;
// no visdata
if (!mod->visdata)
return true;
for (i = 0 ; i < mod->numleafs ; i++)
{
// leaf 0 is the solid leaf, leafs go to numleafs + 1
leaf = &mod->leafs[i+1];
// not interested in these leafs
if (leaf->contents >= CONTENTS_EMPTY || leaf->contents == CONTENTS_SOLID || leaf->contents == CONTENTS_SKY)
continue;
// check marksurfaces for a water texture
surf = leaf->firstmarksurface;
for (j = 0 ; j < leaf->nummarksurfaces ; j++, surf++)
{
// bad surf/texinfo/texture (some old maps have this from a bad qbsp)
if (!surf || !(*surf) || !(*surf)->texinfo || !(*surf)->texinfo->texture)
continue;
// not interested in teleports
if (!ISTELETEX((*surf)->texinfo->texture->name))
goto LeafOK;
}
// no water/etc textures here
continue;
LeafOK:
// get the decompressed vis
vis = Mod_DecompressVis (leaf->compressed_vis, mod);
// check the other leafs
for (j = 0 ; j < mod->numleafs ; j++)
{
// in the PVS
if (vis[j>>3] & (1 << (j & 7)))
{
mleaf_t *visleaf = &mod->leafs[j + 1];
// the leaf we hit originally was under water/slime/lava, and a
// leaf in it's pvs is above water/slime/lava.
if (visleaf->contents == CONTENTS_EMPTY)
return true;
}
}
}
// found nothing
return false;
}