# Lerping two colors based on pixel z-axis value

**URL:** <https://forums.unrealengine.com/t/lerping-two-colors-based-on-pixel-z-axis-value/390079>\
**Category:** Rendering\
**Tags:** lerp, unreal-engine, z-axis, question, vectors\
**Created:** [April 5, 2017, 9:48pm UTC](https://forums.unrealengine.com/t/lerping-two-colors-based-on-pixel-z-axis-value/390079 "2017-04-05T21:48:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iacopo\_Antonelli](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Iacopo\_Antonelli](https://forums.unrealengine.com/u/Iacopo_Antonelli)\
**Post date:** [April 5, 2017, 9:48pm UTC](https://forums.unrealengine.com/t/lerping-two-colors-based-on-pixel-z-axis-value/390079/1 "2017-04-05T21:48:02Z")

</div>

Hi! I would like to lerp my material by two different colors based on the pixel z-axis value.  
How could I accomplish that?

Thank you!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fca299ff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fca299ff](https://forums.unrealengine.com/u/anonymous_user_fca299ff)\
**Post date:** [April 6, 2017, 2:03am UTC](https://forums.unrealengine.com/t/lerping-two-colors-based-on-pixel-z-axis-value/390079/2 "2017-04-06T02:03:51Z")

</div>

Hey ,

Maybe something like this is what you’re looking for? AbsoluteWorldPosition lets you get the pixel location, and then you can us the Mask node to get the Z coordinate.

 ![133066-zaxiscolorlerp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/9/1/0912f7c8bd1caaa52abec3b02a0e9f0ddd91c5e5.jpeg)

If you’re using Lightmass, one caveat is that it doesn’t seem to use the AbsoluteWorldPosition node; I suspect it just uses 0 when it’s baking but I’m not actually sure. In either case, if you’re baking your lighting, I wouldn’t expect fully accurate bounce lighting from this. If this is for an emissive material or an object that isn’t part of a light bake, it should be fine.

---

<div class="post-metadata">

**Author:** ![Iacopo\_Antonelli](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Iacopo\_Antonelli](https://forums.unrealengine.com/u/Iacopo_Antonelli)\
**Post date:** [April 6, 2017, 11:06am UTC](https://forums.unrealengine.com/t/lerping-two-colors-based-on-pixel-z-axis-value/390079/3 "2017-04-06T11:06:15Z")

</div>

Thank you very much! That was exactly what I need.
