Jump to content

MaterialGraph RotateUV appears to scale also


photo

Recommended Posts

Posted

Hello,

I'm trying to rotate a texture in a material graph, and the rotation appears to also scale down the texture:

The mesh is a simple quad with UV from 0,0, to 1,1

graph_rotate_uv.gif.6e482ff5bdecbe8b4724a679ecd42ee6.gif

As a sample test, here is the graph used:

image.png.ae81176830b0582bf3ddf618532162c8.png

Am I doing something wrong? Is it the expected behavior for this node? If yes, then how should I compensate the scaling?

Suggestions: add support for a pivot different from (0.5, 0.5)

Suggestions: if the scaling is expected, add support for a compensation in the node as a static switch

Thanks!

Posted

Hi Stephane,

The Rotate UV node was automatically ported into the graph from the general shader codebase. It works as intended for brushes by rotating the UV coordinates and fitting them into the rectangle, which is why you're observing scale changes.

To avoid this scaling behavior, you can create your own rotation method. Simply create a custom Function node and use the following code:

float2 rotateUV(float2 uv, float angle, float2 pivot)
{
float s = 0.0f;
float c = 0.0f;
sincos(angle * DEG2RAD, s, c);

uv -= pivot;

float2 ret;
ret.x = c * uv.x + s * uv.y;
ret.y = c * uv.y - s * uv.x;
  
// uncomment for fitting in square
// ret *= max(abs(c + s), abs(c - s));
return ret + pivot;
}

image.png

Just in case, full matgraph file for that: rotate_uv.mgraph

We plan to add proper Rotate UV methods in future updates (2.21+).

Thanks!

  • Like 2

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

It works! Thanks a lot!

Bonus question: If I want to use the function multiple times in the same graph, I guess I have to put it inside a subgraph and use the subgraph instead, or is there a better way?

Posted
Quote

Bonus question: If I want to use the function multiple times in the same graph, I guess I have to put it inside a subgraph and use the subgraph instead, or is there a better way?

Yes, that's the right approach for using it across multiple graphs. Just don’t forget to replace it with the proper native version once it’s officially released :)

  • Thanks 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

×
×
  • Create New...