admin管理员组

文章数量:1396092

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);
}

本文标签: glslHow to apply fragment transformation after vertex transformationStack Overflow