title: Removing a part of a tex2D before combining it
body: <p>Im coding a unity surface shader to slowly apply a rust effect like this:</p>
  
  <pre><code>//Take 1 base color texture.
  //Take 1 rust decal texture and 1 greyscale maps.
  //Take 1 float range value.
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>//Use the range to remove from the grayscale map all the pixels that are darker than the value itself, then make theese greysclae map the rust alpha, then apply this composited rust layer over the color texture.
  </code></pre>
  
  <p>I managed to do this:</p>
  
  <pre><code>        void surf (Input IN, inout SurfaceOutputStandard o) {
              half4 C = tex2D (_MainTex, IN.uv_MainTex); //Color Texture
              half4 R = tex2D (_RustTex, IN.uv_RustTex); //Rust texture
              half4 RG = tex2D (_RustGuide, IN.uv_RustGuide); //Greyscale texture
  
              //Here i need to compose the rust layer
              half4 RustResult = //??? Maybe a Clip() function or what? and how?
  
              //Here i apply the previusly composed layer over the color texture. Already tested and working.
              half4 Final = lerp (C, RustResult, RustResult.a);
              o.Albedo = c.rgb;
              o.Alpha = c.a;
          }
  </code></pre>
  
  <p>So how i can complete this shader?
  I cant find a detailed documentation about the usable functuons in surface shaders.</p>
  
  <p>EDIT: I almost get what i need using saturate(); functionlike the following</p>
  
  <pre><code>    Properties {
      _MainTex ("Base (RGB)", 2D) = "" {} //the color texture
      _RustTex ("Rust Texture (RGB)", 2D) = "" {} //the rust texture
      _RustGuide ("Rust Guide (A)", 2D) = "" {} //the rust greyscale texture
      _RustAmount ("Rust Amount", range(0.0, 1.0)) = 0.0 //the rust amount float value
      _RustMultiplier ("Rust Multiplier", float) = 2
  }
  
  SubShader {
      Tags { "RenderType"="Opaque" }
      LOD 200
  
      CGPROGRAM
      #pragma target 3.0
      #include "UnityPBSLighting.cginc"
      #pragma surface surf Standard
  
      sampler2D _MainTex;
      sampler2D _RustTex;
      sampler2D _RustGuide;
      float _RustAmount;
      float _RustMultiplier;
  
      struct Input {
          float2 uv_MainTex;
          float2 uv_RustTex;
          float2 uv_RustGuide;
      };
  
      void surf (Input IN, inout SurfaceOutputStandard o) {
          half4 M = tex2D (_MainTex, IN.uv_MainTex);
          half4 R = tex2D (_RustTex, IN.uv_RustTex);
          half4 RG = tex2D (_RustGuide, IN.uv_RustGuide);
          half4 RustResult;
          RustResult.rgb = R.rgb;
  
          if (_RustAmount &gt; 0) {
          RustResult.a = trunc(saturate(RG.a * _RustAmount * _RustMultiplier);
          }
  
          half4 Final = lerp (M, RustResult, RustResult.a);
          o.Albedo = Final.rgb;
          o.Alpha = Final.a;
      }
      ENDCG
  } 
  FallBack Off
  </code></pre>
  
  <p>}</p>
  
  <p>This makes the effect that I need. The only problem now is how i can blur the edges of the alpha?</p>