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 /
avatar image
0
Question by arthur_conti · Feb 26, 2014 at 07:13 PM · texture2dfacebookcircleedgesround

Cut Texture2D in circle format

I'm trying to make a square facebook profile fit in a rounded border by clipping its edges.

I have the square texture, but I can't find any function to make it rounded, in a circle format

Any help??

Thanks

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 robertbu · Feb 26, 2014 at 07:32 PM 0
Share

Is the image always the same size and is the circle always cut in the same place? If so, you could author a mask image in Photoshop. There are shaders that allow you to specify a mask. In addition, you could do it more directly by using GetPixels32 and SetPixels32() and copy the alpha channel of the mask to the image.

avatar image Fr0stbite · Feb 26, 2014 at 07:33 PM 0
Share

make circle texture from your and in unity apply it as Transparent

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Wiki

Answer by jumahsafarty · Jun 02, 2014 at 05:45 AM

 Texture2D CalculateTexture(
     int h, int w,float r,float cx,float cy,Texture2D sourceTex
     ){
     Color [] c= sourceTex.GetPixels(0, 0, sourceTex.width, sourceTex.height);
     Texture2D b=new Texture2D(h,w);
     for (int i = 0 ; i<(h*w);i++){
         int y=Mathf.FloorToInt(((float)i)/((float)w));
         int x=Mathf.FloorToInt(((float)i-((float)(y*w))));
         if (r*r>=(x-cx)*(x-cx)+(y-cy)*(y-cy)){
             b.SetPixel(x, y, c[i]);
         }else{
             b.SetPixel(x, y, Color.clear);
         }
     }
     b.Apply ();
     return b;
 }

this function return a texture2d which represent a circular cut of the source texture with radius (r) and center coordinate cx,cy and the rest of texture size (h*w) will be colored as transparent (alpha =0)

this function take time to load you mustn't but it on (OnGui or Update .... etc) you can but it in Start() or make a condition for it to load

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
avatar image
1

Answer by Chikanut · Dec 29, 2015 at 01:11 PM

 Texture2D CalculateTexture(int h, int w,float r,float cx,float cy,Texture2D sourceTex){
     Color [] c= sourceTex.GetPixels(0, 0, sourceTex.width, sourceTex.height);
     Texture2D b=new Texture2D(h,w);
     for(int i = (int)(cx-r) ; i < cx + r ; i ++)
     {
         for(int j = (int)(cy-r) ; j < cy+r ; j ++)
         {
             float dx = i - cx;
             float dy = j - cy;
             float d = Mathf.Sqrt(dx*dx + dy*dy);
             if(d <= r)
                 b.SetPixel(i-(int)(cx-r),j-(int)(cy-r),sourceTex.GetPixel(i,j));
             else
                 b.SetPixel(i-(int)(cx-r),j-(int)(cy-r),Color.clear);
         }
     }
     b.Apply ();
     return b;
 }
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

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

23 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

Related Questions

Round Slider (Circle shaped slider GUI control) 1 Answer

Find corners/edges on a shape using own implementation 2 Answers

Circle GUI Button, Javascript? 1 Answer

How to intergrate facebook SDK with a mobile game 1 Answer

Turning off SSO on Facebook's Unity SDK for Android 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