Inverted fade distance.

Discussion in 'Mapping Questions & Discussion' started by zero_rogue, Dec 2, 2009.

  1. zero_rogue

    zero_rogue L1: Registered

    Messages:
    38
    Positive Ratings:
    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.
     
  2. Freyja

    aa Freyja ¯\_(ツ)_/¯

    Messages:
    2,849
    Positive Ratings:
    4,845
    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)
     
  3. Pocket

    aa Pocket func_croc

    Messages:
    4,489
    Positive Ratings:
    2,219
    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.
     
  4. VelvetFistIronGlove

    aa VelvetFistIronGlove

    Messages:
    567
    Positive Ratings:
    437
    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"
        }    
    }