2
$\begingroup$

enter image description here Blue normals need to be copied to the vertex color.

I have some low-poly models that need to be flat shaded so I want the vertex normals to be the split normals, but for custom shaders in Unity, I also need the smooth normals that are used for smooth shading. Since the vertex color channel is not used for anything, I basically want to store the smooth normals in the vertex color channel. This way the model can be flat shaded in unity, but I can still use the smooth normals for shaders by accessing the vertex color.

I found a plugin from Philipp Seifried that seemed to be what I was looking for, but it didn't do what I was looking for (https://github.com/Philipp-Seifried/Blender-Normals-To-Vertex-Color/blob/master/normals_to_vertex_colors.py) I don't have any experience with making plugins but from what I can guess the code copies the split normals to the vertex color channel?

Is there a way to do this?

$\endgroup$

1 Answer 1

4
$\begingroup$

You can use Geometry Nodes for that, with a very simple node tree:

When you apply the Geometry Nodes modifier in the modifier stack, the new color attribute sm_norm will appear.

$\endgroup$
5
  • $\begingroup$ I'm thinking, you might need to remap the normal from -1...1 to 0..1 range, but I'll wait for OP to eventually report a problem. $\endgroup$ Commented Feb 14 at 16:13
  • $\begingroup$ This gives me a better result but still not perfect. The remapping to 0 to one range makes sense, would i also need to swizzle the cooridinates for the unity axis? How could this be done? We are very new to geometry nodes. $\endgroup$
    – Benni
    Commented Feb 14 at 16:18
  • $\begingroup$ @Benni the normals here are in object space, so no swizzling is required at least as long as you don't rotate your object as a part of exporting process... The normals in tangent space would simply be all $<0, 0, 1>$… As for remapping from $[-1, 1]$ to $[0, 1]$ you could use "Map Range" in Vector mode or just Vector Math: Multiply Add, multiply by $<0.5, 0.5, 0.5>$ and add also $<0.5, 0.5, 0.5>$ $\endgroup$ Commented Feb 14 at 18:13
  • $\begingroup$ Sorry to come back this late. We did the mapping but I still have an issue when I use a outline shader on these objects. The shader moves the vertices out on the normals or in this case the color since that is where the normals are. The problem is all smooth normals in the color channel seem to point in the same direction. Any Ideas? $\endgroup$
    – Benni
    Commented Feb 19 at 8:29
  • $\begingroup$ I solved it kind of. I had to remap the values back to [-1,1] in the shader ...well, obviously. It is still a little bit weird because doing (color * 2 - 1) did not give me a perfect result and some places did not behave correctly for my outline. However doing (color * 2 - 1.5) did give me good results. $\endgroup$
    – Benni
    Commented Feb 26 at 12:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .