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
3
Question by Alex M · Sep 02, 2010 at 03:37 PM · shaderwalloutlineztest

Display complex object when it is behind the wall

In my project a player character can stand behind the wall. I want to draw it in front of all objects. An outline or solid color is good for me. I've found a similar topic(How to make an outline of an object behind a wall?) and implemented a simple shader that displays sphere in different colors when it is behind another object. Sphere Visible through wall

Shader "SolidColorWithZTest" 
{
    Properties 
    {
        _Color1 ("Color1", Color) = (1,1,1,1)
        _Color2 ("Color2", Color) = (1,1,1,1)
    }
    SubShader 
    {
        Tags { "Queue" = "Geometry+1" }
        Pass 
        { 
            ZTest Greater
            Color [_Color1]
        }
        Pass 
        { 
            ZTest Less
            Color [_Color2] 
        }
    }
}

I tried this approach on complex model such as player character, and got an issue. A solid color "pops-up" from back of model. Player Character With Artifacts I'm using character from Third Person Shooter Demo, and here is shader I'm using:

Shader "Texture With ZTest" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {} }

 Category 
 {
     SubShader 
     { 
         Tags { "Queue"="Overlay+1" }

         UsePass "Specular/BASE"
         Pass 
         {
             ZTest Less          
             SetTexture [_MainTex] {combine texture}
         }

         Pass
         {
             ZTest Greater
             Lighting Off
             Color [_Color]
         }
     }
 }

 FallBack "Specular", 1

}

What can be done to hide this white artifacts? Any suggestions are acceptable, including non-shader approach.

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

5 Replies

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

Answer by Jessy · Sep 02, 2010 at 04:46 PM

Just put the ZTest Greater pass before the ZTest Less pass.

Comment
Add comment · Show 4 · 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 Alex M · Sep 03, 2010 at 08:13 AM 0
Share

This is logical step. I tried it before asking a question and this did not work.

avatar image Jessy · Sep 03, 2010 at 03:49 PM 0
Share

That's because of your UsePass, which assumedly uses ZTest LEqual. Considering the UsePass is completely useless in this shader, take it out.

avatar image Alex M · Sep 03, 2010 at 07:58 PM 0
Share

Yes, thats it. I must get some exp in shader writing. I changed my character model to one which our modelers created and removed UsePass as you recommended. $$anonymous$$y new character has only one texture and now everything is good. Thanks a lot.

avatar image falsaform · Jul 07, 2013 at 03:47 AM 0
Share

Would you $$anonymous$$d sharing your final shader? I am having similar problems

Thanks

avatar image
1

Answer by peacefulshade · Feb 12, 2014 at 03:34 PM

I tested the shader and it almost worked, what was missing was to avoid writing to the depth buffer in the greater pass:

Shader "Texture With ZTest"{

 Properties 
 {
     _Color ("Main Color", Color) = (1,1,1,1)
     _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
 }
 
 Category 
 {
     SubShader 
     { 
         Tags { "Queue"="Overlay+1" }
 
         Pass
         {
             ZWrite Off
             ZTest Greater
             Lighting Off
             Color [_Color]
         }

         Pass 
         {
             ZTest Less          
             SetTexture [_MainTex] {combine texture}
         }
     }
 }
 
 FallBack "Specular", 1

}

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 Kaanin25 · Jul 28, 2014 at 03:43 PM 0
Share

This is exactly what I was looking for except it does not support alpha channel transparency for the texture. Anyone know how to do that?

Edit: I fixed it myself with some changes.

 SubShader
 {
     Tags { "Queue"="Overlay+1"
     "RenderType"="Transparent"}
      
     Pass
     {
         ZWrite Off
         ZTest Greater
         Lighting Off
         Color [_Color]
     }
      
     Pass
     {
         Blend SrcAlpha One$$anonymous$$inusSrcAlpha
         ZTest Less
          SetTexture [_$$anonymous$$ainTex] {combine texture}
     }
 }
avatar image
-1

Answer by incredibleHQ · Mar 25, 2015 at 03:23 PM

I dont know whatyou are going to do. I am hacking Unity Games for a while now and i am using a different way!

region Create Material

    void CreateWallhackMaterial()
     {
         if (!WallhackMaterial)
         {
             WallhackMaterial = new Material("Shader \"Custom/Cham\"{\tSubShader \t{\t\tPass \t\t{\t\t\tZTest Less\t\t\tZWrite On\t\t\tColor (1, 0.92, 0.016, 1) \t\t}\t\tPass \t\t{\t\t\tZTest Greater\t\t\tZWrite Off\t\t\tColor (1,0,0,1)\t\t}\t}}");
             WallhackMaterial.hideFlags = HideFlags.HideAndDontSave;
             WallhackMaterial.hideFlags = HideFlags.HideAndDontSave;
             WallMats= new Material[]
         {
             WallhackMaterial
             WallhackMaterial
             WallhackMaterial
             WallhackMaterial
             WallhackMaterial
             WallhackMaterial,
             WallhackMaterial,
             WallhackMaterial,
             WallhackMaterial,
             WallhackMaterial,
             WallhackMaterial
         };
         }
     }

endregion

call this void every frame (OnGUI()) and loop through the enemys! if u wanna see how that looks https://www.youtube.com/watch?v=x0n8hx63zag

I dont know if that helped but this is working for me ;)

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 Kaanin25 · Jul 29, 2014 at 04:32 PM

I tested the shader myself and I found that everything worked except it did not support any sort of alpha channel transparency so I fiddled with it and came up with this.

 Shader "Custom/NewShader" {
     Properties
     {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
     }
      
     Category
     {
         SubShader
         {
                Tags { "Queue"="Overlay+1"
                 "RenderType"="Transparent"}
      
             Pass
             {
                 Blend SrcAlpha OneMinusSrcAlpha
                 ZWrite Off
                 ZTest Greater
                 Lighting Off
                 SetTexture [_MainTex] {combine texture}
             }
      
                 Pass
             {
                 Blend SrcAlpha OneMinusSrcAlpha
                 ZTest Less
                 SetTexture [_MainTex] {combine texture}
             }
     
         }
     }
      
     FallBack "Diffuse"
 }

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 NetherChef · Oct 06, 2018 at 09:01 AM 0
Share

This works great! Could we somehow add a pass that colours the sprite when it's behind another object though?

avatar image
0

Answer by Charly75 · Sep 16, 2018 at 02:27 PM

Hey, the Main Color don't change the color of the texture, so I have a Text Mesh with this material, but the text appear black, I want it white and that don't work, how can I make Main Color work or download the font texture to change it color on photoshop ? thx

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

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

Ztest shader issues 0 Answers

Display object with subobjects when it's behind the wall 0 Answers

Is there a shader to draw outline of a solid sphere in unity 20.1.0a12 , that works in unity WebGL? 0 Answers

Silhouette Outline Shader and SpriteRenderer 0 Answers

2D Sprite Always Visible - Shader / Material not working (ZTest, ZWrite, Culling) 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