Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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
3
Question by $$anonymous$$ · Feb 17, 2017 at 10:28 PM · cameravrviewportworldtoscreenpoint

WorldToViewportPoint and WorldToScreenPoint give wrong positions when VR is enabled

In my application, I want to use eye-tracking to determine if a user looks at a certain GameObject. From the eye-tracker I get positions in "normalized screen space", which is comparable to the viewport positions in Unity: A vector in range [0;0] - [1;1].

To determine the position of the GameObject on the screen, I use Camera.WorldToViewportPoint. This works fine as long as VR is disabled. As soon as I enable VR, the calculated viewport position is wrong (except in case the GameObject is in the center), it seems like a nonlinear distortion.

Do I need to apply another conversion after WorldToViewportPoint?

Here is an example of the issue, which displays the viewport position and overlays a GUI element using the screen position. I modified the code from this question and attached it to the cube:

     void OnGUI()
     {
         Vector3 viewportPos = Camera.main.WorldToViewportPoint(transform.position);
         Vector3 screenpos = Camera.main.WorldToScreenPoint(transform.position);
 
         GUI.Label(new Rect(30, 30, 100, 30), viewportPos.ToString());
         GUI.Box(new Rect(screenpos.x - 10, Screen.height - (screenpos.y + 10), 20, 20), "X");      
     }


The correct result (VR disabled): viewport position correct when VR disabled

The incorrect result (VR enabled): viewport position wron with VR disabled

As you can see, there is no GUI element displayed (the calculated screen position is off limits) and the calculated viewport position is wrong as well. I understand that the screen positions can be wrong in case the values (in pixels) are calculated for the screen in the HMD and then are used to position GUI objects on the secondary monitor, where the window has other dimensions than the HMD. But the viewport positions should work correctly, or am I missing something?

Many thanks!

For VR, I used both the standard Unity Camera and the HTC Vive Camera Prefab - same effect with both.

normal.jpg (12.0 kB)
vr.jpg (11.6 kB)
Comment
Add comment · Show 2
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 Invirtuo · Apr 16, 2019 at 03:19 PM 0
Share

Hi!

Did you found a solution? I have the same problem and I don`t know how to fix it.

Thanks!

avatar image sisse008 · Sep 25, 2019 at 02:56 PM 0
Share

@$$anonymous$$ did you figure this out? I'm having trouble with this too.

Thank you

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SuperScience · Sep 25, 2019 at 04:54 PM

Hi Otto,

You have 2 questions here so I am going to attempt to answer them individually.

First the GUI: VR is a special beast.Because framerate is extremely important in VR, certain parts of the rendering stack are not drawn at all. (I believe that this is the deferred rendering? But everything in VR needs to be forward rendering or something like that).

Anyway: the important bit is that the GUI drawing phase of rendering is ignored by design in VR. Additionally, it would be disorienting. You don't actually want to use GUI with VR because its 2D in a 3D space. It would mess with your eyes to kinda have GUI elements pasted to your face.

What I recommend is to child a GUI to the headset object, and set its Z to be a reasonable distance in front of the HMD.

If you want to still use the GUI elements, I think you still can do it by switching your canvas render mode to world space. Now that its a world space object you should be able to mount it to the HMD by childing it to the HMD object.

For your second question, I suspect that Unity is correct and that it is considering the HMD itself to be the camera (one of the eyes, anyway).

You could simply print out the world coordinates of each camera and see if the starting positions are different. I bet they are. And I bet if you move your HMD you'll see the values change in the VR case.

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 SuperScience · Sep 25, 2019 at 05:01 PM 0
Share

One other possibility is that you've maybe scaled your VR camera/playarea differently than your non-VR camera, which would make coordinates in the local system different than the global system.

I recommend never scaling unless you absolutely have-to because it futzes with coordinate calculations, which can cause difficult-to-diagnose bugs. Ins$$anonymous$$d, scale using scale files when importing meshes and leave all in-engine scales at 1,1,1

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Crosshair Not Parallel To camera 1 Answer

Disabling VR Camera rotation creates ''cinema'' effect in VR device 1 Answer

Draw texture directly on Oculus screen 1 Answer

Scene view different with camera view/VR view 0 Answers

RenderTexture.active for a non-VR camera in a VR project 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