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 /
  • Help Room /
avatar image
3
Question by Julien-Lynge · May 23, 2013 at 11:27 PM · camerashadervertex

Shader MVP matrices: what does vertex position mean at each step?

I've been scouring the web trying to find an explanation of what the position of a vertex actually means before and after each projection in the standard MVP chain. After reading and trying some things out, I understand it in a general sense:

  • Initially, position is a multiple of the bounds of an object, in local object space

  • After M, position is in world coordinates

  • After V, position is in camera coordinates

  • After P, position is in screen coordinates

What I'm trying to figure out for each of these is what exactly the units mean. Here's what I understand so far - if anything is incorrect or you can fill in the gaps, I'd appreciate any help :)

Initial

Units are -0.5 to 0.5 along the 3 axes, with -0.5 and 0.5 corresponding to the bounds of the object. No surprises there.

Post-M

Units are in Unity's world coordinate system. No surprises there.

Post-V

Units are in some kind of camera coordinate system. X and Y appear to be square, and a quad with an assigned X and Y range of 1 in MV spaces doesn't appear to quite fill up the screen from bottom to top. No idea what units Z is in.

Post-P

X and Y units are in viewport coordinates, with -1 to 1 being the range horizontally and vertically? No idea what units Z is in.

Once you're in post-P space, it appears you can use _ScreenParams to get the number of pixels and convert from viewport to pixel coordinates in XY.


So in a general sense, I'm looking for information on what the coordinates mean in each space, and what can be done with them.

I'm trying to create some custom billboarding. Here are a couple examples of what I hope to do with this information:

  • Create a billboard that appears the same size regardless of distance from the camera.

  • Create a billboard whose size is dependent on distance from the camera, but not linearly. E.g. a billboard that appears to be 0 pixels wide at 1000 game units, and 100 pixels wide at 10 game units, increasing along some kind of curve.

Comment
Add comment · Show 3
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 GarthLaoshi · Mar 08, 2019 at 12:29 AM 0
Share

Why do you assume that it is $$anonymous$$ then V then P? By convention in mathematics, the expression $$anonymous$$VP * u would be evaluated by multiplying by P first. I can only assume that the same is done here, so that would be a matrix from projection space to model space.

avatar image Bunny83 GarthLaoshi · Mar 08, 2019 at 12:52 AM 0
Share

No, that's not true, The point is that we do a right side multiplication.

 transformedpoint = P * V * $$anonymous$$ * point

So yes, we do first apply $$anonymous$$ then V and finally P. $$anonymous$$ (model matrix) brings local model coordinates into worldspace. V (view matrix) brings world space coordinates into the local space of the camera (essentially the inverse of the camera transform object). P (projection matrix) finally does the projection from view space into normalized viewport space.


If you want to know more about the projection matrix or matrices in general, have a look at my matrix crash course

avatar image Owen-Reynolds GarthLaoshi · Mar 08, 2019 at 03:12 AM 0
Share

And beyond the math, that's the definition - it applies them in that order, when used the standard way. If the actual math was P($$anonymous$$/2+V^2) we'd still call it the $$anonymous$$VP matrix.

3 Replies

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

Answer by Owen-Reynolds · May 24, 2013 at 01:45 AM

OpenGL stuff (like the graphics "Red Book") do a pretty good job explaining that stuff. It's standard -- nothing to do with Unity.

Initial are the raw model coords, straight from the modelling program. Can be anything, but obviously should be touching/surrounding 000. The tip of an animated orc's nose is always (0,3,0.4) for every orc, every frame.

After MV is "world units" in the camera's local coordinate system. The same as Cam.main.InverseTransform(P);. If the camera is 10 meters away facing you, it will be (0,0,-10) (at some step, negative Z is in front of you.)

P accounts for the view angle and converts to generic viewPort as you say. Depending on the system that's often -1 to 1 (so 00 is centered.) Hardware will convert to pixels. The same way, is now "normalized" depth.


Standard way to make something the same size at depth is to set the matrix not to shrink it. In Unity, it's simpler to just make a 2nd Ortho camera (which makes the matrix you wanted.) For depth doing funny stuff, should be able to have the vert shader check Z (in meters) or distance(xyz), also in meters, after the MV step.

Comment
Add comment · Show 2 · 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 Julien-Lynge · May 24, 2013 at 02:00 AM 0
Share

Awesome, thanks for the answer. The $$anonymous$$V thing makes perfect sense now that you've pointed it out :)

In terms of keeping billboards the same size, ortho is definitely a good way to go (and we do that for GUI elements), but we need our billboards to actually be at a point in-world, able to be occluded and of course moving relative to the camera as the user moves around.

So a hybrid approach sounds like it will work: save the depth in the $$anonymous$$V stage, and then set the size (as pixels or percent) in the $$anonymous$$VP stage.

At the $$anonymous$$V stage, I presume that (0,0,0) is at the point of the camera, not something bizarre like the center of the camera's near clip plane or anything - let me know if that isn't correct :)

avatar image Owen-Reynolds · May 24, 2013 at 12:47 PM 1
Share

The view matrix really is just pure local camera coords, so (000) is the camera. For example this:

http://webglfactory.blogspot.com/2011/06/how-to-create-view-matrix.html is just doing a lookAt (Unity did not invert the LookAt :-))

The near and far planes are part of the depth calc, in the P step. Likewise the camera view angle (or Ortho bounds) is for Perspective, which is, of course, in the P step.

avatar image
0

Answer by Boris S. · Nov 18, 2014 at 05:33 PM

I am learning transformations too and have found a strange issue. After applying MVP transformation in vertex shader I expect to get vertex coordinates in [-1;1] range, but it is true only for orthographic camera. With perspective camera it is not true. I do not know what exactly values I get, but they are much bigger than 1. Could anyone please explain me why it happens?

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
avatar image
0

Answer by darktemplar216 · Jul 27, 2015 at 11:05 AM

the answer is wrong. after v = p*v*m*v0, v.x is not[-1, 1], v.y is not[-1, 1]alt text

the grey area is[-1, 1]

I use o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.vertex as color to do the experiment


qq图片20150727181046.jpg (44.8 kB)
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

18 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

Related Questions

how can i reproduce the 'Unity_Matrix_VP' value? 0 Answers

Anyone know how to change the size of a point with a vertex shader? 1 Answer

Need help with custom shader 0 Answers

How to darken the camera feed from ARkit without darkening the AR objects 0 Answers

Age of Empires type Fog of War from Point Light 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