Inside3D!
     

MH Transparent Water Detection

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Fri Aug 13, 2010 4:23 pm    Post subject: MH Transparent Water Detection Reply with quote

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
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Sat Aug 14, 2010 12:49 am    Post subject: Reply with quote

Did you get it working? Kudos if so, I never could get it 100% accurate.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
metlslime



Joined: 05 Feb 2008
Posts: 177

PostPosted: Sat Aug 14, 2010 2:30 am    Post subject: Reply with quote

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
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sat Aug 14, 2010 3:13 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Sat Aug 14, 2010 4:38 am    Post subject: Reply with quote

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
View user's profile Send private message
metlslime



Joined: 05 Feb 2008
Posts: 177

PostPosted: Sat Aug 14, 2010 8:42 am    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message
Sajt



Joined: 16 Oct 2004
Posts: 1026

PostPosted: Sat Aug 14, 2010 3:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group