- Home /
One-frame delay with 2 cameras
Hello everyone. Why does my render texture is sent from one camera to another with one-frame delay? Even if the cameras are standing still. Also cameras' depths are set correctly.
Heres the full description of the problem im having:
Im making an object motion blur shader, so this is what im doing:
1) I have 2 cameras, one for rendering velocities, the other one is main camera. Main camera depth is 0, velocity camera depth is -1 (it should render first). Velocity camera's parent is main camera.
2) First, velocity camera frees previous temporary RTs/does shader replacement (OnPreRender), renders/stores the RT in temporary RTS(OnRenderImage), sets all the shaders back(OnPostRender).
3) Then, main camera takes that temp RT and sets it as a texture in my post processing shader (OnRenderImage).
4) When i compare positions of the object on Source image from main camera, and on image from velocity camera, they are exactly one frame off on a velocity one.
Am i doing something wrong?
EDIT: I just checked, and for some reason, OnPostRender is called before OnRenderImage, on both cameras. But even after making changes in an order, it still has this one-frame delay.
Here are screenshots comparisons at the same frame:
I get a similar problem... (https://forum.unity3d.com/threads/bug-1-frame-delay-when-rendering-to-texture.367353/)
I found a workaround myself, but it doesn't look like it'd work in your case.
Well, of course "OnPostRender" is called before "OnRenderImage" since OnPostRender is called right after a camera has finished rendering while "OnRenderImage" is called when all rendering has finised to perform postprocessing on the actual screen.
Have a look at the event order here.
You might want to disable your velocity camera and render it manually. $$anonymous$$eep in $$anonymous$$d that you can directly render a camera with a replacement shader.
Your answer
Follow this Question
Related Questions
Easy way to render a texture, pixel perfectly, with a shader, and get the result? 0 Answers
Use camera depth texture to find distance from camera 0 Answers
,Can camera output negative values to render texture? 0 Answers
Check if mouse is over GUI element using Rendertexture? 1 Answer
Unity Grabpass Feature 1 Answer