Inverted fade distance.

zero_rogue

L1: Registered
Sep 15, 2009
38
36
I am currently working on a tf2 map project where I need a model to Disappear once a player gets too close to it.

Now, I know there's ways to make it disappear instantly as such but I would like it to fade out once the player gets too close.

I'm just wondering if anyone knows of something that would work like this.
 

Freyja

aa
Jul 31, 2009
2,994
5,813
Some textures can be given the quality to fade away when you get close, so you could use that and make it fully transparent.

I'm not sure how, though there are tutorials on FPSB for it (Distance fading sprays)
 

Pocket

Half a Lambert is better than one.
aa
Nov 14, 2009
4,696
2,580
What Aly is referring to is people using special sprays that change (or even fade in or out) when you get closer to them. This is done by manipulating the mipmap (multiple, progressively smaller versions of the texture that it uses based on how close you are, to save rendering time). Models have these too. I don't know what your modeling program does as far as textures, but I assume the mipmaps are created automatically. Which means you'd have to compile the model, open the texture in VTFedit or whatever, and manually edit and re-import the mipmaps so the biggest ones are just empty, transparent images and the others don't change.

One possible issue with this is that Source (unfortunately) renders textures viewed from a shallow angle with the lower-resolution mipmaps, so there's a good chance you'll just end up with a model whose "sides" (from the player's point of view) are visible but whose "fronts" are not. Naturally this is not what you want, but I don't know of any other way to do what you're suggesting.
 
Dec 25, 2007
566
439
You can add proxies to the model's texture to make it become more transparent as the user gets closer. For example, adding the following to your material's .vmt (inside the first set of curly brackets) should make it begin fading at 768 units away, and become fully transparent at 256 units away (measured from the model origin). Changing the "$startfade" and "$fadedistance" values will change where the fade occurs.

Beware that while this should work, I have not actually tested it.

Code:
// The distance at which the texture will become fully transparent
"$startfade" 256
// The distance the fade will last for. 
"$fadedistance" 512

// Variables used in calculating the fade
"$d1" 0
"$d2" 0
"$d3" 0

"Proxies"
{
    "PlayerProximity"
    {
        "scale" "1"
        "resultVar" "$d1"
    }
    "Subtract"
    {
        "srcVar1" "$d1"
        "srcVar2" "$startfade"
        "resultVar" "$d2"
    }
    "Divide"
    {
        "srcVar1" "$d2"
        "srcVar2" "$fadedistance"
        "resultVar" "$d3"
    }
    "Clamp"
    {
        "min" 0
        "max" 1
        "srcVar1" "$d3"
        "resultVar" "$alpha"
    }    
}