View previous topic :: View next topic |
Author |
Message |
Baker

Joined: 14 Mar 2006 Posts: 1538
|
Posted: Fri Aug 13, 2010 4:23 pm Post subject: MH Transparent Water Detection |
|
|
Because r_wateralpha 0.5 looks really bad when the map isn't vised for transparent water.
Code: | #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;
} |
_________________ Tomorrow Never Dies. I feel this Tomorrow knocking on the door ... |
|
Back to top |
|
 |
mh

Joined: 12 Jan 2008 Posts: 909
|
|
Back to top |
|
 |
metlslime
Joined: 05 Feb 2008 Posts: 177
|
Posted: Sat Aug 14, 2010 2:30 am Post subject: |
|
|
kinda seems over-complicated to look at textures.... if any water/slime/lava leaf can see any empty leaf, surely that is sufficient? |
|
Back to top |
|
 |
Spike
Joined: 05 Nov 2004 Posts: 944 Location: UK
|
Posted: Sat Aug 14, 2010 3:13 am Post subject: |
|
|
consider: cube in the middle of nowhere. its water, it has no access to any air at all. it does not connect to empty, thus the not water-vised. To fix that you would have to scan every single water leaf's pvs in order to ensure that you don't get a false negative. And that's painful.
Doing it only for leafs that have a water surface will result in better scaling, naming no names some maps can be rather large, and any routine that gets four times as slow as map size merely doubles is bad. Hence the texture check, and then only one leaf's pvs is checks.
Tbh, I'm not sure it would be all that slow, but its not a trivial operation.
Reliablity is probably better than speed here though...
Side note: hexen2 has opaque lava and transparent water. _________________ What's a signature? |
|
Back to top |
|
 |
r00k
Joined: 13 Nov 2004 Posts: 483
|
Posted: Sat Aug 14, 2010 4:38 am Post subject: |
|
|
I curious, how a brush model can have an alpha channel and render without any performance issues, but water cannot. Is it possible to remove water from a map and replace it with something simpler? But still retain the transparency? |
|
Back to top |
|
 |
metlslime
Joined: 05 Feb 2008 Posts: 177
|
Posted: Sat Aug 14, 2010 8:42 am Post subject: |
|
|
well consider:
if on average, 1% of water leafs have a water surface, and the map size doubles, then you have twice the number of leafs with a water surface, so you still have 4x as much work to do  |
|
Back to top |
|
 |
Sajt
Joined: 16 Oct 2004 Posts: 1026
|
Posted: Sat Aug 14, 2010 3:31 pm Post subject: |
|
|
r00k wrote: | I curious, how a brush model can have an alpha channel and render without any performance issues, but water cannot. Is it possible to remove water from a map and replace it with something simpler? But still retain the transparency? |
The brush model is a func_wall or other entity? (Meaning it doesn't block vis) _________________ F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe. |
|
Back to top |
|
 |
|