Announcement

Collapse
No announcement yet.

Changing materials based on distance <solved>

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Changing materials based on distance <solved>

    Hello all!

    I'm trying to alter a material based on the distance it is to a player. My intent isn't to fade it out based on distance (like DestDepth), but to actually alter the material using a LinearInterp node. I want it so that when a player is closer to the object with the material it fades to another texture within the material.

    I've tried a number of different ways, but the best I've managed to get so far is using time and sin nodes, but those reset back to the original (understandably so) on their own. I ttried using the "If" nodes to gain a little more control over when a certain texture is displayed, but it doesn't quite seem suited to what I need. Does anyone have any ideas how you might do this? Thanks much!

    #2
    Use a PixelDepth expression and divide that by a Constant. the value of the constant will be the distance where the transition begins (or ends depending on how you look at it I guess). Clamp the result of the divide to a range of 0 to 1. Use that result as the Alpha of a Linear Interp to blend between the two textures.

    So if you choose a value of 1024 for the Constant, when the player is right next to the object the material is applied to, the material will display the texture connected to the A input of the Linear Interp. And when the player is 1024 or more units away, it will display the texture connected to the B input. Between the two distances it will fade between the textures.

    You can play with it to get whatever specific effect you want, but that is a basic way to do distance blending.

    Comment


      #3
      Awesome, thanks so much!! Looks like it's gonna work well.

      Comment

      Working...
      X