如何以非矩形形式裁剪精灵?
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您知道我们可以使用
UV
来获取坐标。由于公式有一些参数,让我们将它们添加为制服:
我们计算我们的公式:
这应该会产生从白色到黑色的渐变。
请记住编辑着色器参数。如果将它们保留为零,您将只能看到白色。
因此我们可以继续使用
discard
:这应该会给您想要的结果。
或者,让我们使用
step
这样我们就得到了黑白结果:现在我们用它来决定在哪里输出原始纹理以及在哪里输出透明度:
这也应该给你你的结果想。
附录:我没有注意到在你的例子中你已经按整个像素剪切了图像。您可以这样做:
在这里,我已经将方程的坐标用于以与纹理像素大小相匹配的离散步骤前进。
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.