【问题标题】:Godot - can I pixelate a node (Sprite)?Godot - 我可以像素化一个节点(Sprite)吗?
【发布时间】:2021-03-05 07:39:57
【问题描述】:

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

如何做到这一点并不重要:使用着色器或使用代码或进行一些调整。任何帮助表示赞赏。

【问题讨论】:

    标签: sprite godot pixelate


    【解决方案1】:

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

    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 看起来就像在图像示例中一样。

    P.S.它不适用于GUI节点,也许我会解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-31
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-27
      相关资源
      最近更新 更多