Download

HLSL Custom rotation? Need help

Hello, I’m trying to do something in an HLSL Custom node but first need to figure out how to rotate a texture, so as a test I’ve tried copying over the CustomRotator node below.

Here’s the code I’ve created (same variable names as the comments in the nodes above)


//Inputs: Tex, UV, Center, Angle

float2 angle1 = float2(sin(Angle), cos(Angle));
float2 angle2 = float2(cos(Angle), -sin(Angle));

float preDot = -Center + UV;

float dot1 = dot(preDot, angle2);
float dot2 = dot(preDot, angle1);

float2 preRot = float2(dot1, dot2);
float2 rot = Center + preRot;

return Texture2DSample(Tex, TexSampler, rot); 

The code seems to be identical to the nodes above, however look at my HLSL rotation compared to the Nodes one:

I can’t see where my code went wrong from the nodes. Any ideas?

Thanks!

Figured it out, leaving here for reference. Bold is what was added/changed to make it work:



//Inputs: Tex, UV, Center, Angle

**//Needed correcting the angle so it spins in a full circle**
**float ang = Angle * 3.14 * 2;**

float2 angle1 = float2(sin(ang), cos(ang));
float2 angle2 = float2(cos(ang), -sin(ang));

**//I had the UV as a single number var by accident**
**float2** preDot = -Center + UV;

float dot1 = dot(preDot, angle2);
float dot2 = dot(preDot, angle1);

float2 preRot = float2(dot1, dot2);
float2 rot = Center + preRot;

return Texture2DSample(Tex, TexSampler, rot);

I would like to know if there is any node in the Material Editor that can rotate a texture sample 90 degrees. I thought that the Textur,coordinate would do that, but it seems it does not. If there is no option for it in the material editor, is there any other option besides changing the original texture file

Greetings @kanyekim !

We see that this is your first time posting! :medal_sports: Welcome to the Unreal Engine Community!

Thank you for providing your inquiry. Until one of the Rockstars in the community provide you with some great suggestions and possible solutions, it may help to post which version of the Unreal Engine you are currently using. Thank you so much for being an important part of our growing community!