Author Topic: Pixel Processor - Mapping a square texture to a circle grid (see example)  (Read 136 times)

As usual, this is coming from a newbie. So, any help is appreciated! I've been learning the Pixel Processor well enough to get by, but this problem has me stumped. I am trying to transform a square texture to disc, and found a formula that works in JavaScript (the source page has an excellent demo) but I'm doing something wrong with it in Pixel Processor.

Here's an illustration of the concept:

Edit: I found a linkable image.

Here's the math:

This is the graph:

I suspect one of my problems is defining the center (I tried extending the range to -1 to 1, but I still get a slightly warped banding)... oh, and the Pixel Processor contains:

I can move all this to a new .sbs and attach it, if needed. Right now, it's in a graph with other PP experiments. Again, any help is welcomed. Assuming the math is right, the problem is how I'm handling it in Designer. My search for help online mostly turned up equirectangular mapping (none of which are problem free, trading off distortion at the poles with worse distortion--mostly stretching--along the prime-anti-prime meridians). The square-to-circle method I'm working on is part of a workaround I could feed into a polar-to-cartesian (or two) I'll put up on share, assuming I can get it to work.

Last Edit: April 17, 2019, 10:04:56 pm
David Roberson
Freelance 2D|3D Artist

Auburn CA, United States of America

You need the inverse function I'm afraid.
I tried doing what you're doing a while ago and made the exact same mistake.

Some software can 'push' pixels to a new location, or at least interprets input as if that is happening. Most programming languages apparently work by 'pushing', but the pixel processor 'pulls' pixels from a location.
The function you're showing will nicely map a circle to a square though.

I found this inverse function, which did the trick:

I was just getting ready to put my version on substance share actually, but I modified the functions to include interpolation, so it's a bit different. I'll post it here when I get home if you want to take a look.
Edit: attached my version
Last Edit: April 17, 2019, 08:06:14 pm
Esger van der Post.
Game design student and texturing addict.

Thanks, Eggfruit! I'm happy to hear that someone else has worked on this same effect! I think I've been searching for a way to 'push' pixels since I started using SD, to come up with ways to stretch, smudge or even scale areas using an intensity map or vector map. Those are all on my to do list, assuming I can find a way to 'pull' those pixels.

I did come across references to squircles in my research, but in the ones I looked at the math seemed more complicated than the formula I'd already found. It seems like the solution to a lot of the things I've tried have been the inverse of what I expected to work. I'll study the page you linked, and I'm going to take a look at your version and see what I can learn. I like the idea of throwing in the interpolation, so I hope you get that to work.

Edit: Well, it sort of does the trick. Of course, the result is the exact opposite of what I was going for. I really need it to pull the corners in, so that the tile edge aligns with the circumference of the circle. Run that through a Polar to Cartesian, scale it down by half, duplicate and flip vertically, then blend the top and bottom halves and you have a unit square texture properly mapped to a unit sphere.

I've managed to get there using a complicated set of nodes, but it ought to be possible to get all of this done inside a Pixel Processor. I know I'll keep trying; it's become an obsession!
Last Edit: April 17, 2019, 09:52:35 pm
David Roberson
Freelance 2D|3D Artist

Auburn CA, United States of America