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 @anonymous_user_c2195e15 !

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!

I’ve done this without an HLSL node too, but all I was doing was the same trig math on the UV coords that you’re doing in HLSL.

This really is the correct thing to do. You’re essentially rotating the UV coords. There’s no other mathematical way to do this that I can think of.

The same thing can be done without an HLSL node too, but all I was doing was the same trig math on the UV coordinates that you’re doing in HLSL, just not with an HLSL node. There is no doubt in my mind that this is the correct course of action. It is essentially rotating the UV coordinates that you are doing. My understanding is that there is no other way mathematically to do this that I have come up with so far.

It is possible to do this without an HLSL node also, but all I was doing was the same trig math on the UV coordinates that you are doing in the HLSL node.

There is no doubt that this is the right thing to do. In essence, what you are doing is rotating the UV coordinates. As far as I can tell, there is no other mathematical way to solve this problem that I can think of.

Your remark about checking the first page and not seeing any models gave me the feeling that you were curious about that discussion. On the off chance that you’ve been there 15 years, you know precisely exact thing I’m discussing.

I’ve done this without a HLSL hub as well, yet all I was doing was a similar trig math on the UV coords that you’re doing in HLSL.

In the beyond couple of days. I have been encountering challenges signing into my Bitbucket record, and I have seen the typical goal for the issue with the accompanying message which seems, by all accounts, to be common goal for issue:

I’ve done this without a HLSL hub as well, however all I was doing was a similar trig math on the UV coords that you’re doing in HLSL.

This truly is the right thing to do. You’re basically turning the UV coords. There could be no other numerical method for doing this that I can imagine.

All I was doing was the same trig math on the UV coords that you are doing in HLSL.
This is the correct thing to do.
You are rotating the UV coords.
There is only one mathematical way to do this.

Would it be possible to rotate a texture sample 90 degrees using a material editor node? That seems to be contrary to what I thought the Textur,coordinate would do. Are there any other options besides changing the original texture file if the material editor does not have this option?

You can rotate the texture 90 degrees by just swapping the U and the V: