Page 1 of 1

MH Transparent Water Detection

Posted: Fri Aug 13, 2010 4:23 pm
by Baker
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;
}

Posted: Sat Aug 14, 2010 12:49 am
by mh
Did you get it working? Kudos if so, I never could get it 100% accurate.

Posted: Sat Aug 14, 2010 2:30 am
by metlslime
kinda seems over-complicated to look at textures.... if any water/slime/lava leaf can see any empty leaf, surely that is sufficient?

Posted: Sat Aug 14, 2010 3:13 am
by Spike
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.

Posted: Sat Aug 14, 2010 4:38 am
by r00k
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?

Posted: Sat Aug 14, 2010 8:42 am
by metlslime
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

Posted: Sat Aug 14, 2010 3:31 pm
by Sajt
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)

Posted: Thu Aug 19, 2010 3:58 am
by jonyroger
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.

Posted: Thu Aug 19, 2010 4:13 am
by Baker
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.

Posted: Thu Aug 19, 2010 6:16 am
by Spike
yay, even the bots are quoting me!

Posted: Thu Aug 19, 2010 1:18 pm
by gnounc
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.