How can I calculate rotated vertex position?

Node-based Shader Editor

How can I calculate rotated vertex position?

Postby punkbot » Fri Aug 24, 2018 4:49 am

Hi all! I'm working on a simple wind shader that moves (rotates across axis) the vertex position offsets using noise.

I've gotten the wind to look nice with grass, which all faces front, but it doesn't work right with other meshes, since they can be rotated arbitrarily. I realized that since I'm basing the wind movement on vertex position in object space, if my objects are rotated, the wind movement is rotated too (since rotation is not taken into account). I'm wondering if there is a way to adjust the vertex position based on the object's rotation, so that the wind movement always goes the same way no matter the object's rotation?

Something like, multiple the wind vector by the object's rotation? Or rotate the input vertex position by the object's rotation so that the output is adjusted? (not sure how to do either).

I am using
Code: Select all
Graphics.DrawMeshInstanced
to draw the meshes.

This is my "wind vertex position" function which outputs wind-adjusted vertex offset:

https://www.dropbox.com/s/qgubhmpe7isoilp/Screenshot%202018-08-24%2000.39.46.png?dl=0

This is an example of a simple shader using said function:

https://www.dropbox.com/s/s46trlthq1i472o/Screenshot%202018-08-24%2000.39.40.png?dl=0

Thank you for your help!
punkbot
 
Posts: 1
Joined: Fri Aug 24, 2018 4:41 am

Re: How can I calculate rotated vertex position?

Postby Amplify_Borba » Fri Aug 24, 2018 2:04 pm

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

The Local Vertex Offset port, such as the name implies, is in object space, so in this case you have to adapt the wind vector from world to object space.

You can use our Transform Direction node to achieve this, just make sure that the Normalize parameter is active.

Image

Please let me know if this helps, thanks!
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 27 guests

cron