Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.02 KB | None | 0 0
  1. Shader "N2O/VFX/PostProcessing"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Albedo (RGB)",2D)="white"{}
  6.     }
  7.  
  8.     SubShader
  9.     {
  10.         Pass // Bloom mask
  11.         {
  12.             Cull Off ZWrite Off ZTest Always
  13.  
  14.             CGPROGRAM
  15.             #pragma vertex vert
  16.             #pragma fragment frag
  17.  
  18.             #include "Assets/Shaders/Utils/ShaderLib.cginc"
  19.            
  20.  
  21.             sampler2D _MainTex;
  22.             //float4 _MainTex_ST;
  23.             uniform half4 _MainTex_TexelSize;
  24.             uniform float _BloomIntensity;
  25.             uniform float _LensIntensity;
  26.             uniform sampler2D _LensTex;
  27.             float4 _LensTex_ST;
  28.  
  29.             struct v2f
  30.             {
  31.                 float4 pos : SV_POSITION;
  32.                 half2 uv : TEXCOORD0;
  33.                 half4 huv12 : TEXCOORD1;
  34.                 half4 huv34 : TEXCOORD2;
  35.                 half4 vuv12 : TEXCOORD3;
  36.                 half4 vuv34 : TEXCOORD4;
  37.             };  
  38.  
  39.             v2f vert(appdata_full v)
  40.             {
  41.                 v2f o;
  42.                 o.pos = UnityObjectToClipPos(v.vertex);            
  43.                 o.uv = v.texcoord.xy;
  44.  
  45.                 half2 offs = _MainTex_TexelSize.xy * fixed2(4, 0);
  46.                 o.huv12.xy = o.uv + offs;
  47.                 o.huv12.zw = o.uv - offs;
  48.                 o.huv34.xy = o.uv + offs * 2;
  49.                 o.huv34.zw = o.uv - offs * 2;
  50.  
  51.                 offs = _MainTex_TexelSize.xy * fixed2(0, 4);
  52.                 o.vuv12.xy = o.uv + offs;
  53.                 o.vuv12.zw = o.uv - offs;
  54.                 o.vuv34.xy = o.uv + offs * 2;
  55.                 o.vuv34.zw = o.uv - offs * 2;
  56.                 return o;
  57.             }
  58.            
  59.             fixed4 frag(v2f i) : SV_Target
  60.             {
  61.                 fixed4 col = tex2D(_MainTex, i.uv);
  62.  
  63.                 col = col * 0.2;
  64.                 col += tex2D(_MainTex, i.huv12.xy) * 0.125;
  65.                 col += tex2D(_MainTex, i.huv12.zw) * 0.125;
  66.                 col += tex2D(_MainTex, i.huv34.xy) * 0.075;
  67.                 col += tex2D(_MainTex, i.huv34.zw) * 0.075;
  68.  
  69.                 col += tex2D(_MainTex, i.vuv12.xy) * 0.125;
  70.                 col += tex2D(_MainTex, i.vuv12.zw) * 0.125;
  71.                 col += tex2D(_MainTex, i.vuv34.xy) * 0.075;
  72.                 col += tex2D(_MainTex, i.vuv34.zw) * 0.075;
  73.  
  74.                 col = lerp(fixed4(0, 0, 0, 1), col, (col.a - 0.25) * _BloomIntensity);
  75.                 col += tex2D(_LensTex, i.uv) * _LensIntensity;
  76.  
  77.                 return col;
  78.             }
  79.  
  80.             ENDCG
  81.         }
  82.  
  83.         Pass // Blending, motion blur, noise vignette
  84.         {
  85.             Cull Off ZWrite Off ZTest Always
  86.  
  87.             CGPROGRAM
  88.             #pragma vertex vert
  89.             #pragma fragment frag
  90.  
  91.             #pragma shader_feature _BLOOM
  92.             #pragma shader_feature _MOTION_BLUR
  93.             #pragma shader_feature _NOISE
  94.             #pragma shader_feature _VIGNETTE
  95.  
  96.             #include "Assets/Shaders/Utils/ShaderLib.cginc"
  97.            
  98.  
  99.             sampler2D _MainTex;
  100.             uniform half4 _MainTex_TexelSize;
  101.  
  102.             #ifdef _BLOOM
  103.                 uniform sampler2D _MaskTex;
  104.                 float4 _MaskTex_ST;
  105.             #endif
  106.  
  107.             #ifdef _MOTION_BLUR
  108.                 uniform half2 _MotionBlurIntensity;
  109.                 uniform float _MotionBlurRadius;
  110.                 uniform float _MotionBlurSoftness;
  111.                 uniform float2 _CarCenter;
  112.             #endif
  113.  
  114.             #ifdef _NOISE
  115.                 uniform float _NoiseSeed;
  116.                 uniform float _NoiseIntensity;
  117.             #endif
  118.  
  119.             #ifdef _VIGNETTE
  120.                 uniform float _VignetteRadius;
  121.                 uniform float _VignetteSoftness;
  122.             #endif
  123.  
  124.             uniform float _Saturation;
  125.  
  126.             struct v2f
  127.             {
  128.                 float4 pos : SV_POSITION;
  129.                 half2 uv : TEXCOORD0;
  130.                 #ifdef _MOTION_BLUR
  131.                     half4 uv12 : TEXCOORD1;
  132.                     half4 uv34 : TEXCOORD2;
  133.                     half4 uv56 : TEXCOORD3;
  134.                 #endif
  135.             };  
  136.        
  137.             v2f vert(appdata_img v)
  138.             {
  139.                 v2f o;
  140.                 o.pos = UnityObjectToClipPos(v.vertex);            
  141.                 o.uv = v.texcoord.xy;
  142.            
  143.                 #ifdef _MOTION_BLUR
  144.                     half2 offs = _MainTex_TexelSize.xy * _MotionBlurIntensity;
  145.                     o.uv12.xy = o.uv + offs;
  146.                     o.uv12.zw = o.uv - offs;
  147.                     o.uv34.xy = o.uv + offs * 2;
  148.                     o.uv34.zw = o.uv - offs * 2;
  149.                     o.uv56.xy = o.uv + offs * 3;
  150.                     o.uv56.zw = o.uv - offs * 3;
  151.                 #endif
  152.  
  153.                 return o;
  154.             }
  155.  
  156.             #ifdef _NOISE
  157.                 float rand(float2 uv)
  158.                 {
  159.                     float2 noise = (frac(sin(dot(_Time.x * uv, float2(12.9898, 78.233))) * 43758.5453));
  160.                     return abs(noise.x + noise.y) * 0.5;
  161.                 }
  162.             #endif
  163.        
  164.             fixed4 frag(v2f i) : SV_Target
  165.             {
  166.                 fixed4 col = tex2D(_MainTex, i.uv);
  167.  
  168.                 float dist = 0;
  169.                 #ifdef _MOTION_BLUR
  170.                     fixed4 sum = col * 0.4;
  171.                     sum += tex2D(_MainTex, i.uv12.xy) * 0.15;
  172.                     sum += tex2D(_MainTex, i.uv12.zw) * 0.15;
  173.                     sum += tex2D(_MainTex, i.uv34.xy) * 0.1;
  174.                     sum += tex2D(_MainTex, i.uv34.zw) * 0.1;
  175.                     sum += tex2D(_MainTex, i.uv56.xy) * 0.05;
  176.                     sum += tex2D(_MainTex, i.uv56.zw) * 0.05;
  177.  
  178.                     dist = length((i.uv - _CarCenter));
  179.                     dist -= _MotionBlurRadius;
  180.                     dist = clamp(dist, 0, 1);
  181.                     dist.x = 1 - dist * _MotionBlurSoftness;
  182.  
  183.                     col = lerp(sum, col, dist.x);
  184.                 #endif
  185.  
  186.                 #ifdef _BLOOM
  187.                     col += tex2D(_MaskTex, i.uv);
  188.                 #endif
  189.  
  190.                 #ifdef _NOISE
  191.                     col.rgb += (rand(i.uv) + _NoiseSeed) * _NoiseIntensity;
  192.                 #endif
  193.  
  194.                 #ifdef _VIGNETTE
  195.                     dist = length((i.uv - 0.5f));
  196.                     dist -= _VignetteRadius;
  197.                     dist = clamp(dist, 0, 1);
  198.                     dist.x = 1 - dist * _VignetteSoftness;
  199.                     col *= dist.x;
  200.                 #endif
  201.                 return Saturation(col, _Saturation);
  202.             }  
  203.  
  204.             ENDCG
  205.         }
  206.     }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement