- Home /
Motion Blur effect on Windows with multiple cameras
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
}
What do you mean you're using multiple camera passes? Do you actually render the camera manually using Camera.Render()? Or did you mean you use multiple cameras that are just with different depths to render one on top of the other?
Answer by StephanK · Aug 09, 2010 at 06:09 PM
This is not a really a solution for the original problem, but I found a workaround. If I change all calls to ImageEffects.Blit in the MotionBlur.cs file to Graphics.Blit it doesn't flip the image anymore. I'm not even sure why that works, but it did solve my problem. Still interested in a "clean" solution and explanation though... ;)
Your answer
Follow this Question
Related Questions
Anti-Aliasing causes post processing effects to flip. 3 Answers
How to force the compilation of a shader in Unity? 5 Answers
What is the right way to modify depth of field focal distance via script at runtime? 1 Answer
SSAO: How do I get rid of these artifacts? 0 Answers
Custom Brightness/Contrast shader doesn't work on OpenGL ES 2.0 0 Answers