Advertisement
Guest User

crt Shader

a guest
May 29th, 2018
2,675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Crt pixel"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture Pixel", 2D) = "white" {}
  6.         _ScansColor("Color Scans", COLOR) = (1,1,1,1)
  7.         _Tiles ("Tiles value", Range (1, 10000)) = 500
  8.         _VertsColor("Verts fill color", Range(0, 1)) = 0
  9.         _VertsColor2("Verts fill color 2", Range(0, 1)) = 0
  10.         _Contrast("Contrast", Range(-20, 20)) = 0
  11.         _Br("Brightness", Range(-200, 200)) = 0
  12.         _Density("Density", Range(0, 30)) = 0
  13.  
  14.         _Strength("Strenght curve", Range(-0.035, 30)) = 0.0
  15.         _DisplacementTex("Displace Text", 2D) = "white" {}
  16.         _Distort("Distortion", Range(-0.1, 0.1)) = 0.0
  17.         _OnOff("OnOff", Range(0.0, 1000.0)) = 1.0
  18.         _ScanDensity("Scan density", Range(0.0, 1.0)) = 1.0
  19.         _ScanThikness("Scan thick", Range(0.0, 500.0)) = 100.0
  20.         _ScanPoint("Scan point", Range(-200, 2000)) = 0.0
  21.     }
  22.     SubShader
  23.     {
  24.         // No culling or depth
  25.         Cull Off ZWrite Off ZTest Always
  26.  
  27.         Pass
  28.         {
  29.             CGPROGRAM
  30.             #pragma vertex vert
  31.             #pragma fragment frag
  32.            
  33.             #include "UnityCG.cginc"
  34.  
  35.             struct appdata
  36.             {
  37.                 float4 vertex : POSITION;
  38.                 float2 uv : TEXCOORD0;
  39.             };
  40.  
  41.             struct v2f
  42.             {
  43.                 float2 uv : TEXCOORD0;
  44.                 float4 scr_pos : TEXCOORD1;
  45.                 float4 vertex : SV_POSITION;
  46.             };
  47.  
  48.             float _Tiles;
  49.             sampler2D _MainTex;
  50.             float _VertsColor;
  51.             float _VertsColor2;
  52.             float _Contrast;
  53.             float _Br;
  54.             float4 _ScansColor;
  55.             float _Density;
  56.             float _Strength;
  57.             sampler2D _DisplacementTex;
  58.             float _Distort;
  59.             float _OnOff;
  60.             float _ScanDensity;
  61.             float _ScanThikness;
  62.             float _ScanPoint;
  63.  
  64.             v2f vert (appdata v)
  65.             {
  66.                 v2f o;
  67.  
  68.                 o.vertex = UnityObjectToClipPos(v.vertex);
  69.                 o.uv = v.uv;
  70.                 o.scr_pos = ComputeScreenPos(o.vertex);
  71.                 return o;
  72.             }
  73.  
  74.             float4 frag (v2f i) : SV_Target
  75.             {
  76.                 ///Curvature
  77.                 half2 n = tex2D(_DisplacementTex, i.uv);
  78.                 half2 d = n * 2 - 1;
  79.                 i.uv += d * _Strength;
  80.                 i.uv = saturate(i.uv);
  81.                 ///
  82.  
  83.                 //Distort image on y axis
  84.                 i.uv.y += _Distort;
  85.  
  86.                 float4 color = tex2D(_MainTex, i.uv);
  87.                
  88.                 //Vertical lines
  89.                 float2 ps = i.scr_pos.xy * _ScreenParams.xy / i.scr_pos.w;
  90.                 int pp = (int)ps.x % _Density;
  91.                 float4 outcolor = float4(0, 0, 0, 1);
  92.                 float4 muls = float4(0, 0, 0, 1);
  93.                 if (pp < _Density/3){
  94.                     outcolor.r = color.r;
  95.                     outcolor.g = color.g*_VertsColor;
  96.                     outcolor.b = color.b*_VertsColor2;
  97.                 }
  98.                 else if (pp < (2*_Density)/3){
  99.                     outcolor.g = color.g;
  100.                     outcolor.r = color.r*_VertsColor;
  101.                     outcolor.b = color.b*_VertsColor2;
  102.                 }
  103.                 else{
  104.                     outcolor.b = color.b;
  105.                     outcolor.r = color.r*_VertsColor;
  106.                     outcolor.g = color.g*_VertsColor2;
  107.                 }
  108.  
  109.                 //Horizontal lines
  110.                 if ((int)ps.y % _Density == 0) outcolor *= float4(_ScansColor.r, _ScansColor.g, _ScansColor.b, 1);
  111.  
  112.                 //Color correciton
  113.                 outcolor += (_Br / 255);
  114.                 outcolor = outcolor - _Contrast * (outcolor - 1.0) * outcolor *(outcolor - 0.5);
  115.  
  116.                 //Scan lines
  117.                 if ((i.scr_pos.y *_ScreenParams.y) >= _ScanPoint && (i.scr_pos.y *_ScreenParams.y) < _ScanPoint+ _ScanThikness)
  118.                 {
  119.                     outcolor *= _ScanDensity;
  120.                 }
  121.  
  122.                 return outcolor;
  123.             }
  124.             ENDCG
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement