I’m working on material function ‘LocationBasedAlpha’ that takes two world-space points and gives 0-1 alpha for vertices between these points… Maybe it’s better to explain by some images:
It already works, but let me show what I did here to explain the problem better. At first I had this function:
… And this result:
As you can see, it’s not fully red at the bottom, because this is what happens (it’s the bottom of this cylinder):
It’s because it compares distance on all axes, so the further from center of the cylinder, the further the alpha value goes.
What we need to do is to compare vertex distances only along this PointA —> PointB LookAt axis:
… And because I can’t figure out how to implement that, for now I’ve fixed it by taking LookAt vector from point A (point that specifies Alpha == 0.0) to point B (point that specifies Alpha == 1.0) [this way we have the ‘alpha axis’] and multiplying it by all the checked locations:
… This gives the correct result (as in the first image), but there is a problem:
As you can see, alpha values are calculated OK when mesh is rotated at 0 or 90 degrees, but they’re bad when it’s rotated by e.g. 40 degrees. The cube is there to help to visualize the problem - it has the same material, with the same ‘alpha points’.
So I feel like I’m close to finishing this function, but I can’t figure out what’s wrong with that.
… Or maybe there is some other, better solution for this type of location-based alpha function?
I hope that I’ve explained this in understandable way. I would be grateful for some hints, function like this (location based alpha) would be really useful in some dynamic interaction/generation cases, and probably for other projects too!
PS. The material is just two colors (red & green) Lerp’ed with the calculated Alpha value.*