I'm trying to cut sprites in non-rectangular forms, I found this for angled cutting but is there a way to crop if an equation is given?
for example the equation of an oval (x−h)^2/a^2 + (y−k)^2/b^2=1
would crop as such:
I'm trying to cut sprites in non-rectangular forms, I found this for angled cutting but is there a way to crop if an equation is given?
for example the equation of an oval (x−h)^2/a^2 + (y−k)^2/b^2=1
would crop as such:
I'll asume you are aware that we can work with
UV
for the coordinates.Since the formula has some parameters, let us add them as uniforms:
And we compute our formula:
This should result in a gradient from white to black.
Remember to edit the shader parameters. If you leave them at zero you will see only white.
So we can go ahead and use
discard
:This should give you the result you want.
Alternatively, let us use
step
so we get a black and white result:And now we use that to decide where to output the original texture and where to output transparency:
And this should also give you the result you want.
Addendum: I had not payed attention that in your example you had cut the image at whole pixels. You can do that like this:
Here I had made the coordinates uses for the equation advance at discrete steps that match the size of the pixels of the texture.