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
4
Question by ProudOne · Jun 24, 2012 at 09:46 PM · shadertexturetransparenthealthbarcutout

Transparent Cutout Shader?

I've been trying to make a circular health bar. Now, there's a tutorial out there that uses the cutout shader to create one.

My problem is: The health bar is supposed to be semi transparent.

So I looked for addon shaders because as far as I can see, there's no solution to that built in to Unity - needless to say, I didn't find any.

I tried writing my own, using the script reference to manage, sadly this one only works on straight bars (also, only really badly since its my first...)

So, my question is really: Can this shader somehow be salvaged to work in a circular manner? Or, even better, does anyone know a Shader with a Transparent Base Texture that also allows a seperate texture for cutouts?

 Shader "Transparent/Bar" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     _Fill ("Fill Percentage", Range(-1.0,1.0)) = 0.5
     _BarSz ("Bar Size", Float) = 3.0
 }
 
 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
     LOD 200
     Cull Off
 
 CGPROGRAM
 #pragma surface surf Lambert alpha
 
 sampler2D _MainTex;
 fixed4 _Color;
 float _Fill;
 float _BarSz;
 
 struct Input {
     float2 uv_MainTex;
     float3 worldPos;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     float p = _BarSz * _Fill;
     clip(IN.worldPos.x + p);
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     o.Albedo = c.rgb;
     o.Alpha = c.a;
 }
 ENDCG
 }
 
 Fallback "Transparent/VertexLit"
 }


Thanks in advance!

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 MoliCat · Jun 30, 2014 at 12:35 AM 0
Share

@proudeone can you show me some screenshots

avatar image dttngan91 · Aug 19, 2014 at 02:58 PM 0
Share

Thanks, your shader save me!

1 Reply

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

Answer by ProudOne · Jul 06, 2012 at 07:46 PM

For Everyone else looking for a solution; Here it is!

 Shader "Transparent/Cutout/Transparent" {
 Properties {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
     _CutTex ("Cutout (A)", 2D) = "white" {}
     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
 
 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
     LOD 200
 
 CGPROGRAM
 #pragma surface surf Lambert alpha
 
 sampler2D _MainTex;
 sampler2D _CutTex;
 fixed4 _Color;
 float _Cutoff;
 
 struct Input {
     float2 uv_MainTex;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
     float ca = tex2D(_CutTex, IN.uv_MainTex).a;
     o.Albedo = c.rgb;
     
     if (ca > _Cutoff)
       o.Alpha = c.a;
     else
       o.Alpha = 0;
 }
 ENDCG
 }
 
 Fallback "Transparent/VertexLit"
 }

Comment
Add comment · Show 12 · 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 Matt-Downey · Aug 25, 2012 at 11:28 AM 0
Share

Excellent for learning shader logic.

avatar image MakinStuffLookGood · May 28, 2013 at 06:40 PM 0
Share

This is exactly what I was looking for! So much potential for cool effects you can achieve with this shader. Thanks for this!

avatar image matthewhoyes18 · Aug 15, 2013 at 10:53 PM 0
Share

Hey, thanks for the shader. I was wondering..In what context is this shader used? I guess a better way to put it is: How is this shader used in order to create the "circular healthbar" effect?

avatar image bozmir · Oct 13, 2013 at 02:32 PM 0
Share

Awesome shader, the semi transparency works! Only i cant seem to get any colors using graphics.drawtexture(rect,tex,mat). Im very new to shaders/coding, please help :) Thanks

avatar image RadJor64 · Oct 22, 2013 at 04:32 AM 0
Share

more than a year later, just what I needed. Thanks for this!

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

15 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

Related Questions

Creating a shader that overlaps a diffuse with a TexGen ObjectLinear cutout 0 Answers

Cutout & reflective shader 0 Answers

Unlit Transparent Cutout shader that can switch between two textures 0 Answers

What is the fastest shader? 2 Answers

Transparent Cutout Shader - max transparency distance? 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