Page 1 of 1

How can I calculate rotated vertex position?

PostPosted: Fri Aug 24, 2018 4:49 am
by punkbot
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!

Re: How can I calculate rotated vertex position?

PostPosted: Fri Aug 24, 2018 2:04 pm
by Amplify_Borba
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!