Rotating vertex position and normals around local Y axis

Node-based Shader Editor

Rotating vertex position and normals around local Y axis

Postby TripleOneGames » Mon Dec 11, 2017 4:21 am

Okay, so this question is probably a bit advanced. I'm looking for a way to rotate a mesh around the object origin's Y axis using vertex offset while preserving normals. I need to preserve normals so that the metallic object reflects the environment accurately.

The reason is for optimized performance. I have quite a few coins in my scene in Unity that are always rotating. I'm not sure if I would get a performance boost by using the shader instead of just rotating the objects transforms. Is there a node for this, or am I going to have to do some trigonometry (I'm only "pretty good" at math at math)? I've searched the internet and found nothing really useful. Any help or tips are appreciated.
TripleOneGames
 
Posts: 6
Joined: Mon Dec 11, 2017 3:57 am

Re: Rotating vertex position and normals around local Y axis

Postby Amplify_Borba » Mon Dec 11, 2017 3:21 pm

TripleOneGames wrote:Okay, so this question is probably a bit advanced. I'm looking for a way to rotate a mesh around the object origin's Y axis using vertex offset while preserving normals. I need to preserve normals so that the metallic object reflects the environment accurately.

The reason is for optimized performance. I have quite a few coins in my scene in Unity that are always rotating. I'm not sure if I would get a performance boost by using the shader instead of just rotating the objects transforms. Is there a node for this, or am I going to have to do some trigonometry (I'm only "pretty good" at math at math)? I've searched the internet and found nothing really useful. Any help or tips are appreciated.


Hello TripleOneGames, thank you for getting in touch and for your support!

We don't have a specific node for rotating a mesh, but we're sharing a simple shader sample as an attachment to this post that shows how this can be achieved, for your convenience.

SampleRotate.zip
(2.06 KiB) Downloaded 437 times


There is a limitation though, when reshaping your mesh using Vertex Offset, the normal direction of the surface will not follow along. This is simply because normals are stored in the mesh, and not computed in real-time.

It's not an easy task to recalculate Normals on a vertex shader because you need to have vertex neighbor information to fully calculate the new normal vector which is something you only have on a geometry shader.

There are a couple of ways to overcome this, you can check this post which does it by calculating a new binormal and tangent vectors, or our included sample: AmplifyShaderEditor/Examples/Official/VertexNormalReconstruction

Let us know if this information was useful and if you have any further questions, we'll be happy to help!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Rotating vertex position and normals around local Y axis

Postby TripleOneGames » Tue Dec 12, 2017 9:22 am

This does what I need, thanks! I did manage to get the normals working. Or at least I was able to achieve the desired effect. I did a similar thing to what was done in an Unreal forum:

https://answers.unrealengine.com/questi ... norma.html

I just plugged the vertex normal into the same node structure instead of the vertex position and didn't subtract it from the final product. Which inverts it I guess. Anyway, here is the shader in case anyone is interested:

SampleRotateAndNormals.rar
(2.65 KiB) Downloaded 300 times


Thanks again for the help and great customer service! Cheers!
TripleOneGames
 
Posts: 6
Joined: Mon Dec 11, 2017 3:57 am

Re: Rotating vertex position and normals around local Y axis

Postby Amplify_Borba » Tue Dec 12, 2017 10:00 am

TripleOneGames wrote:This does what I need, thanks! I did manage to get the normals working. Or at least I was able to achieve the desired effect. I did a similar thing to what was done in an Unreal forum:

https://answers.unrealengine.com/questi ... norma.html

I just plugged the vertex normal into the same node structure instead of the vertex position and didn't subtract it from the final product. Which inverts it I guess. Anyway, here is the shader in case anyone is interested:

SampleRotateAndNormals.rar


Thanks again for the help and great customer service! Cheers!


Glad to know you were able to achieve the desired effect, and thank you for sharing both the shader and additional information with the community!

Have you had the chance to rate and review Amplify Shader Editor? It would be awesome if you could share your experience with the Unity community, the Unity Asset Store thrives on user interaction and direct feedback.

Every bit helps, your feedback is extremely valuable to us!

Don't hesitate to get back in touch if you have further questions, we're always happy to help!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 0 guests

cron