• News

• Industries

• Learning & Support

• Community

• Marketplace

# Material: Get texture direction?

I’m attempting to create a material where some text on it is always pointing up no matter what orientation the player is in. I know I can use the custom rotator node to supply a custom rotation, but I need to figure the angle to rotate it by. I’m pretty sure I can use some form of dot product to find the angle, but I would need to know what direction the texture is currently drawn at for that. If my knowledge of shaders serves me texture direction is usually dealt with at the vertex level so things like normal maps can be orientated correctly, but I’m not sure how that translates to the material editor. So is it possible to access or calculate somehow the texture direction in the material editor?

Maybe this can help https://docs.unrealengine.com/latest/INT/Resources/Showcases/Stylized/Materials/index.html scroll down to Foliage Material

Close but not actually trying to create a billboard. For mine use I don’t need it to face the camera. Rather I need the texture to orient on a surface it is applied to. Basically rotate on its existing plane.

After a bit of research and experimentation I was finally able to make it work. To get the texture direction I found you can use the transform node (Tangent to World). I then fed it the constant 1,0,0 and your output is the direction the texture is pointed in world space. Then I needed the camera up axis. Once again I used the handy transform node (View to World) and fed it 0,1,0. Then simply project the camera up axis onto the surface and find the angle between this vector and the texture direction vector. Plug that into the custom rotator. complete.

Lehm, I’m not familiar with “project the camera up axis onto the surface”. Is there a specific node that you used for that? I’m not very familiar with material blueprints. Please help! Thank you.

I am guessing a dot product with the camera up axis and vertex normal. When the input vectors are normalized, Dot product returns the cosine of the angle between the vectors which you can use. In the above case he is probably doing acos(x) using a custom node which does the inverse cosine to return the angle. That said, acos is not cheap and if possible I’d try to solve it another way. Since its just for a simple vertex shader though, probably not a big deal.

Without seeing what exactly the OP is trying to do, it is hard to suggest an alternate method. But generally I’d avoid rotations if they can be avoided and instead try to recreate the position using a projection along the defined vectors.