• 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 HppyDedPxl · Dec 07, 2015 at 11:21 PM · shaderpositiongraphicsvector

Shader input position.w, what is it for?

Hello everybody! So I stumbled upon this neat snippet of code here:

 float2 WIN_SCALE = float2(_ScreenParams.x/2.0, _ScreenParams.y/2.0);
 //frag position
 float2 p0 = WIN_SCALE * IN[0].pos.xy / IN[0].pos.w;
 float2 p1 = WIN_SCALE * IN[1].pos.xy / IN[1].pos.w;
 float2 p2 = WIN_SCALE * IN[2].pos.xy / IN[2].pos.w;

This is inside of a geometry shader, hence the input array. I figure that this code transforms vertex positions into screen space vertex coordinates (as gl_fragCoord would do?) Now, multiplying the vertex position with the halved screen size is quite self explaining, but the division at the end is what I am still wondering about.

I guess pos.w holds information about the depth of a vertex (drawing order). But that is really only an uneducated guess based on the fact that deleting or manipulating the division resulted in many artifacts on edges of spherical objects, where vertices are particularly close to each other. So can anybody enlighten me as to what exactly w contains?

Thank you in advance!

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
0
Best Answer

Answer by tanoshimi · Dec 07, 2015 at 11:23 PM

They're 4D homogenous coordinates, so the w coordinate implies whether you're talking about a 3D vector or a 3D point - see here for a better explanation: https://books.google.co.uk/books?id=mNw_CQAAQBAJ&pg=PA14&dq=homogeneous+coordinate+in+the+fixed-function+pipeline&hl=en&sa=X&ved=0ahUKEwiE7-rk8crJAhUDPhQKHSzSCJQQ6AEIIzAA#v=onepage&q=homogeneous%20coordinate%20in%20the%20fixed-function%20pipeline&f=false

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 HppyDedPxl · Dec 08, 2015 at 09:23 AM 0
Share

That clears things up! Thank you.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make vector monitor graphics in Unity? 3 Answers

How to edit one axis of the transform position 1 Answer

Unity 5 Deferred Stencil Buffer Usage 1 Answer

Black Texture on Initial Load 1 Answer

Need help with a shader that uses additive particle blending (worked in 4.6; broken in unity 5): 0 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