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 vexe · May 15, 2015 at 03:44 AM · 2dshaderoutlinesurface shader

2D Outline shader issue: Apply outline on separate sprites as a whole?

Hi all,

so I have this 2d outline shader which is a modified version of the shader in the comment to this answer. The idea is to represent health in an outline, you start with full health = full outline = green. As hp goes down, the outline fill decreases and it becomes red.

The issue however is that I was testing it on a single sprite, when I came to the actual model that we're using, it turned out that it was a complex sprite made out of many renderers. Every piece acts on its own now :(

Please see this video demonstrating the problem.

Here's a simplified version of the shader without the "Fade to black" and "Fill inside" portions seen in the video, just the outline and thickness:

 Shader "Custom/2DOutline"
 {
     Properties
     {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _Width ("Thickness", Range(0, 1)) = 0.5
         _Fill ("Filling", Range(0 , 1)) = 1
     }
 
     SubShader
     {
         Lighting Off
         LOD 110
 
         CGPROGRAM
         #pragma surface surf Lambert alpha
 
         struct Input
         {
             float2 uv_MainTex;
             fixed4 color : COLOR;
         };
 
         sampler2D _MainTex;
         float _Width;
         float _Fill;
 
         void surf(Input IN, inout SurfaceOutput o)
         {
             if (IN.uv_MainTex.y > _Fill)
             {
                 fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
                 o.Albedo = c.rgb;
                 o.Alpha = c.a;
             }
             else
             {
                 _Width /= 100;
 
                 fixed4 TempColor = tex2D(_MainTex, IN.uv_MainTex + float2(_Width, _Width))
                                  + tex2D(_MainTex, IN.uv_MainTex - float2(_Width, _Width));
 
                 fixed4 OutlineColor = 0;
                 OutlineColor.r = (1 - _Fill) / (_Fill * _Fill);
                 OutlineColor.g = _Fill;
                 OutlineColor.b = 0;
                 OutlineColor.a = 1;
 
                 fixed4 AlphaColor = (0, 0, 0, TempColor.a);
                 fixed4 MainColor = AlphaColor * OutlineColor.rgba;
                 fixed4 TexColor = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
 
                 if(TexColor.a > 0.95)
                     MainColor = TexColor;
 
                 o.Albedo = MainColor.rgb;
                 o.Alpha = MainColor.a;
             }
         }
         ENDCG
     }
 
     Fallback "Diffuse"
 }

The goal is to make the shader work with multiple renderers the same way did with a single one i.e. have the outline applied on the whole model not on each individual piece. I'm not sure how to. I tried comparing IN.worldPos.y to _Fill but didn't work, I figured if I go with world space and not the texture coord things should improve, no dice.

Any ideas?

Thanks!

Edit: Forums crosslink.

Comment
Add comment · Show 1
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 nashella · Aug 11, 2015 at 07:12 PM 1
Share

Hi, I need something like this too! Did you find a solution since you asked this question?

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

20 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 avatar image avatar image avatar image

Related Questions

Edge outline & 2D shadow Shader for planar mesh 0 Answers

Outline Overlapping Game Objects 1 Answer

2d lighting effect 1 Answer

Combine Shaders 0 Answers

one shader for multiple sprites 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