Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by varumora · Mar 14, 2016 at 11:43 AM · shadertexturespheredepth-bufferz-buffer

Projecting a plane onto a sphere

So, I have a Sphere (right in the attached image), a camera (in the center of the sphere) and a Quad in between (the Ubuntu Logo). What I want to achieve is making some kind of projection from the cam to the sphere so I can get the Ubuntu logo printed in the sphere. The goal is getting the pixels of the texture and getting the equirectangular projection of the logo (like the quad in the left).

My first thought was raycasting every pixel in the logo and painting it in the sphere, but doing it with c# is too slow and not as good as I thought.

After this i thought using a blending shader so the logo is printed on the sphere. But I don't think there's a way to write the texture from that.

Does anybody have any better idea? or anybody knows a way to get the information from the zbuffer to get the pixel that is printed on top of the ones in my sphere texture?

Thanks so much :)

alt text

pic.jpg (62.3 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 Verusoft · Mar 14, 2016 at 12:30 PM 0
Share

At first, I would try Projector. http://docs.unity3d.com/$$anonymous$$anual/class-Projector.html If that doesn't work, you could use two spheres (1st with default image, 2nd with ubuntu logo) Event If the previous solutions don't work you can always write a custom shader for that purpose.

avatar image varumora Verusoft · Mar 14, 2016 at 02:44 PM 0
Share

Yes, that's not my problem, I know how to show the sphere with the logo. what I want to achieve is writing that information in the sphere texture (in the .jpg) so i get the projection of the logo in the 2D texture as a .jpg/.png.

I'm starting to think I'll have to go with opencv+python. I was trying to avoid that :P

2 Replies

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

Answer by varumora · Mar 15, 2016 at 08:49 PM

OK, I finally solved it thanks to this:

http://mathinsight.org/spherical_coordinates http://mathworld.wolfram.com/CylindricalEquidistantProjection.html

If someone wants to know how, I just followed my first instinct. Iterating for every frame of the sphere's texture, getting its position in real world and raycasting to the camera. If the raycast passes through the logo I get the color of the raycasthit and paint my sphere texture.

Nice result :')alt text


sin-titulo.png (386.5 kB)
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 kru64 · Feb 06, 2017 at 07:01 PM 0
Share

Hi, varumora! Glad that You solved this problem. Can You share the code?

avatar image
1

Answer by devorenge · Feb 29, 2020 at 06:10 AM

I know this is a really old question, But I would like to share a small snippet of code that replicates the askers solution, because I stumbled upon this post today and had to painstakingly implement this rough concept. This code is pretty slow and isn't perfect, but it works. It loops through the entire texture of the sphere and draws anything to it that is in the path from the zero vector to the radius of the sphere.

 for (int x = 0; x < sphereTex.width; ++x) {
     for (int y = 0; y < sphereTex.height; ++y) {
         float phi = y * Mathf.PI / sphereTex.height;
         float theta = x * (1 / Mathf.Cos(l1)) * Mathf.PI / (sphereTex.width / 2);
         //Debug.DrawLine(new Vector3(r * Mathf.Sin(phi) * Mathf.Cos(theta), r * Mathf.Cos(phi), r * Mathf.Sin(phi) * Mathf.Sin(theta)),
         //                new Vector3(0, 0, 0), Color.magenta, 1f);
         RaycastHit rch = new RaycastHit();
         bool hit = Physics.Raycast(new Vector3(0, 0, 0), new Vector3(r * Mathf.Sin(phi) * Mathf.Cos(theta), r * Mathf.Cos(phi), r * Mathf.Sin(phi) * Mathf.Sin(theta)), out rch, r - 3);
         if (hit && rch.distance > 3) {
             Debug.Log("hit at: " + x + " " + y);
             Debug.Log("distance: " + rch.distance);
             sphereTex.SetPixel(-x, -y, exampleTex.GetPixel((int)(-rch.textureCoord.x * exampleTex.width), (int)(rch.textureCoord.y * exampleTex.height)));
         }
     }
 }

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 ncortiz · Feb 13 at 04:23 PM 0
Share

Thx very much for this answer, saved me some time!

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

8 People are following this question.

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

Related Questions

Why does spec map turn object black? 0 Answers

There is an issue with texture wrapping around sphere's in unity 0 Answers

Mesh z-fighting to itself 1 Answer

Equirectangular or radial texture scaling on a sphere 0 Answers

How do I fix texture seam from UV spherical mapping? 1 Answer


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