Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Tudor · Sep 22, 2015 at 04:22 PM · unity 5shadercgopenglmatrix4x4

Difference between pos.z and pos.w?

I'd like some clarification on what's stored in the builtin float4's at different stages.

What value does the .w parameter of a vertex Position hold in the stages prior to the Projection stage? Is it 1? (is it at all useful in the vertex program of a unity CG shader?)

From theory I know that if you want to do a perspective divide on your view frustum in your clip / projection stage, you need to divide the current position by the inverse of its distance from camera. Which in (viewspace and) clipspace should be 1/ the .z component (and same as 1/ depth), no?

But in opengl books and articles I see it's always divided by .w, not by .z.

Is .w actually == 1/.z and is it only there for homogenous space coordinates reasons (and also to save you having to do an extra 1/ division?)? I'm asking because you have to turn .z into 1/.z (and then back) anyway in order to keep it linear during interpolation (and OpenGL does that automatically between vert and frag), so I'm a bit confused.

As well I see in unity's shader variables that _ProjectionParams.w == 1/FarPlane and ProjectionParams.z == FarPlane.

Does ProjectionParamscontain the camera's near and far clip plane positions in worldspace if you access it in the vert program, vs it being in normalized device coordinates in frag?

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 _Gkxd · Sep 22, 2015 at 07:37 PM 1
Share

3D points are stored as 4D vectors so that homogeneous transforms can be used. The 4-vector (x,y,z,1) represents the point (x,y,z).

Points are passed into the vertex shaders as (x,y,z,1), which is then multiplied at some point by the perspective projection matrix:

alt text

The resulting point then goes through the perspective divide, and so on.

ProjectionParams is just a structure that allows you to obtain certain properties about the current view. Think of it as four separate variables that are stored together ins$$anonymous$$d of a point in 3D space.

projection-matrix.png (10.9 kB)

0 Replies

· Add your reply
  • Sort: 

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

32 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

Related Questions

How to compare colors in Shaders? 2 Answers

Transparent shader disappears with multiple objects 1 Answer

How to force the compilation of a shader in Unity? 5 Answers

Unity5 CG Shader get model position. 1 Answer

Unity 5 toon shaders don't work in Windows standalone build 3 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