Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Kiloblargh · Oct 17, 2013 at 08:10 PM · rotationbillboard3dtextvertex shader

Rotate a mesh on world y axis using a CG vertex shader?

I have a bunch of 3d textMesh objects, each with a single letter on a single quad. What I am trying to do with them is not exactly billboarding but the same idea: Putting the letter facing upward, then rotating it on y so its base is facing the camera, and tilting it up 10º on its local x axis to angle toward the camera a little more.

This works fine with a script that goes through every letter object every frame and says transform.LookAt (a world point below the main camera) but I know it is possible to do the same thing inside the shader and it would be much faster.

I'm comfortable enough with CG shaders now to do most of the color stuff I want to do, but I don't understand all the model view projection matrix arcana and how they can be used to move verts around.

Comment
Add comment · Show 1
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 Kiloblargh · Oct 17, 2013 at 08:40 PM 0
Share

I found this example of rotating vertices around each axis with sine time, in a surface shader, but I still can't figure out from there how to achieve something like "Transform.LookAt" in CG.

1 Reply

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

Answer by Owen-Reynolds · Oct 18, 2013 at 12:09 AM

Yes, the modelView matrix is tricky to understand. Very, very roughly (I have done similar with non-Unity shaders, but it's been a while):

Grab the 3DText shader (Font.shader.) We know that shows 3DText, and luckily, it has a vertex shader in it. Switch the material for your textMeshes to this. Change the vert shader to apply only the world position, but not the rotation. That will put the object in the right spot, but leave it in it's "natural" rotation, which is probably facing the camera. Then look up "rotation matrix" (should be 3x3) and set up one for the 10 degree tilt. Arg, then apply the perspective matrix (all in the vert shader.) Look up how to apply a matrix to a vert, and the order, and how to chain them (it uses the MUL command, same as the original shader.)

I don't think there's a position-only matrix in Unity, but using the rightmost column of WorldView will give that (look up Translation matrix. It explains what the important numbers do and how to use them.) It may be the "natural" facing of a TextMesh is upwards, meaning you'll see the edge, which is nothing. In that case, experiment with applying various rotation matrixes (maybe -90 on x?) to angle it forward. You may not be able to check in Scene View (the shader may keep twisting it away from you) so have to trial and error.

Of course, the optimization rule applies: if LookAt is fast enough, just leave it. Unless you really, really want a mini-project to learn shader matrixes.

Comment
Add comment · Show 1 · 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 Kiloblargh · Oct 18, 2013 at 04:14 PM 0
Share

Thanks- I decided that rotating all the billboards in a script was fast enough, and added a check to only rotate the ones whose renderers are visible. I was disappointed by how my game was chugging on a tablet PC and so went on a re-writing-everything spree. I hoped at first I could learn how matrix transforms work but no, reading about linear algebra still gives me a headache and it's just not worth it at this time.

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

15 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

Related Questions

Opengl es 2.0 Shader Vertex Rotation Issue 1 Answer

Quaternion Multiplication in a shader. 1 Answer

Rotate a vertex about "u" Axis 1 Answer

Is the trail emitted by the Trail Renderer "billboard"? 1 Answer

Billboard grass rotate weird 1 Answer


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