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 nonopblic · Oct 18, 2017 at 09:07 AM · shadergraphicsshader programmingshaderlabcg

Can I see the calculation of unity_MatrixVP ?

I would like to know what is unity_MatrixVP.
I searched it in builtin shader files, whose version is 2017-1-2f1.

I found the UnityShaderVariables.cginc(20)

 #if defined(USING_STEREO_MATRICES)
     #define unity_MatrixVP unity_StereoMatrixVP[unity_StereoEyeIndex]    

UnityShaderVariables.cginc(178)

 #if defined(USING_STEREO_MATRICES)
   CBUFFER_START(UnityStereoGlobals)
       float4x4 unity_StereoMatrixVP[2];

and

UnityShaderVariables.cginc(226)

 #if !defined(USING_STEREO_MATRICES)
     float4x4 unity_MatrixVP;

But I could not found how Unity calculate unity_StereoMatrixVP and unity_MatrixVP.
Is is possible to see not the declaration but the definition of unity_MatrixVP ?

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 Bunny83 · Oct 18, 2017 at 11:19 AM

The VP matrix the the combination of the ViewMatrix (also known as Camera matrix) and the ProjectionMatrix of that camera. So this matrix transforms a point from worldspace directly into viewport space (-1 to 1).

The View or Camera matrix is basically just the WorldToLocal matrix of the gameobject where the camera is attached to. However the camera matrix is doing the conversion from left-handed to right handed space so it's scale is inverted on the z axis. You can access / set the "V" matrix by accessing Camera.worldToCameraMatrix. However for stereo view (VR / AR stuff) you actually have two of these, one for each eye.

The projection matrix converts the positions from camera space into viewport space (or clipspace). The final VP matrix is calculated by simple combining the matrices. Keep in mind that the order in which you combine matrices matters.

 Matrix4x4 VP = ProjectionMatrix * ViewMatrix;

The matrices are taken from the camera(s) involved. Unity sets the external shader variables automatically before rendering the corresponding camera. That's actually the main point of a "Camera". A Camera just represents rendering parameters.

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 CaptainScience · Aug 19, 2019 at 05:26 PM 1
Share

An important note is that because Unity supports so many platforms this answer is only mostly correct. Before you combine the matrices you have to run the projection matrix through GL.GetGPUProjection$$anonymous$$atrix() to convert it from the default OpenGL convention Unity uses in the scene to the proper conventions for whatever API is being used under the hood.

If forget that step, you can get things like weird upside-down/inside-out rendering on certain platforms.

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

121 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

Related Questions

How to achive the same look? Which shaders to use? 2 Answers

Flat Shading / No Vertex Interpolation 2 Answers

How to access another sprite's texture from a 2D shader 0 Answers

The Best Way To Make Stylised Grass in Unity? 0 Answers

Rewrite shader so that the Sprite-Diffuse shader doesn't take incidence angle into consideration when applying lighting? 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