• 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 legion_44 · Aug 17, 2013 at 10:54 PM · shadertexturealpha

Circular Bar - problem with shader

Hi, I using AlphaCutoff shader to make my life bar circular. Its working half good - the texture disappears but it leaving black solid color be$$anonymous$$nd it. How can I change to draw _BackText instead of just solid black?

Shader:

 Shader "Custom/LifeBar" {
     Properties {
       _MainTex ("Base (RGB) Transparency (A)", 2D) = "" {}
       _BackTex ("Texture", 2D) = "black" {}
       _Cutoff ("Alpha cutoff", Range (0, 1)) = 0.5
     }
     SubShader {
     Tags {"RenderType" = "Transparent" "Queue" = "Transparent" "IgnoreProjector" = "True"}
 
              Pass{
         AlphaTest Greater [_Cutoff]
             Material {
                 Diffuse (1,1,1,1)
                 Ambient (1,1,1,1)
             }
             Lighting On
             SetTexture [_MainTex] { combine texture * primary }
         }
     } 
   }

Script to draw bar:

 if (Event.current.type.Equals(EventType.Repaint))
         {
             mat.SetFloat("_Cutoff", lifePerc);
             Grap$$anonymous$$cs.DrawTexture(new Rect((Screen.width - Screen.width / 6) - 5, (Screen.height - Screen.width / 6) - 5, Screen.width / 6, Screen.width / 6), gradient, mat);
 
         }
Comment
Add comment
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

3 Replies

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

Answer by Jona-Marklund · Aug 27, 2013 at 09:11 PM

Provided that you're trying to have the _MainTex be positioned on top of the _BackTex, t$$anonymous$$s should work for you!

 Shader "JM/LifeBar" {
 //Jona Marklund 27th of August 2013
 
     Properties {
       _MainTex ("Base (RGB) Transparency (A)", 2D) = "" {}
       _BackTex ("Texture", 2D) = "black" {}
       _Cutoff ("Alpha cutoff", Range (0, 1)) = 0.5
     }
     SubShader {
     Tags {"RenderType" = "Transparent" "Queue" = "Transparent" "IgnoreProjector" = "True"}
  
           Pass{
        AlphaTest Greater [_Cutoff]
          Material {
           Diffuse (1,1,1,1)
           Ambient (1,1,1,1)
          }
          Lighting On
          SetTexture [_BackTex] { combine texture * primary }
          SetTexture [_MainTex] { combine texture, previous + texture }
        }
     } 
   }

Best Regards Jona

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 $$anonymous$$ · Aug 17, 2013 at 11:14 PM

It hast to do with line 4, replace

 _BackTex ("Texture", 2D) = "black" {}

with

 _BackTex ("Texture", 2D) = "" {}
Comment
Add comment · Show 2 · 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 legion_44 · Aug 18, 2013 at 10:02 AM 0
Share

This doesn't do the trick ;/. Still leaving black instead of texture.

avatar image legion_44 · Aug 20, 2013 at 01:22 PM 0
Share

Really nobody know?

avatar image
0

Answer by whydoidoit · Aug 20, 2013 at 01:35 PM

Add t$$anonymous$$s to your shader:

 Blend SrcAlpha OneMinusSrcAlpha
Comment
Add comment · Show 2 · 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 legion_44 · Aug 27, 2013 at 07:04 PM 0
Share

Hi, its not leaving solid black now but i want it to draw _BackTex instead of black color, not the _MainTex. Sorry for not answering for so long but i was on wacations :). If somebody know what to do please help me please.

avatar image legion_44 · Aug 27, 2013 at 08:58 PM 0
Share

BUMP! - I really need this and i newbie at shaders :(

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

17 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

Related Questions

normal map, mask different areas? 0 Answers

Making a cutout semi-transparent? 1 Answer

2048px square texture blurr problem 0 Answers

When doing two passes on different alphas, shader gets overwritten. 0 Answers

Toon Shader gets alpha from color, not texture 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