Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Babyarm · May 23, 2021 at 08:32 AM · rotationshadershaders

Shadergraph: How do I get an object's rotation value inside of shadergraph? (HDRP)

Hello, I'm trying to add a rotational value to the "Rotate About Axis" node to offset my vertices positions relative to the object. I need to use the object's rotation.euler.y value to dynamically offset those vertices, but I can't seem to find a way to reference the object's rotation value inside of shadergraph? Right now I just have a float "Counter Rotation" in place of the rotation for testing purposes, but I need the shader to be able to dynamically plug in the object's y rotation value to compute the vertex positions.

Please help, thank you!

preview

1.png (11.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by andrew-lukasik · May 23, 2021 at 10:41 AM


Try multiplying {1,0,0} vector by InverseModel matrix and then plug resulting x and z components into atan2


shader graph inverse rotation euler angle y

Comment
Add comment · Show 13 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Babyarm · May 23, 2021 at 06:26 PM 1
Share

omg that worked perfectly! thank you so much! I was stuck on this part for so long and you just made my entire week!

Question: what exactly is the inverse model matrix, and would you $$anonymous$$d explaining what the math behind this formula is? I couldn't find too much documentation on what exactly the transformation matrix does but I'd love to learn more about it.

Thanks in advance!

avatar image andrew-lukasik Babyarm · May 24, 2021 at 07:58 AM 0
Share

what exactly is the inverse model matrix

Afaik Model matrix is more or less a transform.localToWorldMatrix and Inverse Model is just transform.localToWorldMatrix.inverse. So, role of this matrix is tell shader how every vertex of your mesh (or source file "model", as it was called 20 years ago) should be transformed to display it as rotated, scaled and positioned correctly in space. I proposed inverse matrix here only because you wanted to negate (or "inverse") the rotation.

math behind this formula

There is not that much to it, really. Atan2 is there to measure that angle in XZ plane. And because of how atan2 function works (angle 0 is {1,0} as input vector) I made sure to feed it the correctly oriented vector by multiplying {1,0,0} with this matrix (multiplication will rotate it and this rotation we want to measure here).

avatar image Babyarm andrew-lukasik · May 24, 2021 at 08:21 PM 0
Share

Awesome! That makes a lot of sense. Thanks for the explanation, I learned a lot!

Show more comments
avatar image kbkmn · Sep 24, 2021 at 04:10 PM 0
Share

Im trying to solve similar problem, but this method gives me rotation relative to 0,0,0. How do you get local rotation in shader graph? alt text

screenshot-2021-09-24-at-190438.png (148.5 kB)
avatar image andrew-lukasik kbkmn · Sep 25, 2021 at 04:23 PM 0
Share

Shader has no access to scene hierarchy data by default. If you want to change that you must pass this data manually via material property block.

avatar image kbkmn andrew-lukasik · Sep 26, 2021 at 09:09 PM 1
Share

I solved the issue by setting position column to zero in transformation matrix alt text alt text

screenshot-2021-09-27-at-000804.png (61.6 kB)
screenshot-2021-09-27-at-000848.png (319.7 kB)
Show more comments
avatar image nicmarxp · Dec 15, 2021 at 08:06 AM 0
Share

Amazing, this worked! I used this in 2D and had to change the split node B->B to use G->B instead, to make it work when rotating in Z. Also I had to change from Inverse Model to Model on the first node. Thank you!

avatar image andrew-lukasik nicmarxp · Dec 15, 2021 at 10:43 AM 0
Share

Hi. Ask this question as a separate thread, explain the situation, link here and we will figure it out.

avatar image nicmarxp andrew-lukasik · Dec 15, 2021 at 01:27 PM 0
Share

Thanks, i have no more questions. You might have seen my previous comment, but that was a mistake. :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

227 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Getting the forward position of an object in a vertex shader 0 Answers

Any idea how to get object rotation or transformMatrix in the vertex shader? 0 Answers

Shader doesn't work when object is inverted by axis 1 Answer

Grass shader sprite 2D 3 Answers

How to create a hole using a shader? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges