Advertisement
Guest User

ImageEffectGradientMap

a guest
Aug 7th, 2020
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Hidden/GradientMap"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _GradientMap("Gradient Map", 2D) = "white" {}
  7.         _Intensity("Intensity", Range(0,10)) = 1
  8.     }
  9.     SubShader
  10.     {
  11.         // No culling or depth
  12.         Cull Off ZWrite Off ZTest Always
  13.  
  14.         Pass
  15.         {
  16.             CGPROGRAM
  17.             #pragma vertex vert
  18.             #pragma fragment frag
  19.  
  20.             #include "UnityCG.cginc"
  21.  
  22.             struct appdata
  23.             {
  24.                 float4 vertex : POSITION;
  25.                 float2 uv : TEXCOORD0;
  26.             };
  27.  
  28.             struct v2f
  29.             {
  30.                 float2 uv : TEXCOORD0;
  31.                 float4 vertex : SV_POSITION;
  32.             };
  33.  
  34.             v2f vert (appdata v)
  35.             {
  36.                 v2f o;
  37.                 o.vertex = UnityObjectToClipPos(v.vertex);
  38.                 o.uv = v.uv;
  39.                 return o;
  40.             }
  41.  
  42.             sampler2D _MainTex, _GradientMap;
  43.             float _Intensity;
  44.  
  45.             fixed4 frag (v2f i) : SV_Target
  46.             {
  47.                 fixed4 col = tex2D(_MainTex, i.uv);
  48.                
  49.         // take the 3 color channels and average them out to create a grayscale version
  50.         float grayscale = (col.r + col.g + col.b) / 3;
  51.         // control the intensity
  52.         grayscale *= _Intensity;
  53.         // project the gradient map over the grayscale
  54.         fixed4 gradient = tex2D(_GradientMap, grayscale);
  55.         // get the transparency
  56.         gradient *= gradient.a;
  57.         // add original camera view back where the gradient is transparent
  58.         gradient += (1 - gradient.a) * col;
  59.  
  60.                 return gradient;
  61.             }
  62.             ENDCG
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement