Download

Applying Material with World Aligned Blend to Procedural Mesh Component

I am currently using the Runtime Mesh Component plugin to created a tiled landscape but this issue occurs with the Procedural Mesh Component too so this isn’t some unique setup I have.

Anyway, here’s the issue:

The same material instance is being applied to all of these objects. What I WANTED to accomplish is to have the Mesh Components material change from grassy to rocky on steep slopes. This happens fine with the landscape. Something funky is happening with the skeletal mesh there but at least it’s altering. For the mesh components, if I scale the Blend Bias and Blend Sharpness a bunch I can see the results reflected on the landscape and skeletal mesh. For the Procedural Mesh and Runtime Mesh, it’s like… they’ll be completely green with -49 for a blend bias. Then -49.5 it’s halfway between grass and rock - the texture is the same across the whole thing (it’s supposed to be green on the flat part and gray on the sloped part). Then at -50 it’s all gray.

I’m assuming this is a result of the WorldAlignedBlend node being unable to properly get the vertices of these mesh components. Here is my material:

Do I need to be passing additional information into the In World Vector? I’m new to this node and bad with the material editor in general so a lot of this has been guesswork for me - I’m not sure what I might use here.

This is my “SANITY” actor - an actor with a runtime mesh component and a procedural mesh component, built with the same parameters.

I am able to use the Absolute World Position node and it seems to have no problem changing the material

But that’s not what I’m looking for here…

Any suggestions?

If you’re still having trouble here, I’ll point out that the WorldAlignedBlend node uses the normal and tangent data provided by the mesh it’s applied to. In your sanity check actor, it seems you’re setting all the normals and tangents to the same value - thus you wont see any variation across the mesh. You can use the “Calculate Tangents for Mesh” node to correctly calculate these values for you by passing in Vertex, Triangle, and UV arrays.

Note: There’s a node for the procedural mesh component, and a node for the runtime mesh component. I’ve been using RMC v3 compiled for 4.23 - in this version, at least, the RMC CalculateTangentsForMesh was returning NaNs for most of my terrain vertices. This might be fixed in v4, haven’t migrated to that yet. Though they’re defined as different objects, the contents of an RMC tangent and a PMC tangent are the same. My workaround (in c++) was to use the PMC function, then loop through all returned PMC tangents and set each member of an RMC tangent array with the same TangentX and bFlipTangentY. That bit of c++ looks like this, after having set up ThisSectionVerts, ThisSectionTris, and ThisSectionUVs:



// RuntimeMesh Tangent calculation throws back a bunch of NaNs, might be fixed in v4 but for now we can just use the slower PMC tangent calc.

UKismetProceduralMeshLibrary::CalculateTangentsForMesh(ThisSectionVerts, ThisSectionTris, ThisSectionUVs, ThisSectionsNormals, ThisSectionPMCTangents);

ThisSectionRMCTangents.SetNum(ThisSectionPMCTangents.Num());

for (int u = 0; u < ThisSectionPMCTangents.Num(); u++)
{
    ThisSectionRMCTangents.TangentX      = ThisSectionPMCTangents.TangentX;
    ThisSectionRMCTangents.bFlipTangentY = ThisSectionPMCTangents.bFlipTangentY;
}


Use VertexNormalWS->SlopeMask, or at the very least VertexNormalWS->CompMask(B) as your alpha for mixing the grass/stone.

This definitely helped. I re-created your solution as well in blueprint. Now I am calculating the tangents initially and any time a mesh section is updated. Here is the current result (I did this in my actual project instead of the “sanity” test project from the first post):https://youtube.com/watch?v=VoNkCRMqiTM
It needs some tweaks to make the grass more predominant until the slope is more dramatic, but overall it’s pretty nice. What’s being shown here is the intersection of 4 mesh sections, raising and lowering the intersecting corners on each.

What is strange now is the stark lines between the mesh sections. I admit my understanding of textures, UV mapping, normals and tangents is pretty lacking so a lot of what I’m doing here is guesswork. My current blueprints (pardon the mess, it’s a WIP):
https://i.imgur.com/YC5MjnI.png

https://i.imgur.com/SFwj0X7.png

I’m … not really sure how to implement this, mostly because I don’t really understand what the inputs for SlopeMask are looking for. I’ll try to do some research on it

Did this ever get working properly, without the dark lines?
I’m attempting the same sort of thing for my project, and my “auto texture” is mashing all of the textures together on the procedural mesh.

Not yet, I kinda put this on the back burner hoping someone would respond here and I could fix it.