Hi everyone. I hope someone can give me an example of finding the angle between two vectos using arctangent 2 in shader graph. I would like to have the result in degree. This is for a billboard shader. Really appreciate your help!
Did you try searching for it in the nodes?
Wait, why? Why would you need degrees specifically?
Actually radians is fine too. But the thing is I don’t really know how to get the angle between two vectors in shader graph and that angle should have a range of 0-360 degree. So hoping to get some help here.
You don’t need to use any angles to make a billboard shader. You can grab base vectors from camera or store them as parameers, then you can build object matrix using cross products.
You also can’t really measure angle with atan, and would need acos. And acos goes to 180 degrees only.
To build a billboard matrix, you need Up vector, camera position, object position. Up vector could be extracted from thecamera (if it is screen aligned billboard), or it could be pointing up, if iti s something like a tree or grass tile.
First you take vector from object to cam. With cross product right = Vector3.Cross(up, vecToCam)
, you’ll get a vector pointing right. Using another cross product you can get a vector pointing forward forward = Vector3.Cross(up, right)
;
When you have position (of the billboard), up, right and forward, that forms a transformation matrix for that object.
No angles invovled.
Hey. You are awesome! Thank you so much. That’s nice and clean. Don’t know why I keep thinking using angle and rotation.
Using atan2 function is also a way to go.