// #include //ly.img.cesdk/shader/common/ubq_constants // Inputs uniform shader image; uniform float2 imageSize; uniform float dots; uniform float size; uniform float blur; half4 main(float2 coord) { float2 uv = coord / imageSize; float dotSize = 1.0 / dots; float2 samplePos = uv - mod(uv, dotSize) + 0.5 * dotSize; float distanceFromSamplePoint = distance(samplePos, uv); float4 imageColor = image.eval(samplePos * imageSize); float4 backgroundColor = float4(0.0); // Adjust blur value to avoid sharp transitions between image color and background color. // Reasoning: when both lower and upper edge values are the same, smoothstep no longer provides // a gradual transition between them (either immediatelly returs 0 or 1). // This causes mix() to output imageColor or backgroundColor instead of doing a linear interpolation between them. float adjustedBlur = max(blur, EPSILON); float4 color = mix(imageColor, backgroundColor, smoothstep(dotSize * size, dotSize * (size + adjustedBlur), distanceFromSamplePoint)); return color; }