Triplanar mapping in object space (should be rotatable in editor without swimming)

Hey!

Triplanar mapping would be extremely useful for a project I’m working on. I found out about the pre-made material expression WorldAlignedTextures_Complex and it’s working fine. The problem is the textures are projected along the world-space axes, which causes the alignment to change depending on the orientation of the StaticMeshActor the material is applied on. I would like to be able to rotate the object without affecting the material (the textures should be projected along object-space axes instead).

Tried applying the transform from world to object space myself in the material using the cross product of ObjectOrientation and VertexNormalWS (Coordinates Material Expressions in Unreal Engine | Unreal Engine 5.1 Documentation). Seems like anything based solely on ObjectOrientation will not work as it provides the up-vector, which does not contain any info about the rotation along Z-axis. Not sure if VertexNormalWS is the correct input to use either.

Tips? Here are a few pics to illustrate:
https://
https://
https://
https://

looks like you want local aligned textures

LocalAlignedTexture seems to only solve this if the model has proper UVs, if you want to skip manual unwrap altogether you can use BoundingBoxBased_0-1_UVW as the WorldPosition input of WorldAlignedTexture/WorldAlignedTextures_Complex. In my quick test is seems to only work properly for two axes, but there is probably a simple fix for the remaining axis which gets stretched.

On closer inspection BoundingBoxBased_0-1_UVW seems to be based on the up vector just like the ObjectOrientation node is, which makes the triplanar texturing only work correctly if the Actor has not been rotated around its Z-axis. Anyone know a way to feed the Z-rotation of an Actor to a material graph?

This is actually really easy to do.

I’d been looking in to this myself for some time.
Ran across I dont know how many obscure forum posts talking about finding an objects rotation from its z-axis and other things, then using that to manually make a CustomRotator node work around the object pivot function so it was aligned, then applying those rotation points to the three projected world-space UV coordinates, and… It was a mess.

Turns out if you go in to the WorldAlignedTexture node and just do this to the WorldPosition and VertexNormalWS nodes, it does exactly what you’re after:

So a really easy Locally-World-Aligned texture node network would look like this:

9 Likes

rotatable in

This works for the rotation… but not for scaling the mesh in the world space.
Did someone know how to make this local mapping work the way world mapping does - be unaffected by the scaling of the actual object???

Thank you

Kudos… :sunny: