Guest User

ThermalVisionImageEffect.shader

a guest
Dec 17th, 2019
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Hidden/ThermalVisionImageEffect"
  2. {
  3.     Properties
  4.     {
  5.         _Matcap("Texture", 2D) = "white" {}
  6.         [HideInInspector]_MainTex("Texture", 2D) = "white"{}
  7.         _Opacity("Normals Opacity", Range(0,2)) = 0.4
  8.    
  9.     }
  10.     SubShader
  11.     {
  12.         // No culling or depth
  13.         Cull Off ZWrite Off ZTest Always
  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.                 float4 pos : TEXCOORD1;            
  33.             };
  34.  
  35.             v2f vert (appdata v)
  36.             {
  37.                 v2f o;
  38.                 o.vertex = UnityObjectToClipPos(v.vertex);
  39.                 o.uv = v.uv;
  40.                 o.pos = v.vertex;          
  41.                 return o;
  42.             }
  43.             float _Opacity;
  44.             sampler2D _CameraDepthNormalsTexture;
  45.  
  46.             float4 GetPixelValue(in float2 uv) {
  47.                 half3 normal;
  48.                 float depth;
  49.                 DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, uv), depth, normal);
  50.  
  51.                 return fixed4(normal, depth);
  52.             }
  53.            
  54.             sampler2D _Matcap, _MainTex;
  55.  
  56.             fixed4 frag (v2f i) : SV_Target
  57.             {
  58.            
  59.             fixed4 normals = GetPixelValue(i.uv);
  60.             fixed4 color = tex2D(_MainTex, i.uv );         
  61.             float2 cap = normals.xy * 0.5 + 0.5;
  62.             fixed4 col = tex2D(_Matcap, cap * _Opacity);
  63.             return color + col;
  64.             }
  65.             ENDCG
  66.         }
  67.     }
  68. }
Add Comment
Please, Sign In to add comment