Triplanar projection: how to keep texture size from scaling with objects (and landscapes) while in local space?

Hey, I’m trying to make a triplanar projection material function (based on this UE4 Tutorial 101 — Texture Projection 2/3 - Tri-planar - YouTube) that should work with all kinds of meshes, be it landscapes, static meshes, skeletal meshes, primitives, imported, whatever.

By design when using World Space, textures don’t change position, rotation nor scale while you move the objects. Inversely, if you transform to Local Space, textures get locked onto objects, and will now move, rotate and scale with them.

I wanted to keep texture size consistent while using Local Space, and I managed to do that by dividing my Transform Position by (constant 50 divided by Object Bounds) as seen here:

However, this is only working for Unreal Primitives, doesn’t really work for Landscapes or imported Static Meshes. Any way I could achieve this?

1 Like

I replaced that part circled in red for this:

and now it kinda works, everything is at the same scale, landscape, static meshes, skeletal meshes, primitives, and their texture stay fixed to them as I move them around.

however, if I rotate them, the texture distorts a bit, as if it’s getting its position from a world aligned bounding box. also, landscapes still get seams at components boundaries.

Any help is appreciated. thanks

1 Like

bumping this one

1 Like

In case anyone’s interested, Ben Cloward (worked on many well known titles, and also has an amazing Youtube channel full of useful tutorials) gave me a little hand on this.

Instead of dividing by object local bounds nonsense, you just multiply the AbsoluteWorldPosition transformed to local space by ObjectScale. Very simple, and effective.

It doesn’t really work with landscapes and skeletal meshes right now, but I’m getting there.

1 Like

Yes! It works across the board now, with all kinds of meshes that I tested, all of them get the texture applied at the same scale, regardless of the size of the mesh, while textures stick to the surface when translating/rotating:

sort of a monologue up there, but I hope this will help someone

cheers

2 Likes

Is it possible for you to repost the entire material function? I’m having difficulty getting your last post to work, I think I might be missing some context. I’m getting texture swimming when I move an object after that last change.

1 Like