Absolute World position material - how to set it up?

I am trying to create material where object is mapped in absolute world position coordinates. So far, I’ve got only partial success, only top side is correct, side coordinates are weirdly skewed.
Can you please help me and tell me how to set it up so all sides of the box are mapped correctly?
This is what i have so far.

Thanks, H

There is a material function called World Aligned Texture. It is in the engine\content folder and it should do all of the necessary math for you.

The thing you are missing above is that you actually need 3 separate textures, one for each axis. You added the projection UVs together instead of sampling a different texture with each, so you kind of got a weird skew going on instead.

2 Likes

this is what i was looking for! thank 100x!

One more question if you don’t mind. That node is not exactly cheap and if i want to blend multiple textures i need to create ‘World aligned texture’ node for each texture which adds to the complexity. Is there a way to blend textures before i feed them to the ‘World aligned texture’ node?

unfortunately, no. That just isn’t how textures work. When you sample a texture you sample it from a specific point called a UV position. Once you have already sampled a texture all you have is the data at the particular UV sample you grabbed.

For the world aligned, you need to pass a texture OBJECT so that the shader can sample each texture from the correct location.

Now you COULD do something different and instead of blending 3 different textures, simply use an IF node to modify the UVs of one texture. But you would end up with a complete hard edge at the transition points and probably very bad mipping issues there too unless you use ddx and ddy to specify the mips (set mip to derivative mode on node).

To do that last version you need to get the dot product of the worldnormal and the 3 projection axes (just like it does inside of the world aligned blend node). Then you would find the largest one of those and that would be the UV that wins.

Note that I don’t really recommend that method but thats the gist of it.

Hm, too bad :frowning:
:slight_smile:

Anyway, huge thanks for advice and prompt response! I really appreciate it!
H.

While you’re definitely right that this metod is not very cheap, depending on the kind of project you’re doing it can definitely be worth it. My company makes archviz stuff, and in those circumstances it’s been worth it for us. Our scenes contain up to a couple hundred materials, and about 80% of them use the WorldAlignedTexture node. Then again, we’re in the position of being able to specify ourselves which computer/gfx card the customer should have to run our stuff.

One other thing I like with that node is that you save lots of time by not having to UV-map as carefully as if you used “normal” materials.

Yeah, archviz is kinda exception from the regular practices. I sadly don’t have that luxury. But still, ‘World aligned texture’ is quite useful and i am going to use it a lot.

Yeah I guess for games it’s something you don’t use all the time, still it’s worth using it in some places =D