GLSL Polar Coordinate Mapping Seam Issue

So I recently needed to map a texture into polar coordinates onto a full sphere but the sphere doesn’t actually become complete and there’s a seam between the end and start of the texture. I don’t know if I’ve made a mistake, or there’s some edge-case with touch designer glsl I’ve not accounted for.

Here’s what I have set up

I notice the seam issue when I zoom into the glsl top viewer, I’m really confused and not sure how this is even occurring.

The GLSL Code:

uniform float scale; // 0 > 1, just use 1 for now
uniform vec2 resolution;

out vec4 fragColor;

void main() {
    vec2 uv = gl_FragCoord.xy / resolution;
    uv = uv * 2.0 - 1;

    float r = length(uv) * (scale + .5); // jank scale fix for now
    float theta = atan(uv.y, uv.x);

    vec2 polarUV;
    polarUV.x = r / sqrt(2.0);
    polarUV.y = (theta + 3.14159) / (2.0 * 3.14159);

    vec4 color = texture(sTD2DInputs[0], polarUV);
    fragColor = TDOutputSwizzle(color);
}

Any help or advice is appreciated.

Thanks!

To update this, I don’t know if this is a ideal solution but what ended up working was setting input smoothness to nearest pixel for the GLSL Top.
~ Ariel

Hi there,

The reason the little line is visible is because the polarUV.y value goes from 0 to 1 and you’re using this as a ‘v’ coordinate in your texture() call. The texture() call needs uv coordinates that point in the center of the pixel if you don’t want it to interpolate with it’s neighboring pixels.
By default the glslTOP is set to ‘input Extend mode UV → Zero’. (GLSL tab). So the pixel at v=1 will be interpolated with a black pixel. You could set this to ‘hold’, this will brutely fix that problem but will also do this with your ‘u’ coordinate.

Another (more clean) option is to rescale your polarUV.y and move it half a pixel up. Something like this:

    polarUV.y = polarUV.y*(1.-uTD2DInfos[0].res.y) + uTD2DInfos[0].res.y*.5;

The uTD2DInfos[0].res is a predefined uniform that gives a vec4 of your input images: vec4(1/width, 1/height, width, height).
So I’m scaling the value with 1 less pixel and moving it half a pixel up.
(btw, also ‘resolution’ is predefined in uTDOutputInfo.res.zw, and uv as vUV.st)

Hope this helps.
Cheers,
Tim

1 Like

Always as awesome with your detailed replies, this has helped solve it significantly and taught me a lot.

Also thanks for letting me know about uTDOutputInfo.res & uTD2DInfos[0].res, really useful!

Many thanks,
Ariel

1 Like