# Creating a greyscale gradient between two chosen points in the modelling space

I'm making a model for a game which is rendered in an isometric view. The mechanics of game engine also factor in model height to determine which part of the model should be rendered in front of other elements of the scene.

Here comes my problem. The way the height is being mapped on the isometric view, is through a greyscale overlay of the model, which basically maps model height to how "grey" the pixels are (0,0,0 being the possible lowest and 255,255,255 being highest).

I tried to use the Texture Coordinate node, paired with a map node and Gradient Texture with Color Ramp but i found that method to be very cumbersome if one wants to obtain very precise gradient over certain height. Here is an example of the above use case, where i use the "Object" vector output.

To map the gradient over the entire model (which also has to change during animation steps) i used an artificial "bounding box" which is highlighted in the middle of the model. The issue with this method is that i have to scale the vector accordingly to obtain a full gradient over the entire height of the bounding box. In this case, the box is 6.54372m tall, so to get a proper scale in, i have to set the scale to 1/6.54372. Here is the result.

To make the process simpler, i tried to also use the "Generated" output, but then the issue is that the gradient is overlayed separately over each element of the model, ignoring the bounding box.

As you can see, the result is far from ideal. Finally my precise question would be - Is there a simple method to obtain a gradient stretched over some arbitrary two points in the model space, that every other part would respect, that wouldn't require calculating all this manually. The ideal case would be something like this:

1. Determine two verts or objects with a single vert each, that would act as top and bottom of the gradient
2. Input the global coordinates of those two vertices and use them to project the gradient
3. The direction and scale of the gradient would be calculated depending on the direct length between those two verts and the direction of a vector pointing from one to another

I'm asking if there is an already existing combination of nodes (or a script) that would handle such operation?

I'm sorry if my question seemed trivial, i'm not very familiar with blender in terms of texture node handling so this might be a very simple problem which i'm just not aware of. I tried looking for solutions before that, but nothing seemed to be describing my problem to a satisfactory degree.

Best regards,

• Is this mesh static in shape or have moving parts? Have you used and have a basic understanding of UV Map? Is UV map is inadequate? May 20, 2022 at 17:15
• I also find the question 50% clear. Can you put a goal at the top such as .. [I want the color of the model behave this way _______]. Fill in the blank. Currently the color fails in this way ______ May 20, 2022 at 17:21
• Do you simply want the model to have a simple gradient color flowing across all components and does not change? Just a simple paint job? May 20, 2022 at 17:22
• You can produce a UV Map for two objects at once. Select two items in object mode. Have UV edit window open for convenience. Create gradient image or similar . Switch to edit mode in 3D View. Verify vertex selections are complete. Project from view. Inspect UV placement and adjust if necessary. Switch to Object mode. Each item will have a UV Map preserving their relative positions. These instructions are high level and [not] a tutorial. Please suit to your goals. If you do this 38 times or less it may only take 60 seconds. May 20, 2022 at 17:45
• To clarify my goal, i want to color all objects inside a model with a single greyscale gradient from bottom (000 RGB) to top (XXX RGB), but the twist to that is that i want the top and bottom be defined by some chosen arbitrary vertices with their individual global coordinates. The issue with applying UVs is that this whole project uses 3 different shader masks and i switch them between 3 different scenes using object pass indexes. I'm affraid that by trying to simplify this issue that way, i would complicate everything else. May 20, 2022 at 17:47