How to map normals to voronoi texture cells

https://www.reddit.com/r/blenderhelp/comments/1ghzxb0/how_to_map_normals_to_voronoi_texture_cells/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

Any help you can give here or on reddit would be appreciated, thanks.

Hmm,
no idea what you are after (strange mapping) but if you want the voronoi colours to change the normals you could do something like this.

Iā€™m trying to take the center point of each voronoi cell, sample the normal of the object at that point and colour the whole cell that colour.

Something like this?

Edit
Not quite a solid colour though

3 Likes

Thatā€™s almost an exact replica of my second example image on reddit. It is block colour as intended, however, I want to be able to manipulate the voronoi and have the colours still be right for the normals. If I change the mapping on the voronoi to anything but object or normal (stretch it any way etc) the colours get messed up.

1 Like

Well the way you formulate your intention its not possible, no. You cant sample the normal in a shader and propagate it to other pixels. Thats not possible by the way shaders work.

1 Like

Can I achieve the exact same effect through other means? Iā€™ve looked into using geometry nodes and doing the voronoi there, but then the voronoi is tied to the vertices and therefore is quite low res.

Not really, youā€™d have to bake the normals in one pass and composite

I am not sure what 3d shape we are really talking about, its not possible if your mesh isnt aligned to the voronoi cells, but if just split the mesh per voronoi cell and store the normal as attribute.

Sorry I did not see that read more button :sweat_smile:

I donā€™t understand the purpose of this shader.

if you want to transform voronoi cells into angle, then into normal map, itā€™s possible:

Thatā€™s going in the right direction, but with normal maps, youā€™re adding normals to the existing geometry normals. I donā€™t want to add. I basically want to smear the normals into cells, but I want the cells to be stretched. Iā€™ve been told so far on here itā€™s not possible, but I feel like there must be a way to get this effect. Perhaps if voronoi textures werenā€™t even used, I donā€™t know.

Does anyone know if this is possible with OSL?

For doing it with OSL, you need to know exatcly what you want to doā€¦
I confess that after reading all your posts, I still donā€™t have a clear idea of what youā€™re trying to achieve.

Just to get things clear: Do you want each cell to instead of a color, to output a normal vector (maybe the normal vector at the center of each cell)?
Is that it?

4 Likes

Yes, essentially. Usually you could do this by just plugging the normal output of a geometry node into the vector input of the voronoi, but I want to have a different kind of mapping for the cells, but still retrieve the normal from the center of those mapped cells.

I donā€™t know how you isolate the cells and their center to sample the normal at that position on the geometry :confused:

Youā€™ll need to use a 2D voronoi for this, and UVmapping as youā€™re vector space.
This is because, having a 3D voronoi will produce cell centers that arenā€™t on the objects surface, and that makes a cell to have multiple possible normals to choose from.
Youā€™ll also need to bake the normal map (object space) into a texture. This is because you cannot ā€˜jumpā€™ from one sample position to another without crampling your shader completly, and you need to be able to sample a specific coordinate, and thatā€™s easy with texture files.

Then you can just use a setup similar to this one:

1 Like

Thatā€™s cool if that works with manipulating the UV map too. Unfortunately it doesnā€™t work for what i want to do because Iā€™m going to be animating the W value of a 4D voronoi.

It would be cool if there was some way to apply the voronoi texture like a filter on an image, you map the voronoi and then the image with itā€™s own mapping is smeared into block colours for each cell.

I donā€™t know if thatā€™s possible with shader nodes or if that is even something possible in compositing. My best guess would be that OSL could provide the customisability needed to achieve such an effect, but Iā€™m not sure.

Itā€™s not technically Voronoi, but the Kuwahara filter in the compositor allows you to mostly do this. What you want to do isnā€™t possible by any method, but this will allow you to animate the cells, at least

There is no real difference between OSL and other Shading Languages in this regard. You cant sample the normal of distant values.

Geometry nodes give you in principle one more level of indirection, but they work on vertex data not pixels. So get your idea to align with that if thats what you want.

You need a mesh that aligns with your voronoi. You can then use a finer mesh version it to approximate your initial shape better in a next step, but still its not pixelbased. And the normal updating is in this case in the geometry nodes setup.

3D cells will just break any logic youā€™re trying to formulate (4D is just 3D with the random factor having itā€™s own dimention).
You can use a 2D voronoi and drive the randomness with a third dimentionā€¦ But for that youā€™ll need to use OSL, as we donā€™t have that texture builtin.

Thatā€™s the sameā€¦ In my example I just used the baked normals but you can plug any image into it:

And to be honest, if you want a more concrete solution for your problem, you shouldnā€™t hide any details from us. What would be the purpose of such shader? Where are you planning to use it, in what context?
In my experience, anytime that someone occludes the final objective when asking a fuzzy question, results in pure confusion and misunderstandings.

1 Like