Forum

MH Transparent Water Detection

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

MH Transparent Water Detection

Postby Baker » 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;
}
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby mh » Sat Aug 14, 2010 12:49 am

Did you get it working? Kudos if so, I never could get it 100% accurate.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby metlslime » Sat Aug 14, 2010 2:30 am

kinda seems over-complicated to look at textures.... if any water/slime/lava leaf can see any empty leaf, surely that is sufficient?
metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Postby Spike » Sat Aug 14, 2010 3:13 am

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.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby r00k » Sat Aug 14, 2010 4:38 am

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?
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby metlslime » Sat Aug 14, 2010 8:42 am

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 :D
metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Postby Sajt » Sat Aug 14, 2010 3:31 pm

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.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby jonyroger » Thu Aug 19, 2010 3:58 am

For these you have to consider: cube in the middle of nowhere. the water has no access to any air at all. it is not connected to empty, so no water revised. To fix this you must scan all PLWHA single piece of water to ensure that you do not receive a false negative. And it is painful. is the only way for magazines with a water surface will result in better scaling, without mentioning the names of some cards can be very large, and the whole routine gets four times slower than card size only doubles is poor. So check the texture, and a single sheet is PVS is control.
jonyroger
 
Posts: 3
Joined: Thu Aug 19, 2010 3:53 am

Postby Baker » Thu Aug 19, 2010 4:13 am

jonyroger wrote:For these you have to consider: cube in the middle of nowhere. the water has no access to any air at all. it is not connected to empty, so no water revised. To fix this you must scan all PLWHA single piece of water to ensure that you do not receive a false negative. And it is painful. is the only way for magazines with a water surface will result in better scaling, without mentioning the names of some cards can be very large, and the whole routine gets four times slower than card size only doubles is poor. So check the texture, and a single sheet is PVS is control.


You sir, have completed your degree in horseshitology from the distinguished University of Phoenix and should be a very proud spambot, indeed!

Congrats in being some Meixcan making 0.02 cents an hour and actually knowing some of the right words.

*Sniff*

I'm gonna miss you.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Spike » Thu Aug 19, 2010 6:16 am

yay, even the bots are quoting me!
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby gnounc » Thu Aug 19, 2010 1:18 pm

I'm so glad you guys pegged him as a spambot first...because I was actually trying to decipher that.

I read from the bottom up when skimming.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest