I want to fade out this Texture Masking Shader (using Rendertextures) and I need your help

So I just spent more than 8 hours researching on Google, Answers, Stackoverflow etc. why this wouldn’t work, to no avail:

I followed this tutorial here:

I used the instructions and shaders in there to make this “dust cleaning” effect work - but I have a problem fading out the image.
Here’s what I tried to do, in Properties I added an _Alpha Property as a Float:

    Properties {
        _MainTex ("Main", 2D) = "white" {}
        _MaskTex ("Mask", 2D) = "white" {}
        _Alpha ("Alpha", Float) = 0.5

Then I would try to insert that _Alpha Variable into this line of code (instead of the “1.0” that was there previously):

            fixed4 frag(vert2frag input) : COLOR
                fixed4 main_color = tex2D(_MainTex, input.texcoord);
                fixed4 mask_color = tex2D(_MaskTex, input.texcoord);
                fixed4 _Alpha;
                return fixed4(main_color.r, main_color.g, main_color.b, main_color.a * (_Alpha - mask_color.a));

So far so good, but instead of letting me change the Alpha Channel of the Texture it produces a strange “flickering” of the image on Mac, and on Windows it gives me this error:

Shader error in ‘TextureMasking’:
incorrect number of arguments to
numeric-type constructor at line 52
(on d3d11)

I really need help, I want a dust-cleaning effect for my sprites but also want to alpha-fade this. It seems like NO one has done this before (which seems strange) and I can’t find anything on the Asset Store (I would gladly pay for it at this point).

Can anyone help?

Pretty sure you have ‘fixed4 _Alpha’ in your frag shader when it shouldn’t be. ‘uniform float _Alpha’ should be somewhere just under CGPROGRAM outside of the functions/structs and you’ll be able to access the property in the frag function without issue.

Alright, I solved it:

Instead of

uniform fixed4 _Alpha;

I needed to write

uniform float _Alpha;

Thanks for your help! :slight_smile:

Found a PDF of the original tutorial - which is no longer available at that link: http://www.bitong-wang.com/wp-content/uploads/2016/03/DustRemoveEffect.pdf

Also, the Wayback Machine has the original page, minus a few graphics: How to remove dust/fog from an object in Unity with swipe?