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
1
Question by Whelandrew · Jan 12, 2012 at 12:48 AM · spritemaskoverlay

Shaders to show damage?

I'm trying to take the pressure off of my artist a bit in designing the game. Buildings in the game take damage and I'm wondering if there is a simple method to take a sprite that would indicate damage and mask it over the buildings?

As an example, when a building is damaged, I would place a mask that has just drawings of cracks on it that would cover the sprite. This would allow me to reuse the same damage indicator for multiple buildings.

Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Berenger · Jan 12, 2012 at 05:13 AM

As it happens, I just had to do the same thing. Here is what I did : In the shader below, I the is the main texture and three masks, for low / mid / high damage, controlled by a float I change in-game (material.SetFloat etc) but enough talk, here is the shader :

 Shader "Custom/Breakables" 
 {
     Properties 
     {
         _Color ("Main Color", Color) = (1,0.5,0.5,1)
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _Crack1 ("Crack 1", 2D) = "white" {}
         _Crack2 ("Crack 2", 2D) = "white" {}
         _Crack3 ("Crack 3", 2D) = "white" {}
         _CrackIndex ("Index", Float ) = 1
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         
         CGPROGRAM
         #pragma surface surf Lambert
         
         float4 _Color;
         float _CrackIndex;
         sampler2D _MainTex;
         sampler2D _Crack1;
         sampler2D _Crack2;
         sampler2D _Crack3;
 
         struct Input 
         {
             float2 uv_MainTex;
             float2 uv_Crack1;
             float2 uv_Crack2;
             float2 uv_Crack3;
         };
 
         void surf (Input IN, inout SurfaceOutput o) 
         {
             half4 c = tex2D ( _MainTex, IN.uv_MainTex );
             
             half4 cracks;
             if( _CrackIndex <= 1f ) cracks = (1).rrrr;
             else if( _CrackIndex <= 2f ) cracks = tex2D ( _Crack1, IN.uv_Crack1 );
             else if( _CrackIndex <= 3f ) cracks = tex2D ( _Crack2, IN.uv_Crack2 );
             else cracks = tex2D ( _Crack3, IN.uv_Crack3 );
             
 
             o.Albedo = c.rgb * _Color * cracks.r;
             //o.Albedo = cracks.rgb;
             o.Alpha = c.a;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }

I'm not really a pro in shaders from unity so it's the simplest possible, but I guess you works things out with that !

Comment
Add comment · Show 1 · 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 Hathakas · Jan 14, 2015 at 12:50 AM 0
Share

I can't seem to get this to work, is it outdated or something?

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

Sprite Mask Render Issue 1 Answer

Sprite pixels problem on Android with mask 0 Answers

Mask a sprite mask?,Is there anyway to use a sprite mask under a rect mask? 0 Answers

Dynamically building sprite by using masks in unity 1 Answer

How to apply gradient to sprite at runtime? 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