distance from pivot

Is there a way to calculate how far a vert on a mesh is from it’s pivot? Basically, I want to lerp some ground textures onto the base of some meshes w/o needing to vert paint them. Single-Axis distance from pivot would be sufficient, but i can’t find anything close:(

How about something like this ?

that looks promising, i’ll give it a try:)

hmmm. not quite:( Even when I place the mesh at 0,0,0 (so world coords = local coords, just in case) i get a solid value output (of about 10, i think - hooking it into the alpha of a lerp only blends if i multiply the distance output by .1 or lower).

That is strange. It outputs a gradient, that you have to divide by approx mesh size and clamp it to 0-1 range to use as mask.

As an alternative you could bake distance to pivot in your modelling application, or use a texture mask.

true that, though i wanted to avoid an extra mask; i’ll play w. it some more in a bit

You can use the object radius to scale the results. Obviously distance will yeild a very extreme result because 1 unit in Unreal Engine is like 1 cm, so you’ll want to divide it by the object radius (or maybe 2x the object radius, whatever gets you the best results).

awesome you two. dividing the distance output by the object radius brings it into a useable range. thanks:D

yeah, once i did that, i set it up as a scalar param so I can adjust it on a per-material basis. looks like i might need to add in a mult after the divide…

actually the power node is what i want. here’s the setup w. instance-friendly variable names:

I will hijack this thread since I’ve ran into somewhat similar task. I need to blend static meshes with terrain. While blending itself is pretty straightforward , I want to automatically mark the area where mesh intersects with terrain. Vertex paint is fine, but in my I case I will be dealing with large procedurally generated world, and vertex painting becomes a no go.

So far I have identified the following methods of automatically getting mesh/terrain intersection:

  • Transform mesh vertex positions into new coordinate system, where Z basis vector would be terrain’s normal at given position, then get a distance along new Z between vertex position and pivot point. This results in a mask stripe, that would always follow the terrain shape. Generally, result is acceptable, but somewhat costly. Might also try moving terrain normal map sampling down to vertex shader. It is also quite limiting, as the mesh needs to be placed in a such way, that its pivot is near terrain surface and this method suffers from accuracy loss on high slopes.

  • Just sample terrain’s heightmap and convert it to world Z, then compare with mesh’s vertex position. This is ideal solution, however, adding terrain’s heightmap as a texture would be just a waste of memory. On top of that, 8bit heightmap would probably suffer from precision issues. And as with normal map, this approach also deteriorates on high terrain slope angles.

  • Use distance fields. So far distance fields are not used in the project. Enabling them just for this purpose would seem irrational. I would stay away from this.

Does anyone have any advice or thoughts on this?