kernel DotPixelator < namespace : "micron_developers"; vendor : "micron_developers"; version : 1; description : "Pixelates an image to little dots"; > { input image4 src; output pixel4 dst; parameter float radius< minValue: float(1.0); maxValue: float(20.0); defaultValue: float(5.0); >; parameter float padding< minValue: float(0.0); maxValue: float(1.0); defaultValue: float(0.25); >; parameter int snap_to_pixels < minValue: 0; maxValue: 1; defaultValue: 0; >; parameter int anti_alias< minValue: 0; maxValue: 1; defaultValue: 0; >; void evaluatePixel() { // flash-compat dependent eval float cell_size; float2 offset; float half_radius; cell_size = radius * (1.0 + padding); half_radius = radius/2.0; if (snap_to_pixels == 1) { cell_size = floor(cell_size); half_radius = floor(half_radius); } // kernel offset = float2(cell_size/2.0); // snap to nearest cell; float2 origin = floor(outCoord() / cell_size) * cell_size; // find cell center float2 center = origin + offset; // calculate opacity float alpha; if (anti_alias == 1) { alpha = 1.0 - clamp(length(outCoord() - center) - half_radius, 0.0, 1.0); } else { if (length(outCoord() - center) < half_radius) { alpha = 1.0; } else { alpha = 0.0; } } // render dot dst.rgb = float3(alpha) * sampleLinear(src, center).rgb; dst.a = 1.0; } }