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
0
Question by Matt-Downey · Dec 01, 2011 at 09:02 PM · shadertextureshaderlabhealthbarcutout

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

I was wondering how I would superimpose the red blood from this picture onto the soldier UV from this picture:

alt text with alt text

Here is the code I thought would work, but Alpha values don't seem to factor into shaderlab, which makes sense because otherwise transparency would be easy. The problem is I don't know how to combine anything without +/-/*, so I can never get the shader to look correct. I'm not worried about shader efficiency right now, just methodology.

Without further adeu, here's my code:

 Shader "A/Blood Thermometer"
     {
     Properties
         {
         //_Health ("Health",Range(0,1)) = 1?
         //_InvHealth ("Inverse Health",Range(0,1)) = 0?
         //_Color ("Color", Color) = (1,0,0,1)? //red?
         _MainTex ("Base (RGB)", 2D) = "" //the optimized UV texture for the character
         _BloodTex ("Base (RGBA)", 2D) = "" {TexGen ObjectLinear} //the blood texture, which is placed in world space vertically
         //_BloodTex is the output from a Substance (.SBSAR filetype) made in Substance Designer 2. 
         }
     SubShader
         {
         Pass
             {
             SetTexture [_MainTex]
             SetTexture [_BloodTex] {combine texture} //+ or * previous} doesn't work too well with any variation of _BloodTex color combinations
             }
         }
     }

I'd like to see lighting turned on for the _MainTex, if that's easy. It seems like UsePass would work for the Diffuse, but not the Cutout-shader.

[EDIT:] I found this but I don't know how it helps.

 /*! 
  * \file
  * \author Stig Olavsen <stig.olavsen@randomrnd.com>
  * \author http://www.RandomRnD.com
  * \date © 2011-August-05
  * \brief The shader definition for the HealthBar/HealthBar Transparent shader
  * \details A transparent shader with two texture inputs and a ratio control
  * that lets you set the display ratio of the two textures
  */
 
 Shader "HealthBar/HealthBar Transparent" {
     Properties {
         _MainColor ("Base Color", Color) = (1,0,0,1)
         _BackgroundColor ("Background Color", Color) = (0,0,0,0)
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _BackgroundTex ("Base (RGB)", 2D) = "white" {}
         _Health ("Health", Range(0.0, 1.0)) = 1.0
     }
     SubShader {
         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Lambert alpha
 
         sampler2D _MainTex;
         sampler2D _BackgroundTex;
         fixed4 _MainColor;
         fixed4 _BackgroundColor;
         float _Health;
 
         struct Input 
         {
             float2 uv_MainTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o) 
         {
             half4 c;
             if (IN.uv_MainTex.x < _Health)
             {
                 c = tex2D (_MainTex, IN.uv_MainTex) * _MainColor;
             }
             else
             {
                 c = tex2D (_BackgroundTex, IN.uv_MainTex) * _BackgroundColor;
             }
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         
         ENDCG
     } 
     FallBack "Diffuse"
 }



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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Transparent Cutout Shader? 1 Answer

How to remove a color from texture using Shader? 0 Answers

How to blend two textures? 1 Answer

How to Customize Standard Shader ( Repeating Textures in Mirror Mode ) 1 Answer

[Unity Free]Add textures to existing Unity DOF Shader 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