Is it possible to "lock" a worldaligned texture?

I somewhat recently discovered the worldalignedtexture node, and it has revolutionized how I design environments. However, I am wondering if I can use it with animated objects without the texture changing.

So more specifically, I am wondering if it is even possible to “lock” or “bake” a world aligned texture when an actor is spawned, so that it can be moved, rotated, or animated without the texture changing. For example, say I wanted to model a boulder with a world aligned rock texture for variation, with moss on the top side, and be able to roll the boulder, and for the texture to perfectly roll with it, as if worldalignedtexture wasn’t used at all.

a world aligned texture is locked by definition. what you want is to shift it’s coordinates based off the object it’s on yes? if so then this should solve your issue. also if you are using world aligned texture i believe you plug in the 1-x into the WorldPosition input. if that doesn’t work remove the 1-x and try again.

Thanks for the reply! However, I suppose I could have been a little more specific.

The main thing I’m trying to accomplish, is to get an animated actor to initially have its texture world aligned, and then somehow locked, so that the texture appears to be baked onto the mesh. A much better example would be applying a world aligned texture to a few tree actors, mainly for some texture variation, but have them animated to move with the wind, and not look like the texture is morphing because certain vertices are changing their world space location. Does that make sense?

To some, this may seem like an unnecessary thing to accomplish, but if I can get it to work, it can produce some truly powerful results. What I like so much about world aligned textures, is the fact that they appear seamless, and I would like to be able to use them for detail texturing on actors like characters, because it can cover up seams very nicely. Is what I’m trying to do even possible? I tried your method, dillzilla, and it didn’t do what I wanted.

Yeah it is possible. You need to project textures in mesh local space rather than world space. You would need to modify WorldAlignedTexture material function for this yourself though.

If I recall correctly, there’s a local counterpart to this node: ObjectAlignedTexture.
If there isn’t, go inside this node (it’s a function) and Transform world position into local space.
But that only works for object position/rotation anim. Moving vertices are why standard UVs were invented. For baking, you can recreate the setup in Substance Painter (using Fill type of layers with Triplanar option).

im wondering if you ever got a solution to this… im using world aligned because it fixed so many of my UV problems directly in unreal editor, but if i have something like a moving iceberg using world aligned texture it looks ultra silly…

thanks for your detailed explanation. I found out a solution on my own as well here is a screenshot

by using world aligned function with a world position using a local position function it locked into place (so the icebergs material are locked onto it even if it is moving)

I did it for the same reason as you, as the icebergs used where originally very low poly and then i subdivided them and I don’t have much time to setup uv maps for each and everything in the game so world aligned seems like a quick fix for almost everything that has an issue with the uv map

1 Like

I found something close to what I wanted, but not exactly. I had to do some ‘under-the-hood’ experimentation to get it to work properly.

Basically, I looked through the engine content folders and found a material function called “LocalAlignedTexture”, or something like that. I don’t believe it was a finished function, as it didn’t seem to work properly by itself. So I messed around with it until I got it to accomplish what I wanted.

When applied to an actor, it would seamlessly wrap the texture around the whole object, and when rotated, the texture stayed fixed. This is really nice for doors that swing on a hinge, and don’t need an intentionally mapped out texture (I used it for a basic white door with a couple different wood grain textures). It’s especially nice, because you don’t have to manually map out the UVs for the mesh–although you will need to give your mesh an ‘automatic UV’ layout to avoid texture stretching.

Will this work for your project? It sounds like it. But my original intention was to be able to do this with a texture ‘start position’, which would be linked to the actors starting point, and then be locked. The local aligned function I used locks the texture, but I believe it will map out the same exact way on a duplicate actor at a different world location.

To summarize, I had two intentions:

  1. Texture automatically wraps around actor seamlessly so I don’t have to go through the hassle of manually UV mapping every mesh.
  2. Give texture a ‘start position’ that is offset by world location, and remains locked when moved or rotated.

I found a way to accomplish the first intention, so my problem is half solved. If you or anyone else have an idea that might work for the second part, let me know!

Imagine-Games, if this looks like any kind of solution to you, let me know, and I can post a screenshot of the function I modified.

Buddy could you please show us how you created a UseLocalPosition node?

Oh sorry, it’s a simple switch statement. Anyway, your method doesn’t solve the problem at least in my case. World Position node doesn’t affect (texture still swimming while the object is moving). The Local Position node works fine but the texture is stretching.

Rule The World: using local position to lock world aligned material ... - YouTube i made a quick video showing how it worked for me… so the object is now moving but the materials are locked onto it… and there is a scale setting so you can fine tune the texture stretching depending the static mesh you use and how you scale it…

Wow thank you for the video! I’ll try out scaling feature tomorrow and give you a feedback!

Don’t remove the video please.

So I’ve played around your material and found out what the issue is. Texture projects fine while the mesh is facing X or –X direction. When I rotate the mesh — texture gets distorted. Texture stretches if rotating the object after simulation is being started as well. Moreover, I’ve tested this material with the starter content simple objects and I ended up with the same issue so there’s nothing wrong with my mesh I believe. Scale parameter doesn’t help unfortunately.

I believe you will get the same stretching if you try rotating your object.

Facing X

Rotated by 30

Rotated by 60

Rotated by 90

As you can see while rotating the object texture starts fading out and instead of perfectly applied image I start getting the stretched one. That’s weird.

I’ll have to post the function graph that I edited, because I initially ran into the same problem. I was able to get rid of it. Not in the way that I wanted, necessarily, but it worked. I’ll try and post that soon.

Nice. Would be interesting.

The first image is the ‘LocalAlignedTexture’ material function, located in the Engine Content folder (just search “local” and it will pop up). If you look closely, you’ll notice there’s a section of the material that apparently never got finished. And the part that is causing the weird texture tearing, is the XY Output. If you look at it, you’ll see that the texture is one flat color.

The second image is my modified version, which includes the ability to rotate the texture (useful for using material instances for wood grain textures on doors). If you look at the graph, you should be able to figure out what I did differently, although please notice that the ‘texcoord’ nodes are [0], [0], and [2]. This is because using [1] results in the flat color, which in turn causes tearing. I don’t fully understand how all of this works, and I’m sure there’s a more efficient way to do it, but obviously the UE4 team didn’t even take the time to finish it, so I at least took it a step further.

Let me know if any part of this is confusing, and I’ll do my best to explain. Please also let me know if it works for you!

This can’t be the correct method, but I would think there would be a way to subtract the objects movement from texture coords using panning. I suppose this could be useful if you wanted to interpolate between world aligned and object aligned at run time. I’m sure there is some psychedelic effect that could make use of this but likely nothing useful.

Anyway that’s my 2 cents. XD

And what is your actual material looks like?

So I went back and put my material on a different mesh, and discovered that it wasn’t actually working the way I though it was. Coincidentally, the meshes I had used all worked well with it, and right after I posted the graph above, I tried it on a new mesh, and it didn’t work right. SO, I’m checking out a tutorial today for something completely unrelated, and stumble across this:

From the gifs, it seems to do EXACTLY what I wanted, and was available the whole time, and I just never found it :S At any rate, I’m testing it out right now, though not entirely successfully, but I think I’m finally on the right track!

hey im sorry ive been away from my main work computer as im moving and so havent been able to update, but this weekend i move in and ill see if i can offer any additional help