Home Technical Talk

Lerp 3 textures

polycounter lvl 11
Offline / Send Message
Bigjohn polycounter lvl 11
Hey all. What I'm trying to get done is basically a Lerp between three textures. For the sake of discussion, assume we're talking about unreal, as our engine's material creator has similar nodes.

My problem is that Lerp usually supports just 2 nodes. The material gets fed a variable that goes between 0..1 range. I need 0 to be TextureA, 0.5 to be TextureB, and 1 to be TextureC.

Anyone has any idea as to how to pull it off?

Replies

  • cryrid
    Options
    Offline / Send Message
    cryrid interpolator
    Can't you just pipe the result of one lerp into a new lerp node?
  • whipSwitch
    Options
    Offline / Send Message
    whipSwitch polycounter lvl 8
    Basically what cryid said. If you need to interpolate between three values, then use 3 nodes:




    ----( 0 - .5 )LERP_NODE--|
    |---- texA
    | ---- texB
    |
    |
    value01(0-1)---|LERP_NODE
    |
    |
    |
    ----( .51 - 1 )LERP_NODE--|
    ---- texB
    ---- texC

    maybe thats not what youre after, but hope it helps.

    *edit: lost all the formatting... Basically you use one node to control the blend between two others. And for each of the two others, you blend betrween a-b and b-c.
  • Bigjohn
    Options
    Offline / Send Message
    Bigjohn polycounter lvl 11
    Hmm, that doesn't quite do it. It actually works nice for 0 and 1, but at 0.5 it blends between all 3 colors.

    Lerp_01.jpg


    At 0.5 I would expect it to be fully blue (the center color), but instead it blends between all 3.

    Hope I'm clear.
  • rooster
    Options
    Offline / Send Message
    rooster mod
    it looks like both initial lerps are taking values ranging from 0-1, but in whip's diagram he mentions using 0.51 - 1 and 0 - 0.5 as input
  • Bigjohn
    Options
    Offline / Send Message
    Bigjohn polycounter lvl 11
    The problem is that the variable that's being fed into the material is just a single variable that goes from 0 to 1. So I'm not sure how to use just part of it with the lerp nodes.
  • tharle
    Options
    Offline / Send Message
    tharle polycounter lvl 9
    you could use an "if" node if your engine has one since it has 3 outputs? you'd need one of the states to be exactly equal to though so it would work as a switch rather than a soft blending. what sort of variable is it you want to pass to this part of the network?

    i've had a quick play with using multiple lerps and come up with something that's pretty close.

    the attached udk network should blend nicely between blue and red from 0-0.5 and then from red to green from 0.5-1 but for some reason the centre path isnt working. the output value from the second 1-x node should be 0 (and does indeed look black) but doesn't work correctly when connected into lerp2. it might just be a quirk of UDK or something though so have a try in your engine. if you just need a switch between 3 textures if you just connect the variable directly into lerp2 that should work correctly for 0, 0.5 and 1.

    just checked and if you change the centre multiply from 50 to 49.9 it works fine. obviously some sort of rounding error that close to zero or something.

    tharle
  • whipSwitch
    Options
    Offline / Send Message
    whipSwitch polycounter lvl 8
    ok, that makes sense in hindsight, mashed my logic together. Tharle is right, it needs an IF to start so that it blends strictly between a-b and b-c. I jumped into the editor, and this works. It normalizes the values above and below .5 so that it blends evenly inside each set:

    blend3textureMaterialTree.jpg

    if you want, I can email you the material if you cant reproduce it. either way, hope this helps!
  • Bigjohn
    Options
    Offline / Send Message
    Bigjohn polycounter lvl 11
    This is great. Thanks for the help guys!
Sign In or Register to comment.