• News
• About

• Industries

• Learning & Support

• Community

• Marketplace

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);

``````