# Polar Coordinate Material Function

**URL:** <https://forums.unrealengine.com/t/polar-coordinate-material-function/1496>\
**Category:** Asset Creation\
**Tags:** unreal-engine\
**Created:** [March 31, 2014, 12:23pm UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496 "2014-03-31T12:23:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Feanix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Feanix](https://forums.unrealengine.com/u/Feanix)\
**Post date:** [March 31, 2014, 12:23pm UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/1 "2014-03-31T12:23:59Z")

</div>

So I’ve been playing around with this to test material functions.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/1/8/f18b41457260eebbb99ddf4de45ec7b9c85c9976.jpeg) ](https://i.imgur.com/NorWuEz.jpg)

There’s a slight error at the top middle where the texture wraps radially. Looks like the I’m getting values of something like 0.01 to 0.99 instead of 0.0 to 1.0, which is annoying. Not sure why that’s happening. If I can get it to work I’ll try to post it up so anyone can use it.

---

<div class="post-metadata">

**Author:** ![Feanix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Feanix](https://forums.unrealengine.com/u/Feanix)\
**Post date:** [March 31, 2014, 5:23pm UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/2 "2014-03-31T17:23:00Z")

</div>

Okay, figured it out.

You can download it here: [http://pietermans.com/blog/downloads/](http://pietermans.com/blog/downloads/)

Here’s a peek:

[![](http://pietermans.com/blog/wp-content/uploads/2014/03/polarCoordsExample.png) ](http://pietermans.com/blog/wp-content/uploads/2014/03/polarCoordsExample.png)

---

<div class="post-metadata">

**Author:** ![CloDevious](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CloDevious](https://forums.unrealengine.com/u/CloDevious)\
**Post date:** [March 31, 2014, 10:26pm UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/3 "2014-03-31T22:26:34Z")

</div>

So what does it actually look like when its applied? I assume its like polar coords filter in photoshop to some degree?

---

<div class="post-metadata">

**Author:** ![Feanix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Feanix](https://forums.unrealengine.com/u/Feanix)\
**Post date:** [April 1, 2014, 1:41am UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/4 "2014-04-01T01:41:42Z")

</div>

Yeah, that’s more or less what its for. It’s useful for when you need a radial effect like ripples (put the UVs through a panner first).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_50a0b22d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_50a0b22d](https://forums.unrealengine.com/u/anonymous_user_50a0b22d)\
**Post date:** [April 1, 2014, 7:28am UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/5 "2014-04-01T07:28:43Z")

</div>

Why not post a screenshot of the material here? I’d suppose many people feel strange about having to download a single material function from an external site, espacially for a relatively simple one like this.

For anyone interested in converting from cartesian to polar or spherical coordinates, back and forth, check out this post:

> **[Converting To and From Polar / Spherical Coordinates Made Easy](https://blog.demofox.org/2013/10/12/converting-to-and-from-polar-spherical-coordinates-made-easy/)**
>
> As a game developer there is just too much darn stuff to learn. You could spend your entire life learning things and never know it all. It’s a blessing in that you are seldom bored, but also …

---

<div class="post-metadata">

**Author:** ![Feanix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Feanix](https://forums.unrealengine.com/u/Feanix)\
**Post date:** [April 1, 2014, 10:04am UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/6 "2014-04-01T10:04:28Z")

</div>

That’s a good point, Malkavian! Thanks. I’ve uploaded [an image of the graph](http://pietermans.com/blog/wp-content/uploads/2014/04/polarCoordsGraph.png). Thanks for the link, btw, that looks REALLY useful! 😃 Do you mind if I include a link to that with the graph on my blog?

---

<div class="post-metadata">

**Author:** ![TechArt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TechArt](https://forums.unrealengine.com/u/TechArt)\
**Post date:** [April 4, 2014, 5:44am UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/7 "2014-04-04T05:44:43Z")

</div>

Hi! I’m glad that you worked out the issue you were dealing with. Did your initial results from one of the functions provided with UE4?

There is a function in UE4 called VectorToRadialValue that creates radial coordinates as well. I was just curious and wanted to know if you had an issue with the node.

Thanks

btw - you might notice (when viewed at a large scale) that a sampling error forms at the point where the radial gradient completes it’s rotation. To correct this you can select the texture node and change the textures mipvaluemode to miplevel under from within the details panel. You can then use a scalar value in the textures “level” input. This removes the sampling error.

Also, you could alternatively look into the ComputeMipLevel function.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_50a0b22d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_50a0b22d](https://forums.unrealengine.com/u/anonymous_user_50a0b22d)\
**Post date:** [April 4, 2014, 7:33am UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/8 "2014-04-04T07:33:32Z")

</div>

It’s basically the same but the default mat function is always dividing by 2\*Pi so there is no parameter to change the radial scale.

True words about the mip artifacts. In UE3 you could fix this by using tex2Dgrad of which I’d assume it’s faster than manually computing the mip level using ddx/ddy and log2.

---

<div class="post-metadata">

**Author:** ![Feanix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Feanix](https://forums.unrealengine.com/u/Feanix)\
**Post date:** [April 4, 2014, 9:25am UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/9 "2014-04-04T09:25:24Z")

</div>

Its not that easy to tell with that texture but when I simply output the radial as a constant and put it through a frac it repeated three times and a bit. Suspiciously close to 3.14 times! That’s right, I forgot to divide by Pi. Wups. D:

I forgot about VectorToRadialValue. I did blitz through the material compendium but not everythings stuck and I guess that one just fell through the cracks.

Thanks for the advice about mips, I’ll keep it in mind.

---

<div class="post-metadata">

**Author:** ![TechArt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TechArt](https://forums.unrealengine.com/u/TechArt)\
**Post date:** [April 7, 2014, 10:21am UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/10 "2014-04-07T10:21:45Z")

</div>

Cool - good point about the tex2dgrad function

Feanix - np 😉

---

<div class="post-metadata">

**Author:** ![simonschreibt](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simonschreibt/32/947877_2.png) [@simonschreibt](https://forums.unrealengine.com/u/simonschreibt)\
**Post date:** [December 12, 2018, 9:58am UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/11 "2018-12-12T09:58:24Z")

</div>

Pietermans Website seems to be down so here is the material graph again. I also added UV Animation/Tiling:

[![](https://i.imgur.com/Bw09FQ5.gif) ](https://i.imgur.com/Bw09FQ5.gif)  
[![](https://i.imgur.com/bxT5cEP.png) ](https://i.imgur.com/bxT5cEP.png)

By the way: To avoid this ugly pixel line:

[![](https://i.imgur.com/hXkVsRS.gif) ](https://i.imgur.com/hXkVsRS.gif)

You can manually set to use always the highest mipmap. This will fix it. But careful: this is not good for performance nor quality when you see your texture from distance!

[Imgur](https://i.imgur.com/rCLjwIU.png)  
[![](https://i.imgur.com/9K4yZni.gif) ](https://i.imgur.com/9K4yZni.gif)

The reason is, that for choosing a mipmap, the graphic card looks at two neightbor-pixels and compares the UVs. If the coordinates are far from eachother, the engine chooses a smaller mipmap (because it seems that the polygon/pixels are far in the back of the scene). For us this means, that at the position where our texture “tiles” over the radial coordinates, there’s a big jump in uv-coordinates and because of that the engine chooses the smallest mipmap for those pixels.

---

<div class="post-metadata">

**Author:** ![Pendali](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pendali/32/765848_2.png) [@Pendali](https://forums.unrealengine.com/u/Pendali)\
**Post date:** [August 13, 2024, 2:45pm UTC](https://forums.unrealengine.com/t/polar-coordinate-material-function/1496/12 "2024-08-13T14:45:06Z")

</div>

Was Looking for this, what code is in the custom node named “atan2” ?

I tried something like this:

```auto
// Input: UV (U, V) - standard texture coordinates
// Output: Polar coordinates (Radius, Theta)

float2 UV = In.xy;

// Center the UV coordinates around (0,0)
UV -= 0.5;

// Compute the Radius
float Radius = length(UV);

// Compute the angle Theta
float Theta = atan2(UV.y, UV.x);

// Convert Theta from radians to [0, 1] range if needed
Theta = (Theta + PI) / (2.0 * PI);

// Output the Polar coordinates
return float2(Radius, Theta);

```

(Name the input “In”)

 ![Capture](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/e/2/1e28aad6d7e23de6f08ac38972aef6688358ad46.jpeg)  
 ![Capture 2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/a/73a83f150749fcf9a6655d88e5799f916cc81f0c.jpeg)
