Stencil buffer or something like

Hi

Thanks a lot it’s very useful. I tried to do this code. The result is

So, as I understood something wrong with offset for colour choose.

I’m not clearly understood what is Width varible. Number of colours, but with this  

 rect:setFillColor(1 / Width)

Thanks a lot for your code. Will investigate and try to change :slight_smile:

Regards

Whoops, sorry. Change each instance of “minTextureFilter” to “magTextureFilter”. I did notice the colors were off, but figured it was a reasonable start. Just tried now with the other key and it seems to work.

Width is the maximum number of colors in the “color set”. I rounded it up to 4, though as I say in the comments maybe a non-power-of-2 would be okay. In Corona’s shaders, texture coordinates will have been mapped to the [0, 1] range, so pixel #1 is found in the interval [0, 1 / Width], #2 in [1 / Width , 2 / Width], etc. Nearest filtering keeps these from blending together.

By assigning 1 / Width as the “color”, we’re basically assigning the per-object density. Additive blending makes these layer on as they cross the same spot. Rather than containing conventional color information, the canvas contains these densities; “denser” parts have a further offset into the color set.

Off-hand I don’t know if it’s wise to read right at the color set’s pixel boundary; non-power-of-2 widths might have issues, for instance. Maybe subtracting half a pixel would be more robust. This could be string.format()'d into the shader source using Width , or added as a shader parameter.

Yep it’s working. Thanks a lot. :D  :smiley:

Will try to do it dynamically with three colours and circles like in first post. 

Thanks