shaderlib: Implement a simple pixelate function (effects.gdshaderinc), examples/hsv.gdshader -> color_and_pixelate.gdshader; implements #30

This commit is contained in:
ChaoticByte 2025-01-08 19:40:36 +01:00
parent 6c48c9fe72
commit 4d12ad4432
No known key found for this signature in database
4 changed files with 30 additions and 10 deletions

View file

@ -0,0 +1,14 @@
// pixelate by lowering uv resolution
vec4 pixelate(sampler2D tex, vec2 uv, float resolution_x) {
vec2 texture_size = vec2(textureSize(tex, 0));
vec2 ratio;
if (texture_size.x > texture_size.y) {
ratio = vec2(texture_size.x / texture_size.y, 1.0);
}
else {
ratio = vec2(1.0, texture_size.y / texture_size.x);
}
vec2 r = ratio * resolution_x;
return texture(tex, trunc(uv * r) / r);
}