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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Major · Mar 25, 2015 at 05:04 AM · cameragameobjectworldspaceworldworldtoscreenpoint

Correcting Object Offset on WorldToScreenPoint

I've been trying to make a skybox generator based on objects in the world. I have been using the WorldToScreenPoint function to try and plot dots to corresponding coordinates on a 2D image. But once the process is complete and everything is built and running, there is a significant offset for the dots on the image vs. the objects in the scene. Here is the code involved in rendering a side:

 if(s.transform.position.z > 0){
                 Vector3 screenPosFront = _cameraLeft.WorldToScreenPoint(s.transform.position);
                 tex_front.SetPixel(Mathf.RoundToInt(screenPosFront.x), Mathf.RoundToInt(screenPosFront.y), Color.cyan);
             }

I have also set the pixel width and the pixel height of the camera to the same resolution as the textures used to hopefully eliminate that variable. I should also mention that I am trying to render objects that aren't even in the camera view. In other words objects that are really far away.

Comment
Add comment · Show 3
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 raja-bala · Mar 25, 2015 at 06:22 AM 0
Share

It looks like you want a stencil image. If that's the case, you should do this via a shader which is invoked for all/specific objects in the scene via RenderWithShader

avatar image Major · Mar 25, 2015 at 04:36 PM 0
Share

I can't use that for a number of reasons. 1 being that the objects that I am trying to plot are too far away to even be seen by the camera.

avatar image Glurth · Mar 25, 2015 at 06:30 PM 0
Share

there is a significant offset for the dots on the image vs. the objects in the scene

How do you position the resultant image for the camera that renders it? Edit: sorry- bad comment- you clearly state you are using a skybox.

Another Edit: I think using a skybox may be the cause of your problem. The skybox will wrap the image all the way around the camera, rather than simply showing an image at a distance that perfectly fills the screen. So, your worldtoscreen point, wont be converting to what the ACTUAL screen point is (it will get warped to fill 360deg, rather than the cemera's viewing angle).

Try putting the image you generate on a sprite, on a canvas that is set to screen-size. Or something similar, the point being to render a plain-ol' rectangular image, that exactly fills the screen.

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

22 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

Related Questions

GUIButtons Follow different GameObjects?? 1 Answer

Why does my TMP inputfield text disappears when I rotate It, why using a world space camera 0 Answers

Cinemachine not working with my Movement Script 0 Answers

how to get the most right point or left point atc of object as visual on the screen in 3d project? 0 Answers

Directional Scrolling with rotating camera 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