Use vertex color of the nearest vertexx

Hello!

I am trying to make a shader that uses the vertex color of the nearest vertex to basically make a Voronoi diagram via a shader. I’ve actually achieved this by writing a geometry shader that essentially passes the info of the three vertices in a triangle down to the fragment shader which then calculates the closest vertex. I will put the code for this as an attachment in case you’d like to see it.
Here is the result. I put on wireframe so you can see where the vertices are. As you can see, the color is determined by the closest vertices’s color, with no smooth interpolation between them.

However, my problem is that overwriting the geometry shader seems to overwrite smooth shading, and all the triangles will be flat shaded. This is not what I want unfortunately.

My main question is this: Does anyone know how to get this same affect while still preserving smooth shading? Either by avoiding to use the geometry shader or somehow implementing smooth shading with the geom shader. Any ideas would be appreciated!

As a little more background: I am trying to do this for a quite large procedural mesh and adding extra geometry to make these hexagon shapes via geometry significantly increases the run time of generating these meshes. A shader like this would make it much more efficient.

Alternative Solution:
I’ve tried just using this shader to create a cubemap, and using that cube map in a separate shader without geom shader to preserve the smooth shading. Unfortunately this has the problem that it looks horribly pixelated. I’m not sure if I’m doing something wrong or if this level of detail is not possible with this cubemap approach but if someone could explain how I could get much less pixilation in this approach that would also solve my problem.
Example of the pixilation on this cubemap approach:

e: in case it’s not clear, I use a cubemap because these meshes i’m generating are spherical and will be planets in game. So I put a camera in the middle render to a cubemap.

6483487–728461–Voronoi.shader (3.52 KB)

Your geometry shader is explicitly overriding the vertex normals with a flattened normal. Just don’t do that. Use the vertex’s original normal, the same way the shader is already using the original everything else.

Wow I can’t believe it’s that simple, I feel like a fool, it was copy+pasted+modified code and I’m new to writing shaders. I thought if I didn’t have that then there’d be no normals at all :confused:

Thank you very much!