Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
1
Question by $$anonymous$$ · Feb 17, 2016 at 10:15 AM · shadervector3transformation

How to convert a unity's transformation to vector4 to use in a shader?

I have a shader which takes a vector4 . This vector4 is a section plane with x, y, z and w . The shader clips the portion below this section plane. What I want to do is assign this section plane's value from the transformation of a unity plane. I understand that I have to get the plane's position and rotation in a c# script and assign it to the shader. The problem is that I don't know how this position and rotation can be converted to a vector4 form. I don't have much idea about transformation matrices and shaders. Thanks in advance..

[1]: /storage/temp/64054-section-plane.jpg

section-plane.jpg (51.8 kB)
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 meat5000 ♦ · Feb 17, 2016 at 10:14 AM 1
Share

https://en.wikibooks.org/wiki/Cg_Program$$anonymous$$g/Unity

This will help. Its good.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Feb 17, 2016 at 10:50 AM

It's not really clear what the shader expects. A plane is usually defined by a normal vector (usually called "a,b,c") and a distance from the origin (usually called "d").

If you use a Vector4 you can use the first 3 components (x,y,z) as normal vector and the 4th component (w) as distance. To convert a given normal and a point on the plane into that format you could use a method like this:

 public static Vector4 CalcPlane(Vector3 aNormal, Vector3 aPoint)
 {
     aNormal.Normalize();
     return new Vector4(aNormal.x, aNormal.y, aNormal.z, -Vector3.Dot(aNormal, aPoint));
 }

However your screenshot shows the x,y and z parameters as "angle" which seems to make no sense. Expecially you would only need 2 angles to define the normal of a (mathematical) plane in space. However using angles would just be way more complicated. Also the values in your screenshot (-0.4, 0.6, 0) seem to represent a normalized vector just like you would expect.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to give a position an offset relative to its forward vector in local space? 1 Answer

Transform Screen Point to Transform extension 1 Answer

My assets losing colors when running on lgsvl simulator. Everything gets black and white after 20-30 minutes. Scripting and assets and maps were done on unity. any suggestions ? 0 Answers

Fog centered on Vector3 1 Answer

Does Unity modify mesh Normals or Vertex before rendering? 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