Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
0
Question by $$anonymous$$ · Aug 08, 2019 at 03:22 PM · rendertextureworldtoscreenpoint

Is there a version of Camera.WorldtoScreenPoint for equirect projections?

I'm using RenderTexture.ConvertToEquirect to capture 360 screenshots of my game, and I'd like to know the coordinates of a given object in my scene in the resulting images. For regular screenshots, I know I can do this with Camera.WorldToScreenPoint. Is there a similar function for equirect projections?

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 Namey5 · Aug 09, 2019 at 03:53 AM 0
Share

You would have to do it manually. WorldToScreenPoint relies on the projection matrix, but because equirectangular images require more than one camera as a source, there isn't a single projection matrix. Ins$$anonymous$$d, you would have to think in terms of the original cubemap; calculate the screen position for each of the 6 cameras, find which one contains the point, then convert said point into an equirect format.

The top answer in following link explains how to do so and has some great examples in Unity:

https://stackoverflow.com/questions/34250742/converting-a-cubemap-into-equirectangular-panorama

1 Reply

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

Answer by Bunny83 · Aug 09, 2019 at 11:47 AM

No, there is no built-in conversion since the cubemap is a 360° projection and not directly related to the camera view or the camera projection. However since the result is an equirect projection of the whole 360°, just using plain lat / lon conversion should work just fine considering the camera position as center.


I have never used the "RenderToCubemap()" or "ConvertToEquirect()" methods, so I don't know if the rendered image is actually relative to the camera rotation or relative to worldspace. Though the only difference would be that you first need to convert between local and world space coordinates.


To convert from worldspace to the equirect projection, just determine the longitude / azimuth (rotation angle around the y-axis) as well as the latitude / polar angle with respect to the camera position.


For localspace conversion, you can just use:

 Vector3 v = Camera.transform.InverseTransformPoint(worldSpacePoint);

For worldspace conversion just subtract the camera position

 Vector3 v = worldSpacePoint - Camera.transform.position;

With that vector we can determine the azimuth using Mathf.Atan2

 float azimuth = Mathf.Atan2(v.z, v.x);

The polar angle can be determined from the normalized vector's y component

 Vector3 dir = v.normalized;
 float polar = Mathf.ASin(dir.y);

Next you want to make sure the angles are positive:

 azimuth += Mathf.PI*2; // 360°
 polar += Mathf.PI; // 180°

Next divide by the angle range to get a value between 0 and 1:

 float U = azimuth / Mathf.PI*2;
 float V = polar / Mathf.PI;

Those are essentially your UV coordinate of your equirect image. The z coordinate (distance from the camera) is simply the magnitude of the v-vector.


Note that as I said there might be some offsets involved or some signs need to be flipped but the general idea is the same.


To calculate the reverse you just do it in reverse. So the UV ranges have to be converted into angles (+-2PI for U and +-PI for V). With those we can simply construct a direction vector using Mathf.Sin and Mathf.Cos. Once we have the normalized vector we can multiply the direction by the wanted distance from the camera to get an actual point. In the last step again either add it to the camera position or use TransformPoint.

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 $$anonymous$$ · Aug 09, 2019 at 06:23 PM 0
Share

Thanks for the elaborate answer, I'll implement this and see if it works ;)

FYI, Cubemaps are made relative to the camera view when using Camera.$$anonymous$$onoOrStereoscopicEye.Left or Camera.$$anonymous$$onoOrStereoscopicEye.Right but relative to the worldview when using Camera.$$anonymous$$onoOrStereoscopicEye.$$anonymous$$ono.

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

112 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 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 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 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 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

How can I build a RenderTexture to Texture2D hidden booth for UI elements? 1 Answer

Is there a way to write to Deferred Depth from a command buffer in CameraEvent.AfterImageEffects? 1 Answer

How to render a custom shadow map in 2D game?,How to render a custom shadow map in a 2D game ? 0 Answers

Weird Image Flickering Behavior on UI Canvas When Using RT Material 1 Answer

Render texture depth smearing 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