我可以在 Godot 中对 2D 节点(Sprite
在我的情况下)进行像素化吗?我需要这样的东西:
怎么做都没关系:使用着色器、代码或一些调整。任何帮助表示赞赏。
我自己想通了,确实很容易。我只需要一个着色器:
shader_type canvas_item;
uniform float size_x = 32.0; // blocks by x direction
uniform float size_y = 32.0; // blocks by y direction
void fragment() {
COLOR = texture(TEXTURE, vec2(floor(UV.x * size_x) / (size_x - 1.0), floor(UV.y * size_y) / (size_y - 1.0)));
}
fragment
函数的内部是放大UV
,使用四舍五入floor
并缩小结果。上面的图像(在问题中)被像素化为 32x32 大小,使用此着色器后,Sprite
看起来就像图像示例中的样子。
PS它不适用于GUI节点,也许我会解决这个问题。