Browse

HexPixelate

by Mewatools

Pixelates image using an hexagonal pattern. The size of the pixel is adjustable.

Go To User Guide

Likes: 1

Source Code
// Brief: Pixelates using an hexagonal pattern
// from: https://www.shadertoy.com/view/wsSyWR

shaderSource = "
    vec2 hexagon(vec2 uv)
    {
        uv *= vec2(0.577350278, 1.0); // hexagonal ratio
        float z = clamp(abs(mod(uv.x+floor(uv.y), 2.0)-1.0)*3.141592653-1.047197551, 0.0, 1.0);
        uv.y = floor(uv.y + z);
        uv.x = (floor(uv.x*0.5 + mod(uv.y, 2.0)*0.5) - mod(uv.y, 2.0)*0.5 + 0.5)*3.464101665; // convert back from hexagonal ratio
        return uv;
    }

    void mainImage(out vec4 fragColor, in vec2 texCoord)
    {
        vec4 tex = texture2D(iChannel0, hexagon(texCoord * pixelCount)/pixelCount);
        fragColor = vec4(tex.rgb, 1.0);
    }";


node = ShaderNode( shaderSource, "HexPixelate" );
node.addShaderInput("iChannel0");

uiControl = node.addFloatControl("pixelCount", 120);
uiControl.setName("Pixels");
uiControl.setStep(0.1);
uiControl.setRange(3, 1024);

node.finishAdding();
File Details
  • Last Update: November 24th, 2020
  • Category: Filter
  • License: CC0