You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Driftology/Assets/FastMobileMotionBlur/FastMotionBlur.shader

103 lines
2.9 KiB
Plaintext

Shader "SupGames/FastMotionBlur_Subtle"
2 months ago
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_BlurStrength ("Blur Strength", Range(0, 1)) = 0.3
2 months ago
}
SubShader
{
Cull Off ZWrite Off ZTest Always
2 months ago
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float _Distance;
float _BlurStrength;
float4x4 _CurrentToPreviousViewProjectionMatrix;
2 months ago
struct v2f
{
half4 uv : TEXCOORD0;
half4 vertex : SV_POSITION;
half4 uv1 : TEXCOORD1;
half4 uv2 : TEXCOORD2;
2 months ago
};
v2f vert(appdata_img v)
2 months ago
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
half4 projPos = half4(v.texcoord.xy * 2.0h - 1.0h, _Distance, 1.0h);
half4 previous = mul(_CurrentToPreviousViewProjectionMatrix, projPos);
previous /= previous.w;
// Reduced velocity scale here!
half2 vel = (previous.xy - projPos.xy) * _BlurStrength;
o.uv.xy = v.texcoord.xy;
o.uv.zw = v.texcoord.xy + vel * 1.0h;
o.uv1.xy = v.texcoord.xy + vel * 2.0h;
o.uv1.zw = v.texcoord.xy + vel * 3.0h;
o.uv2.xy = v.texcoord.xy + vel * 4.0h;
o.uv2.zw = v.texcoord.xy + vel * 5.0h;
2 months ago
return o;
}
fixed4 frag(v2f i) : SV_Target
2 months ago
{
fixed4 col = tex2D(_MainTex, i.uv.xy);
col += tex2D(_MainTex, i.uv.zw);
col += tex2D(_MainTex, i.uv1.xy);
col += tex2D(_MainTex, i.uv1.zw);
col += tex2D(_MainTex, i.uv2.xy);
col += tex2D(_MainTex, i.uv2.zw);
return col * 0.166667h; // Average of 6 samples
2 months ago
}
ENDCG
}
2 months ago
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
2 months ago
sampler2D _MainTex;
sampler2D _BlurTex;
sampler2D _MaskTex;
struct v2f
{
half2 uv : TEXCOORD0;
half4 vertex : SV_POSITION;
};
v2f vert(appdata_img v)
2 months ago
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.texcoord.xy;
2 months ago
return o;
}
fixed4 frag(v2f i) : SV_Target
2 months ago
{
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 blur = tex2D(_BlurTex, i.uv);
fixed mask = tex2D(_MaskTex, i.uv).r;
return lerp(col, blur, mask);
2 months ago
}
ENDCG
}
}
}