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

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
vec2 no = vec2(-cos(foldtheta)*radius, -sin(foldtheta)*radius);
no = no+0.5*sizea;


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

float r = length(normCoord); // find hypot – seems nicer than other
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 //

Viewing 1 post (of 1 total)

Forums > Jitter