Cyanilux

Game Dev Blog & Tutorials

Polar Coordinates

When using UVs you are typically using the Cartesian coordinate system. Values along the X or U axis start at 0 and increase to 1 horizontally, and the same goes for the Y or V axis but vertically. But in some cases it can be useful to convert this to a Polar coordinate system, which can be done by using the Polar Coordinates node.

(Image)

In the Polar Coordinates system each point is defined by a distance from a reference point, and an angle from a reference direction. In Shader Graph this reference point is the Center input on the node, and the reference direction is always downwards, which can been seen on the preview of the node where the green gradient stops.

If you are interested in the maths used to convert between these spaces, this is the generated code for the node:

1
2
3
4
5
6
7
void Unity_PolarCoordinates_float(float2 UV, float2 Center, 
		float RadialScale, float LengthScale, out float2 Out) {
    float2 delta = UV - Center;
    float radius = length(delta) * 2 * RadialScale;
    float angle = atan2(delta.x, delta.y) * 1.0/6.28 * LengthScale;
    Out = float2(radius, angle);
}
(Image)

If we put the output of the Polar Coordinates node into a Split node, the R output will give us the distance from the Center.

The G output will give us the angle from the downwards direction.

Examples

Sampling Textures

One thing that we can do with these new coordinates is use them as new UVs to sample textures. Here I’m using a Sample Texture 2D node to sample a noise texture. Rather than it being flat (like in the other node) it’s become warped around the center point.

Note that the texture used here is seamless so it repeats without any noticeable seams. If you still see a seam you can turn off Mip Maps for the texture, or use the Sample Texture 2D LOD node set to 0 instead.

(Image)

This setup is great for portal/wormhole/whirlpool effects. We can also animate it by using a Time node and offsetting the values using Add (or Subtract).

Polar Coordinates are also useful for creating procedural patterns/shapes, such as :

Sprial

(Image)

Lines

(Image)

Star

(Image)

Flower

(Image)

Cog

(Image)

Other

The Polar Coordinates node is also used in the following breakdowns :



Thanks for reading! 😊

If you find this post helpful, please consider sharing it with others / on socials
Donations are also greatly appreciated! πŸ™βœ¨

(Keeps this site free from ads and allows me to focus more on tutorials)


License / Usage Cookies & Privacy RSS Feed