Mix voronoi with a texture

Hi,

I want to make this kind of effect in shader graph:

https://github.com/keijiro/KinoVoronoi

I want that each voronoi cells show the color of an image at the center of the voronoi’s cell.


I want that the cell in the A node have the color of the B node (uv from cell’s center)
Have you an idea on how to retrieve the center of the voronoi’s cell for the entire cell ?

Thanks

I finally found a way:

  1. Right click on Voronoi node and select “Show generated code”.
  2. Make a custom function node of this
  3. Found the center formula: Center = (offset + lattice + g) / CellDensity;

Here the full code of the custom function node:

float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);

for(int y=-1; y<=1; y++)
{
    for(int x=-1; x<=1; x++)
    {
        float2 lattice = float2(x,y);

        float2 sUV = lattice + g;
        float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
        sUV = frac(sin(mul(sUV, m)) * 46839.32);
        float2 offset = float2(sin(sUV.y*+AngleOffset)*0.5+0.5, cos(sUV.x*AngleOffset)*0.5+0.5);
        float d = distance(lattice + offset, f);
        float2 sign = (lattice + offset) - f;

        if(d < res.x)
        {
            res = float3(d, offset.x, offset.y);
            Out = res.x;
            Cells = res.y;
            Center = (offset + lattice + g) / CellDensity;
        }
    }
}
5 Likes

Hello @Racines
thx for your post it’s exactly what I want to test.
I’ve got just one pobs, nothings hapen when I select "Show generated code"on my Voronoi Node.
My project is HDRP with the 2020.1.5f1 unity version
thx for your reply

Hello @mrFrancois
On Unity 2019.3.13f1 this is working well, opening visual studio and show me the code.

I made a file of the generated code for you

6449262–722085–Voronoi.shader (4.6 KB)

Really thank for your kindness
It doesn’t work on my Unity 2019.3.4, but I’m on a macbook, maybe that’s the problem ?

For your file, I can read it on visual studio, but I don’t know how I can import it on my project or where ? I try to package it, to drag and drop on my scene …

Maybe I am using Windows.

What do you want to achieve exactly?

Like you, I try to recover the color behind the central point of the vorodoi to apply it to its same cell.
I’m a designer and I’m playing with Shader ans VFX to creat emotional experiences.
I uninstalled visual studio code to visual studio for mac. on Package manager the same.
But it still doesn’t work :slight_smile:
Thanx for your answers and your time, I will continue to explore the possibilities and keep you posted

Ok so if you want to recreate this then you can do what I explained in my original post: Mix voronoi with a texture - #2 by Racines

Here is a more detailed description of the steps:

  • Create a node “Custom Function” in shader graph

  • Click on settings icon

  • Add inputs

  • UV - Vector2

  • AngleOffset - Vector1

  • CellDensity - Vector1

  • Add outputs

  • Out - Vector1

  • Cells - Vector1

  • Center - Vector2

  • Select string in Type dropdown

  • Add a name in Name section

  • Past the code below in the Body section

  • In shadergraph use the Center ouput to retrieve the cells UV

float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
for(int y=-1; y<=1; y++)
{
    for(int x=-1; x<=1; x++)
    {
        float2 lattice = float2(x,y);
        float2 sUV = lattice + g;
        float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
        sUV = frac(sin(mul(sUV, m)) * 46839.32);
        float2 offset = float2(sin(sUV.y*+AngleOffset)*0.5+0.5, cos(sUV.x*AngleOffset)*0.5+0.5);
        float d = distance(lattice + offset, f);
        float2 sign = (lattice + offset) - f;
        if(d < res.x)
        {
            res = float3(d, offset.x, offset.y);
            Out = res.x;
            Cells = res.y;
            Center = (offset + lattice + g) / CellDensity;
        }
    }
}

MAN ! Girl ?
YOU SAVE MY DAY !!!
I owe you champagne :slight_smile:
Really thanks a lot for your time and your answers

You are welcome

Very nice.