Rotate towards using Vertex Offset

Node-based Shader Editor

Rotate towards using Vertex Offset

Postby DuvE » Fri Jul 20, 2018 3:38 pm

Hi,

The new version of ASE bring some awesome nodes, like "Rotate About Axis" and it helped me a lot. I want to make particle or non-particle shader that will rotate the mesh towards the player. Currently, I discovered how to just instantly rotate the whole mesh, even particles towards a player or other transforms. But I need to rotate is slowly, using mask or values, it cannot be done with my current method (https://prnt.sc/k8xflc), found this method here (https://realtimevfx.com/t/unity-5-5-5-6 ... tream/2328).

Is there any way to slowly rotate mesh towards another transform, from one rotation to another? Like in Unity functions "RotateTowards" or "Quaternion.LookRotation + Quaternion.Lerp" or something similar. For now, I can think only of two methods.



First method: Using Lerp, but I need to calculate the current and desired rotations, maybe there are some nodes that will help me with this? Basically, I need to convert Quaternion.LookRotation to the shader code, I think...

Second method: Using "Rotate About Axis" node to rotate mesh towards the player, but for that, again, I need to somehow calculate how much and on which axis I need to rotate it.
DuvE
 
Posts: 43
Joined: Thu Nov 23, 2017 6:46 pm

Re: Rotate towards using Vertex Offset

Postby Amplify_Borba » Fri Jul 20, 2018 4:52 pm

Hey there!

It's definitively possible to achieve this via shader through the second method you've suggested, but you'll still need to resort to some scripting in order to get the player's position and pass it into the shader, which will then calculate the Rotation Angle that you will pass into the 'Rotate About Axis' node.

We have a sample that can help you achieve this, the OrientationBasedSprite, which calculates the angle you need through the "Angle From Position" setup inside the Shader Function. Do note that you'll have to pass the property with the player's position vector to the B input of the Subtract node, effectively replacing the 'World Space Camera Pos' node, so that you get the correct Rotation Angle!

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

Re: Rotate towards using Vertex Offset

Postby DuvE » Sat Jul 21, 2018 3:34 am

Thx, this samples helped, but still I have one issue.

In the samples, the rotation is present only on the Y-axis. I tested it and it worked fine. But for a full rotation, I need to rotate on 2 axes, Y, and Z.

I did this setup - https://prnt.sc/k94g9t and it rotates object towards another transform in 3D on 2 axes. However, I think I'm doing it terribly wrong. Because of this fix and rotation is not always optimal, sometimes from certain positions object can make 360-degree twist before it stops.

Is this method correct, I'm just not sure about it, maybe there is a better one? Also, for particles this rotation work only when they are not rotated via ParticleSystem itself. But for now I need to be sure, I'm using correct method for 3d rotation towards another transform.

PS: Shader included if screenshot is not visible
Attachments
AFP.7z
(2.9 KiB) Downloaded 197 times
DuvE
 
Posts: 43
Joined: Thu Nov 23, 2017 6:46 pm

Re: Rotate towards using Vertex Offset

Postby Amplify_Borba » Mon Jul 23, 2018 3:34 pm

Thank you for providing a sample along with additional details, we'll investigate the shader as soon as possible and will get back to you with our findings.
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: Rotate towards using Vertex Offset

Postby DuvE » Fri Jul 27, 2018 7:58 am

Hi,

Thanks, but don't need to rush. :D

I have one more question, I'm using EXR textures which stores each vertex position over time for morph mesh from one shape to another. And of course, these EXR textures have negative values, they work fine in Linear rendering, but in Gamma rendering Unity cannot read negative values from EXR texture. I've tried some nodes like (Gamma to Linear and Linear to Gamma) but they didn't help.

This question is not really ASE related, but maybe you know the solution how to fix this issue?

The morphing looks like this:

Image

And the texture like this:

Image
DuvE
 
Posts: 43
Joined: Thu Nov 23, 2017 6:46 pm

Re: Rotate towards using Vertex Offset

Postby Amplify_Borba » Fri Jul 27, 2018 2:26 pm

Unfortunately, EXR is beyond the scope of the editor, so I'm afraid I can't provide any useful insight regarding this last question. What kind of information did you find on this topic so far?
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 43 guests