glsl - How to apply fragment transformation after vertex transformation - Stack Overflow

Hey I'm using GLSL Shader inside Godot, I "glued" these 2 shaders. One "pixelate&qu

Hey I'm using GLSL Shader inside Godot, I "glued" these 2 shaders. One "pixelate" the TEXTURE on its local UV space and one displace thevertex in a sinusoid shape with TIMe (much like a "wind effect")

But the displacement of the vertex() method apply after the pixelisation of the fragment() I would like to pixelate after the displacement. Maybe in the screen space ? but I only want this texture to be pixelated not what is underneath (it's a png partly transparent).

How can I achieve this ?

shader_type canvas_item;

uniform float size_x = 16.0; // blocks by x direction
uniform float size_y = 16.0; // blocks by y direction
uniform float wave_speed = 1.0;
uniform float wave_amplitude = 8.0;

void fragment() {
    COLOR = texture(TEXTURE, vec2(floor(UV.x * size_x) / (size_x - 1.0), floor(UV.y * size_y) / (size_y - 1.0)));
}

float getWind(vec2 vertex, vec2 uv, float time) {
    return sin(time + uv.y) * wave_amplitude;
}

void vertex() {
    vec4 pos = WORLD_MATRIX * vec4(0.0, 0.0, 0.0, 1.0);
    float time = TIME * wave_speed;
    VERTEX.x += getWind(VERTEX.xy, UV, time);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744104833a4558678.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信