首页 > 解决方案 > Godot - 我可以像素化一个节点(Sprite)吗?

问题描述

我可以在 Godot 中对 2D 节点(Sprite在我的情况下)进行像素化吗?我需要这样的东西:

![在此处输入图像描述

怎么做都没关系:使用着色器、代码或一些调整。任何帮助表示赞赏。

标签: spritegodotpixelate

解决方案


我自己想通了,确实很容易。我只需要一个着色器:

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节点,也许我会解决这个问题。


推荐阅读