I am trying to use the Motion Blur effect from the Pro Standard Assets. It works as expected, but on windows it flips the image upside down. I know that this has to do with D3D9 api and I read about the fix in the manuals. Also the problem seems to be a bit bigger than the docs claim, as it doesn't happen to anti-aliased images only, but rather all the time on windows. I think this is because I'm using multiple camera passes, where the first one has the motion blur effect. However, as I'm quite new to shaders and Shader Lab I can't seem to figure out how to apply the fix to this particular image effect. My idea was to add an extra pass after the two original ones, that does the swapping in the fragment shader. My approach works as far as the swapping is concerned, but I also completely lose the blur effect, which makes me suspect that I'm somehow using the original textures before blurring occurred, but I don't know how to access the texture generated in the last pass. This is what I have so far:
Shader "Hidden/MotionBlur" {
Properties {
_MainTex ("Base (RGB)", RECT) = "white" {}
_AccumOrig("AccumOrig", Float) = 0.65
}
SubShader {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
Pass {
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
SetTexture [_MainTex] {
ConstantColor (0,0,0,[_AccumOrig])
Combine texture, constant
}
}
Pass {
Blend One Zero
ColorMask A
SetTexture [_MainTex] {
Combine texture
}
}
Pass {
CGPROGRAM
#include "UnityCG.cginc"
struct v2f {
float2 uv[4] : TEXCOORD0;
};
uniform float4 _MainTex_TexelSize;
uniform samplerRECT _MainTex : register(s0);
half4 frag (v2f v) : COLOR
{
half4 o;
#if SHADER_API_D3D9
if (_MainTex_TexelSize.y < 0)
v.uv[0].y = 1-v.uv[0].y;
#endif
o = texRECT(_MainTex, v.uv[0]);
return o;
}
#pragma fragment frag
ENDCG
}
}
Fallback off
}