Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Awesomepickle · Aug 13, 2018 at 05:39 AM · shadershadersstencil

Problem with transparency and stencil shader

Hi, so I'm making a liquid mesh look like its inside a bottle with a stencil shader and it looks pretty good, but I thought I could make it look better by trying to make the liquid mesh transparent so it blends in better. However, when I try to turn down the alpha in the color sliders it will not change. I also tried messing with zwrite by turning it off, but all that did is make the object dissapear altogether. I am fairly new to working with shaders and coding in general so please forgive me if I'm missing something really obvious.alt text

1.png (146.7 kB)
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
0

Answer by dan_wipf · Aug 13, 2018 at 05:54 AM

might you want to change this in the line of the tag:

 Tags {“Queue”=“Transparent” “RenderType” =“Transparent”}
 
 ZWrite = Off


EDIT: after ZWrite Off add the Line:

 Blend SrcAlpha OneMinusSrcAlpha
Comment
Add comment · Show 8 · 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 Awesomepickle · Aug 13, 2018 at 06:28 PM 0
Share

Thanks for the suggestion, I tried it and it just made it white and semi transparent (I think?). I still can't mess with the alpha and now the color isn't working.alt text

2.png (140.1 kB)
avatar image dan_wipf · Aug 13, 2018 at 06:35 PM 0
Share

can you pass me the shader code? so i could have a look?

avatar image Awesomepickle dan_wipf · Aug 13, 2018 at 06:58 PM 0
Share

This is the one used on the bottle

 Shader "Custom/bottlefix" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _$$anonymous$$ainTex ("Albedo (RGB)", 2D) = "white" {}
         _Glossiness ("Smoothness", Range(0,1)) = 0.5
         _$$anonymous$$etallic ("$$anonymous$$etallic", Range(0,1)) = 0.0
     }
 SubShader
  {
          Tags 
          {  
              "RenderType"="Transparent" 
              "Queue"="Transparent"
          }
          
              Cull Off
          Lighting Off
          ZWrite Off
          Blend Zero One$$anonymous$$inusSrcAlpha
            Pass
           {
              Stencil
              {
                  Ref 6
                  Comp always
                  Pass replace
  
              }
 
              Blend Zero One
      }
      
      }
      }
      
      
      
      

This one is used on the liquid mesh

 Shader "Unlit/StencilFilter"
 {
 
     Properties
     {
      _Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
    
     [Enum(Equal,3,NotEqual,6)] _StencilTest ("Stencil Test", int) = 6
 
     
     }
 
 
 
     SubShader 
     {
      
         Color  [_Color] 
         Stencil{
             Ref 1
             Comp [_StencilTest]
         }
     
     Pass 
     {
     }
     
     
     }    
     }
     
 


and this is a fix someone gave me so I am also using this shader along with the previous one on the liquid mesh

 Shader "Custom/stencilfix" {
     Properties {
         _Color ("Color", Color) = (1,1,1,1)
         _$$anonymous$$ainTex ("Albedo (RGB)", 2D) = "white" {}
         _Glossiness ("Smoothness", Range(0,1)) = 0.5
         _$$anonymous$$etallic ("$$anonymous$$etallic", Range(0,1)) = 0.0
     }
   SubShader
  {
          Tags 
          { 
           
              "RenderType"="Transparent" 
              "Queue"="Transparent+1"
          }
          
              Cull Off
          Lighting Off
          ZWrite Off
          Blend One One$$anonymous$$inusSrcAlpha
  
          Pass
           {
              Stencil
              {
                  Ref 6
                  Comp equal 
                  ZFail decrWrap                            
              }
                    
          }
          }
          }
           
  
 

avatar image dan_wipf Awesomepickle · Aug 14, 2018 at 05:56 AM 0
Share

Let me know if this is what you're looking for:


 Shader "Unlit/StencilFilter"
  {
  
      Properties
      {
         _Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
         [Enum(Equal,3,NotEqual,6)] _StencilTest ("Stencil Test", int) = 6
      }
 
      SubShader 
      {
       
         
             Color [_Color] 
             Stencil{
                 Ref 1
                 Comp [_StencilTest]
             }
 
      CGPROGRA$$anonymous$$
 
             #pragma surface surf Standard alpha:fade
             #pragma target 3.0
     
             sampler2D _$$anonymous$$ainTex;
     
             struct Input {
                 float2 uv_$$anonymous$$ainTex;
             };
 
             fixed4 _Color;
     
             void surf (Input IN, inout SurfaceOutputStandard o)
             {
                 fixed4 c = tex2D (_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex) * _Color;
                 o.Albedo = c.rgb;
                 o.Alpha = c.a;
             }
             ENDCG
         }    
      }
      
Show more comments
avatar image dan_wipf · Aug 17, 2018 at 09:01 PM 0
Share

@Awesomepickle no problem :) would be nice if you could set it as correct answer!

cheers dan

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

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

Related Questions

Standard Shader Still Visible through Stencil Shader 0 Answers

Deferred Light Rendering: Prevent additional lighting passes on pixels in overlapping point lights 0 Answers

Stencil buffer alternative in deferred shading 0 Answers

Multi-shader Stencil Buffer not working as expected,Multi-shader Stencil not working as expected 0 Answers

Stencil buffer on mobile 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