Forums > Jitter

### Polar to Cartesian shader help…

May 18 2007 | 11:33 pm

Too much coffee is making me crazy, or.. well, maybe its not the
coffee. ITS MY BRAIIIINNNNNNNNNnnnnn.

I am attempting a Polar to Cartesian transform shader while fighting
off my brains attempts to kill me.

My thought is that I should be able to run cartopol shader and then a
poltocar and get basically my same output minus weird edge pixels
that the math messes up.

However, I get nothing of the sort. I am obviously missing something.
Ive looked at Wesleys poltocar code in the kaleidoscope shader
mentioned here (second result in google for polar to cartesian glsl
btw ;):

"
// polar to cartesian conversion
no = no+0.5*sizea;
"

from: http://www.cycling74.com/forums/index.php?
t=msg&goto=61224&rid=0&S=a3d1f2ed3cea8b2a7123521617329dc9

The following is my fragment program in GLSL.

What am I doing wrong?
———–

// define our rectangular texture samplers
uniform sampler2DRect tex0;

// define our varying texture coordinates
varying vec2 texcoord0;
varying vec2 texdim0;

void main (void)
{
const float pi=3.1415926;

vec2 point = texcoord0/texdim0; //normalize coordinates

vec2 normCoord = vec2(2.0) * (point – vec2(0.5)); // center point in
texture

float r = length(normCoord); // find hypot – seems nicer than other
method.
float phi = atan(normCoord.y, normCoord.x)+pi;

vec2 frompol = vec2(r* cos(phi), r* sin(phi)); // this should be
correct, yet I get an incorrect output ?

vec2 outputCoord = (frompol/vec2(2.0) + vec2(0.5)) * texdim0; //
unnormalize and remap to reg rect tex coords

gl_FragColor = texture2DRect(tex0, outputCoord);

}

v a d e //