- Home /
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.
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
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.
can you pass me the shader code? so i could have a look?
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                            
              }
                    
          }
          }
          }
           
  
 
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
         }    
      }
      
@Awesomepickle no problem :) would be nice if you could set it as correct answer!
cheers dan
Your answer
 
 
             Follow this Question
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
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                