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

Show more comments

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.

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

Fill rectangle from bottom to top 1 Answer

Texture is Tied to Two Cubes 1 Answer

Assigning UV Map to model at runtime 0 Answers

Texture Issue causing Unity to Error on Web Player Build 1 Answer

Is it possible to have a shader that draws various textures based on normal angle? 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