为什么我的着色器在 Godot 编辑器中工作正常,但在运行时却不行?

问题描述 投票:0回答:1

我在Godot中的CanvasItem上写了一个着色器:

shader_type canvas_item;

void fragment() {
    vec2 distortedUV = UV;
    distortedUV.x += sin(distortedUV.y * 5.0 * TIME/100.0 + TIME) * 0.1;
    COLOR = texture(TEXTURE, distortedUV);
}

在编辑器中它看起来像这样:

但是当我运行游戏时,它只是缓慢地来回移动,幅度很小,看起来像这样:

这是为什么呢? 有关我的设置的更多信息: 这是在作为 Control 节点的子节点的 TextureRect 上。 这是一款像素游戏,因此设置如下。窗口尺寸为 360x640,并在运行时放大至 720x1280。使用 GPU 像素捕捉 == true。精灵是使用 2D 像素纹理预设导入的 .png。

glsl godot godot-shader-language
1个回答
0
投票

好吧,我正在回答我自己的问题:发生这种情况是因为着色器代码中有两次对

TIME
的调用。这将在编辑器和游戏之间呈现一致的效果。不知道为什么两个
TIME
调用会这样,但事实就是这样。

shader_type canvas_item;

void fragment() {
    vec2 distortedUV = UV;
    distortedUV.x += sin(distortedUV.y * 5.0 + TIME) * 0.1;
    COLOR = texture(TEXTURE, distortedUV);
}
© www.soinside.com 2019 - 2024. All rights reserved.