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 /
  • Help Room /
avatar image
0
Question by joey-squla · Aug 29, 2016 at 07:51 AM · shadersshader programmingshaderlabimage-effects

Can't get Image Effect Transparency to work

I'm trying to write a image effect to transition one camera into the other but I'm stuck on this last problem for a while now and tried googling for solutions and reading up about Blending and Colormasks but so far came up dry. I hope that someone here can help me on my way.

The problem is that instead of Camera1 transitioning to transparent to show Camera2 underneath it, it transitions to black. My guess is that I'm doing something wrong with either the stencil buffer not setting pixels to transparent but to black or overlooking something in the shader setting alpha channel. If I applied the shader to a UI/Image the transparency did work though.

The setup is as followed:

Camera1: Depth Only, Ortho, Depth: 1

Camera 2: Depth Only, Ortho, Depth: 0

This is the code on Camera1 for Blitting:

 void OnRenderImage (RenderTexture src, RenderTexture dst)
         {
             if (TransitionMaterial != null) {
                 RenderTexture rnd = RenderTexture.GetTemporary (src.width, src.height, 0, RenderTextureFormat.ARGB32);
                 Graphics.Blit (rnd, dst, TransitionMaterial);
                 //RenderTexture.ReleaseTemporary (rnd);
             }
             
         }

And I'm blitting this shader to my 1st Camera:

 Shader "Custom/Masking"
 {
     Properties
     {
         _MainTex ("Main Texture", 2D) = "white" {}
         _MaskTex ("Mask Texture", 2D) = "white" {}
 
         _AmountSlider ("Mask Amount", Range (0,1)) = 0.4
         _Color ("Tint", Color) = (1,1,1,1)
         _Invert ("Invert", Float) = 0
  
         _ColorMask ("Color Mask", Float) = 15
 
     }
  
     SubShader
     {
         Tags
         {
             "Queue"="Transparent"
             "IgnoreProjector"="True"
             "RenderType"="Transparent"
             "PreviewType"="Plane"
             "CanUseSpriteAtlas"="True"
         }
      
         Stencil
         {
             Ref [_Stencil]
             Comp [_StencilComp]
             Pass [_StencilOp]
             ReadMask [_StencilReadMask]
             WriteMask [_StencilWriteMask]
         }
         ZWrite Off
         Cull Off
         Lighting Off
         ZTest Less
         Blend SrcAlpha OneMinusSrcAlpha
         ColorMask [_ColorMask]
          
         Pass
         {
         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
  
             #include "UnityCG.cginc"
             #include "UnityUI.cginc"
          
             struct appdata_t
             {
                 float4 vertex   : POSITION;
                 float4 color    : COLOR;
                 float2 texcoord : TEXCOORD0;
             };
  
             struct v2f
             {
                 float4 vertex   : SV_POSITION;
                 fixed4 color    : COLOR;
                 half2 texcoord  : TEXCOORD0;
                 float4 worldPosition : TEXCOORD1;
                 half2 screenpos : TEXCOORD2;
             };
          
             fixed4 _Color;
             fixed4 _TextureSampleAdd;
  
             bool _UseClipRect;
  
             v2f vert(appdata_t IN)
             {
                 v2f OUT;
                 OUT.worldPosition = IN.vertex;
                 OUT.vertex = mul(UNITY_MATRIX_MVP, OUT.worldPosition);
  
                 OUT.texcoord = IN.texcoord;
                  OUT.screenpos = ComputeScreenPos(OUT.vertex);
 
                 #ifdef UNITY_HALF_TEXEL_OFFSET
                 OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
                 #endif
              
                 OUT.color = IN.color * _Color;
                 return OUT;
             }
  
             sampler2D _MainTex;
             sampler2D _MaskTex;
               float _AmountSlider;
               float _Invert;
 
             fixed4 frag(v2f IN) : SV_Target
             {
                 float4 color = tex2D (_MainTex, IN.texcoord );
                 float alpha =  (abs(_Invert-(tex2D(_MaskTex, IN.screenpos).r)) - _AmountSlider) + 1;
                 float4 alpha_color = float4(color.r, color.g, color.b, smoothstep(alpha, 1, 0) * color.a);
                 return alpha_color;
             }
         ENDCG
         }
     }
 }



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

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

69 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

Related Questions

Shader error : unexpected $end, expecting TOK_SETTEXTURE or '}' at line 18 1 Answer

Writing a shader that emulates graphic novel coloring 0 Answers

Is there any way to do multiple passes on a texture / in a fragment shader? 1 Answer

Trying to make a masking shader and the areas that are supposed to be blank are culling the things behind it. 0 Answers

How to map letters on mesh with shader? 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