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
2
Question by jczaban · Aug 13, 2011 at 09:49 PM · guigraphicsalphamaskgroup

Non rectangular GUI Mask / Matte?

I have looked around a bit but can't find anything definitive on this.

I'm using GUI.DrawTexture along with a GUI Group to move textureA behind textureB so that textureA looks like it's disappearing. However, textureB has transparency and a curve so using a simple rect from the GUI Group does not achieve the look.

Is there a way to pass in alpha or color information from another texture in order to get a non-rect masking effect?

I saw something about using the Graphics class along with a custom material which I will look into more. I don't know shader scripting very well so I am hoping there is a more simple approach that I am overlooking.

Thanks! John

Edit: Adding an image to help clarify my question. alt text

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 Julien-Lynge · Aug 13, 2011 at 10:02 PM 0
Share

Not sure I get what you're trying to do. You say you want to move a texture behind another, but I can't visualize what you mean. Can you include a couple screen captures of the beginning and end frame of what you want to do? When you say the texture is 'disappearing' I think fading - is that the case?

avatar image jczaban · Aug 14, 2011 at 04:45 AM 0
Share

I added an image to help visualize. I need a GUI texture to move behind another GUI texture that has transparency and a curve. I want it to look like the moving texture is extending in/out from the top of the curve. Thanks for replying, I hope the image helps, I feel like I'm missing something simple.

2 Replies

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

Answer by Julien-Lynge · Aug 14, 2011 at 05:26 AM

Tricky :). If the moving part (textureA) has no transparency, you could try using a transparent cutout material. There's an example of more or less what you'd need to do here, but your alpha channel would look more like this:

alt text

Then, you'd just check the screen y-value of your object and adjust the alpha cutoff accordingly. That's the easiest way I know of to do it without a bunch of coding and pixel manipulation - hopefully someone else will come along with a more elegant solution :)

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
0

Answer by TheGering · Jan 26, 2015 at 03:14 PM

Or you could cutout the Texture before using it:

     public static Texture2D CircularCutoutTexture(Texture2D texture) {
         if (texture == null) return null;
         Color[] pixels = texture.GetPixels(0);
 
         // generate cutout
         Texture2D cutout = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false);
         int size = (int)Mathf.Sqrt(pixels.Length);
         for (int y = 0; y < size; y++) {
             for (int x = 0; x < size; x++) {
                 float dx = x - size/2;
                 float dy = y - size/2;
                 float d = Mathf.Sqrt(dx * dx + dy * dy) - size/2;
                 if (d >= 0) pixels[x + y * size].a = Mathf.Max(1 - d, 0);
             }
         }
         
         cutout.SetPixels(pixels, 0);
         cutout.Apply();
         return cutout;
     }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Strange shader behaviour on UI component 0 Answers

iphone album art how? 0 Answers

Water foam 1 Answer

How to create this type of mask? 0 Answers

Scrollview is positioning things incorrectly 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