Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "N2O/VFX/PostProcessing"
- {
- Properties
- {
- _MainTex ("Albedo (RGB)",2D)="white"{}
- }
- SubShader
- {
- Pass // Bloom mask
- {
- Cull Off ZWrite Off ZTest Always
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "Assets/Shaders/Utils/ShaderLib.cginc"
- sampler2D _MainTex;
- //float4 _MainTex_ST;
- uniform half4 _MainTex_TexelSize;
- uniform float _BloomIntensity;
- uniform float _LensIntensity;
- uniform sampler2D _LensTex;
- float4 _LensTex_ST;
- struct v2f
- {
- float4 pos : SV_POSITION;
- half2 uv : TEXCOORD0;
- half4 huv12 : TEXCOORD1;
- half4 huv34 : TEXCOORD2;
- half4 vuv12 : TEXCOORD3;
- half4 vuv34 : TEXCOORD4;
- };
- v2f vert(appdata_full v)
- {
- v2f o;
- o.pos = UnityObjectToClipPos(v.vertex);
- o.uv = v.texcoord.xy;
- half2 offs = _MainTex_TexelSize.xy * fixed2(4, 0);
- o.huv12.xy = o.uv + offs;
- o.huv12.zw = o.uv - offs;
- o.huv34.xy = o.uv + offs * 2;
- o.huv34.zw = o.uv - offs * 2;
- offs = _MainTex_TexelSize.xy * fixed2(0, 4);
- o.vuv12.xy = o.uv + offs;
- o.vuv12.zw = o.uv - offs;
- o.vuv34.xy = o.uv + offs * 2;
- o.vuv34.zw = o.uv - offs * 2;
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 col = tex2D(_MainTex, i.uv);
- col = col * 0.2;
- col += tex2D(_MainTex, i.huv12.xy) * 0.125;
- col += tex2D(_MainTex, i.huv12.zw) * 0.125;
- col += tex2D(_MainTex, i.huv34.xy) * 0.075;
- col += tex2D(_MainTex, i.huv34.zw) * 0.075;
- col += tex2D(_MainTex, i.vuv12.xy) * 0.125;
- col += tex2D(_MainTex, i.vuv12.zw) * 0.125;
- col += tex2D(_MainTex, i.vuv34.xy) * 0.075;
- col += tex2D(_MainTex, i.vuv34.zw) * 0.075;
- col = lerp(fixed4(0, 0, 0, 1), col, (col.a - 0.25) * _BloomIntensity);
- col += tex2D(_LensTex, i.uv) * _LensIntensity;
- return col;
- }
- ENDCG
- }
- Pass // Blending, motion blur, noise vignette
- {
- Cull Off ZWrite Off ZTest Always
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma shader_feature _BLOOM
- #pragma shader_feature _MOTION_BLUR
- #pragma shader_feature _NOISE
- #pragma shader_feature _VIGNETTE
- #include "Assets/Shaders/Utils/ShaderLib.cginc"
- sampler2D _MainTex;
- uniform half4 _MainTex_TexelSize;
- #ifdef _BLOOM
- uniform sampler2D _MaskTex;
- float4 _MaskTex_ST;
- #endif
- #ifdef _MOTION_BLUR
- uniform half2 _MotionBlurIntensity;
- uniform float _MotionBlurRadius;
- uniform float _MotionBlurSoftness;
- uniform float2 _CarCenter;
- #endif
- #ifdef _NOISE
- uniform float _NoiseSeed;
- uniform float _NoiseIntensity;
- #endif
- #ifdef _VIGNETTE
- uniform float _VignetteRadius;
- uniform float _VignetteSoftness;
- #endif
- uniform float _Saturation;
- struct v2f
- {
- float4 pos : SV_POSITION;
- half2 uv : TEXCOORD0;
- #ifdef _MOTION_BLUR
- half4 uv12 : TEXCOORD1;
- half4 uv34 : TEXCOORD2;
- half4 uv56 : TEXCOORD3;
- #endif
- };
- v2f vert(appdata_img v)
- {
- v2f o;
- o.pos = UnityObjectToClipPos(v.vertex);
- o.uv = v.texcoord.xy;
- #ifdef _MOTION_BLUR
- half2 offs = _MainTex_TexelSize.xy * _MotionBlurIntensity;
- o.uv12.xy = o.uv + offs;
- o.uv12.zw = o.uv - offs;
- o.uv34.xy = o.uv + offs * 2;
- o.uv34.zw = o.uv - offs * 2;
- o.uv56.xy = o.uv + offs * 3;
- o.uv56.zw = o.uv - offs * 3;
- #endif
- return o;
- }
- #ifdef _NOISE
- float rand(float2 uv)
- {
- float2 noise = (frac(sin(dot(_Time.x * uv, float2(12.9898, 78.233))) * 43758.5453));
- return abs(noise.x + noise.y) * 0.5;
- }
- #endif
- fixed4 frag(v2f i) : SV_Target
- {
- fixed4 col = tex2D(_MainTex, i.uv);
- float dist = 0;
- #ifdef _MOTION_BLUR
- fixed4 sum = col * 0.4;
- sum += tex2D(_MainTex, i.uv12.xy) * 0.15;
- sum += tex2D(_MainTex, i.uv12.zw) * 0.15;
- sum += tex2D(_MainTex, i.uv34.xy) * 0.1;
- sum += tex2D(_MainTex, i.uv34.zw) * 0.1;
- sum += tex2D(_MainTex, i.uv56.xy) * 0.05;
- sum += tex2D(_MainTex, i.uv56.zw) * 0.05;
- dist = length((i.uv - _CarCenter));
- dist -= _MotionBlurRadius;
- dist = clamp(dist, 0, 1);
- dist.x = 1 - dist * _MotionBlurSoftness;
- col = lerp(sum, col, dist.x);
- #endif
- #ifdef _BLOOM
- col += tex2D(_MaskTex, i.uv);
- #endif
- #ifdef _NOISE
- col.rgb += (rand(i.uv) + _NoiseSeed) * _NoiseIntensity;
- #endif
- #ifdef _VIGNETTE
- dist = length((i.uv - 0.5f));
- dist -= _VignetteRadius;
- dist = clamp(dist, 0, 1);
- dist.x = 1 - dist * _VignetteSoftness;
- col *= dist.x;
- #endif
- return Saturation(col, _Saturation);
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement