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 /
avatar image
0
Question by Nabbz0rz · Dec 03, 2014 at 05:17 PM · screennormalsviewprojection

Normal from _CameraDepthNormals to screen space angle

Considering the normals from the depth-normals texture are in view space, I thought it'd be as simple as transforming it by the projection matrix.

 float4 n = mul(UNITY_MATRIX_P, float4(normal, 1.0));
 
 n.xz /= n.w;
 
 float theta = atan2(n.z, n.x);

This doesn't seem to be the case, can anyone guide me in the correct direction?

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 Nabbz0rz · Dec 04, 2014 at 07:57 PM 0
Share

Awhile after tinkering with it I've come to this as suggested by: http://stackoverflow.com/questions/724219/how-to-convert-a-3d-point-into-2d-perspective-projection

Yet it still yields improper results. I've multiplied by the inverse transpose of the model-view matrix, multiplied by the projection matrix, executed a perspective divide, and thereafter converted the coordinates into the [-1,1] range. Is there something I'm missing?

                 float4 n = mul(UNITY_$$anonymous$$ATRIX_IT_$$anonymous$$V, float4(normal, 0.0));
                 
                 n = mul(UNITY_$$anonymous$$ATRIX_P, n);
                 
                 n.xyz /= n.w;
                 
                 n.x = (n.x * _ScreenParams.x) / (2.0 * n.w) + (0.5 * _ScreenParams.x);
                 n.y = (n.y * _ScreenParams.y) / (2.0 * n.w) + (0.5 * _ScreenParams.y);
                 
                 float theta = atan2(n.y, n.x);

1 Reply

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

Answer by Nabbz0rz · Dec 04, 2014 at 08:43 PM

It looks like I was putting too much thought into it. Here's the solution:

 float3 n;
 
 n = mul((float3x3)UNITY_MATRIX_IT_MV, normal);
 n = mul((float3x3)UNITY_MATRIX_P, n);
 
 float theta = atan2(n.y, n.x);

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

25 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

Related Questions

Converting world point to screen point 2 Answers

GUI Follow Object On-Screen 1 Answer

Setting gameobject position by a percentage of screen 1 Answer

Previous Model*View*Projection Matrix 0 Answers

Fixed width, relative height, on different aspect ratio screen? 4 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