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 /
This question was closed Dec 10, 2012 at 02:19 PM by FatWednesday for the following reason:

Resolved the issue, posted fix for others in case anyone else finds this problem.

avatar image
0
Question by FatWednesday · Dec 07, 2012 at 07:22 PM · cameraraycastingrendertexturescreenpointtoray

What effects/controls a ScreenPointToRay() ray?

I've recently set up my project to render the scene to a render texture, which is then used as a texture for a plane that gets drawn to the screen by an orthographic camera. I've got the camera, plane and texture set up so that the aspect ratios are correct (the scene looks the same regardless of if its rendered via the flat plane, or directly from the main camera).

My issue is with Camera.ScreenPointToRay(). which is used for all of the user input to tap on objects in the scene. The rays are generated using the same perspective camera that renders the scene, but provides different rays depending on whether or not the orthogonal rendering setup is active or not. Pictures below show the different results.
First is the view from the editor when just rendering through the camera normaly, the red dot is where I was clicking to generate the ray, which is drawn is yellow).
alt text

Now for the same scene, rendered to a RenderTexture, drawn on a plane by the orthogonal camera. Again with the red dot as the input position, you can clearly see a huge difference in the ray that is generated.
alt text

I've output the screen coordinates that are used for the ray cast, as well as the aspect ratio of the camera. With and without the orthogonal system these values are exactly the same. So I'm confused as to why the ray results differ, unless there is some other value that I've not thought of that would effect the ray generation.

A unity package with a test scene (slightly modified from the one in the screenshots to make testing on device easier) Here.

The test scene has 4 spheres that should cycle colours when clicked or tapped on, and a button to swap between modes. Uses render textures so will only run on pro.

screentoray02.png (32.5 kB)
screentoray01.png (34.0 kB)
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

  • Sort: 
avatar image
0
Best Answer

Answer by FatWednesday · Dec 10, 2012 at 02:18 PM

Managed to resolve the issue by basing raycasts off of viewport coordinates instead of screen coordinates (using Camera.ViewportPointToRay()). Unsure as to why this method works but screen based coordinates don't seeing as they both provide the same values in both rendering modes. But in case anyone else has this issue, this is how I got around it.

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

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Multiple Camera.main.ScreenPointToRay 1 Answer

Canvas interaction on render texture to message PhysicsRaycaster 1 Answer

Projecting camera view on to a right angled surface 1 Answer

How can I take depth into account when rendering to texture? 2 Answers

How to get pixeldata from graphics.drawmesh? 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