Gradient across object

I want to create a material in which there is a smooth vertical gradient from the lowest vertex to the highest.

I also want the flexibility of being able to scale and rotate the mesh, with the gradient looking the same.

I’ve sort of created this effect by using the pixel position, masking Z, and dividing by a height then lerping the color. This would require me to make a new material or instance for every single object though, which would make me cry.


As you can see, the limitation of my current material is that I want the gradient to be static, and as you can see pushing the Z down (object on the right) results in half the mesh becoming darker, instead of looking like the one on the left.

Material:

I’ve thought about subtracting the actor position Z (set to the bottom of the object) from the pixel position Z, but I couldn’t get it to work… and I’d still have to create a new mesh with corrected origin every time as UE4 doesn’t seem to let you change the origin permanently… which is NOT something I want to do…

Vertex colors are definitely not what I want.

https://dl.dropboxusercontent.com/u/107682595/Unreal/DynamicGradient.png

If i understood you correctly this should give you want you want. A gradient from the bottom to the top of the object regardless of scale and orientation.

Thank you, it works perfectly as I wanted it to. Somehow I missed that there is an object bounds node when I was messing around, which was a good cause of my confusion I think.

The multiply can control the intensity but do you know of a way to control the falloff? I’ve been playing around with it and cannot seem to figure it out. Going to keep trying though!

I am a bit late to the party, but can you repost your solution @divi ? That dropbox link is dead :frowning:

1 Like