• 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
3
Question by PhoenixBlackReal · Jun 23, 2014 at 12:53 AM · texturegroup

Is it possible to create a transparent (empty) Texture2D that hides other textures under it?

I have a health gauge that has a sharp 45 degree angle. Basically I need someway to have an area on the screen under which other textures become invisible, but the alpha texture is still see-through.

I already tried rotating groups, etc. It works fine on normal GUI.matrix, but I have changed it so all of my other textures would scale nicely under every resolution.

How do I make the transparent hider texture? Or maybe there is some other approach?

Comment
Add comment · Show 10
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 Kiwasi · Jun 23, 2014 at 01:35 AM 0
Share

By definition you can see something behind a transparent texture. What effect are you trying to achieve?

Put another non transparent texture just behind the transparent texture?

avatar image PhoenixBlackReal · Jun 23, 2014 at 10:26 AM 0
Share

A texture which would hide a part of another texture which is covered. Imagine an invisibility cloak.

avatar image GrahamReeves ♦♦ · Jun 23, 2014 at 12:39 PM 0
Share

What other textures are beco$$anonymous$$g invisible? are they other HUD elements?

From what I can tell you want to use the stencil buffer for explicitly affecting other objects.

Perhaps you could clarify the effect you're trying to achieve with a mock-screenshot in paint of what you currently see, and what you want to see?

avatar image PhoenixBlackReal · Jun 23, 2014 at 01:52 PM 0
Share

alt text

textureexample.png (28.5 kB)
avatar image PhoenixBlackReal · Jun 23, 2014 at 01:59 PM 0
Share

I'm sorry if my English knowledge is not great enough to explain in superb clarity :< In any case - I have tried rotating a group with the texture inside. It works fine, but my GUI.matrix is custom, therefore a 45 degree angle results in having the group rotated by 47 degrees (like what the hell). And the group also pixelates in a very stupid manner, so on low resolution the nice pointy end looks like a chewed up toy.

avatar image GrahamReeves ♦♦ · Jun 23, 2014 at 04:45 PM 0
Share

I thought you might be able to get around this by writing a fragment shader that could write a depth value in the transparent area so that the red bar wouldn't draw over it. That should solve your problems. But it seems that might not be possible with the GLSL implementation, and either way, it wouldn't be usable on $$anonymous$$obile platforms (in case that matters).

Using the stencil buffer might still be a possibility though..

avatar image meat5000 ♦ · Jun 23, 2014 at 04:51 PM 0
Share

Only took a quick look, but would this do it?

http://wiki.unity3d.com/index.php?title=Texture_$$anonymous$$ask

This was my search

https://www.google.co.uk/search?q=unity+transparent+mask&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&channel=sb&gfe_rd=cr&ei=iFqoU4ftLsXR8geQ4oDgDg

I think the term to describe it is "$$anonymous$$ask"

avatar image PhoenixBlackReal · Jun 23, 2014 at 05:35 PM 0
Share

I'm sorry, I do not really know how to use this advice, should I check basic shader tutorials?

avatar image PhoenixBlackReal · Jun 23, 2014 at 06:49 PM 0
Share

Really lost here ._. maybe someone can write the steps on how to create a mask for the texture and then draw it on the screen? :OO

avatar image tanoshimi · Jun 23, 2014 at 06:55 PM 0
Share

Stencil buffer access is a Pro-only feature, but I don't see why you couldn't write your "invisible" texture to the depth buffer first to prevent the texture underneath being drawn.

1 Reply

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

Answer by tanoshimi · Jun 23, 2014 at 07:34 PM

This should work - assuming that your red "pointy-ended" object is drawn with a transparent shader (and therefore in the transparent queue), then create a new material using this shader and put it on the transparent object that you want to use to mask it.

 Shader "Mask" {
     SubShader {
         Tags {
             "Queue" = "Transparent-1" // Needs to be in a queue *before* the thing that you want to mask
             "IgnoreProjector" = "True"
         }
         Pass {
             Cull Back
             Blend Zero One
             Lighting Off 
             CGPROGRAM
             #include "UnityCG.cginc"
             #pragma vertex vert
             #pragma fragment frag
             v2f_img vert (appdata_base v)
             {
                    v2f_img o;
                    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                    return o;
             }
             fixed4 frag (v2f_img IN) : COLOR
             {
                 return fixed4(0,0,0,0);
             }
             ENDCG
         }
     }
 }


alt text


untitled.jpg (52.6 kB)
Comment
Add comment · Show 6 · 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 PhoenixBlackReal · Jun 23, 2014 at 07:49 PM 0
Share

This all seems to do exactly what is needed, but I'm new to shaders and obviously I have to go through a lot of tutorials, but, if you could spare another moment, maybe you can explain step by step on how to draw and assign all and overall use this? I draw my textures on screen using OnGUI(), how do I draw them with the shader attached, etc. I'm sorry, must sound as a complete empty-head.

avatar image meat5000 ♦ · Jun 23, 2014 at 07:52 PM 0
Share

Not at all. I'm $hyt at shaders too. Its a completely different kettle of fish to what you've encountered so far. Don't beat yourself up, this is an advanced topic :P

@tanoshimi, did you say the Texture mask I posted would require pro?

(off-topic: P$$anonymous$$d you some info on forum)

avatar image PhoenixBlackReal · Jun 24, 2014 at 10:14 AM 0
Share

I somehow managed to make it work right this morning, thank you so much! I mean really, where else would you find a community so supportive and full of such fine people, thank you all! ^w^

avatar image PhoenixBlackReal · Jun 24, 2014 at 10:41 AM 0
Share

How do I draw these textures on the screen so neatly?

avatar image Xtro · Jun 24, 2014 at 02:25 PM 0
Share

"How do I draw these textures on the screen so neatly?"

This is a separate question but the answer is... select the texture, set the type to GUI in inspector and click apply

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Texture is Tied to Two Cubes 1 Answer

Assigning UV Map to model at runtime 0 Answers

Fill rectangle from bottom to top 1 Answer

Clarification with Texture2D.ReadPixels. 1 Answer

Strange smearing on texture with unity 4.3.4 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