Sign in to follow this  
Omroth

Rendering at exactly 50hz

Recommended Posts

Omroth    122
Hey guys.

I wish to render at exactly 50hz in my DirectX program. Using the Windows High Performance Timer I believe I have achieved this.

However, the output looks ever so *slightly* jerky. I have a bitmap moving straight accross the screen and it looks *just* off.

My question is - is there anything I'm missing here? Would there be a reason why the graphics card may not output this in a regular enough fashion to look smooth to the human eye?

Any help is much appreciated,
Thanks,
Ian

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
What refresh rate is your monitor set to?
Most monitors use 60 Hz or a higher rate by default, which will give you some artifacts when rendering at a lower rate. In order to get perfect smoothness you must render at exactly the monitor refresh rate, and also present your scene exactly in between monitor refreshes. The best way is to select the most fitting monitor refresh rate and rely on VSync to render at exactly that speed, and the only way to get it perfect.

Share this post


Link to post
Share on other sites
Omroth    122
Thanks Erik.

I have enabled vSync and switched to 60hz - it looks significantly better.

I still have a little hitch every couple of seconds, which I presume is because I'm not feeding quite enough frames, or maybe slightly too many.

What is the behavour of DirectX VSync if I send 62 or 58 frames when the monitor is refreshing at 60?

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
If you have enabled VSync you should remove your own frame delay and draw as fast as possible. DirectX will automatically delay displaying the frames so they match the screen refresh perfectly (Present will block when necessary). For best performance make sure you can draw at least a few more frames than the refresh rate, so that there is never a time when a frame is missing at refresh time.

What DirectX version are you using?
In D3D9 you can use D3DPRESENT_INTERVAL_IMMEDIATE for the D3DPRESENT_PARAMETERS::PresentationInterval parameter in order to render as fast as possible, or D3DPRESENT_INTERVAL_ONE to draw with VSync. In D3D10/11 you specify the present interval when Presenting with your swap-chain.

Share this post


Link to post
Share on other sites
Omroth    122
Thanks again Erik. I'm using DX9.

But if I render *really* fast, then surely DX will have to throw away frames - under what algorithm does it do this?

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
No it doesn't throw away anything. Present will block when necessary, and act as your custom timer does now. So even if you draw at 1000 FPS with D3DPRESENT_INTERVAL_IMMEDIATE, it will stay at exactly 60 with D3DPRESENT_INTERVAL_ONE. Present has code to do the same delay you do yourself, just that it does it with VSync instead to get perfect sync to the refresh rate.

Share this post


Link to post
Share on other sites
Omroth    122
What if I'm not calling Present? Or is that very unlikely.

It's important that I know which part of my renderer will actually block.

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
Present will block, and without it you will not see anything on the screen. If you want to render images without displaying them, then vsync doesn't matter so then you can use your own timer.

Share this post


Link to post
Share on other sites
Omroth    122
I've checked my render pipeline, and I do indeed call Present and *not* with the DO_NOT_WAIT flag.

But my results are that it is not blocking when I give it lots of frames - it just seems to overwrite.

Is it possible that it buffers several frames before blocking? My data looks like it might block only every third frame.

I'm running in windowed mode and Windows is set to 60hz.

(Thanks for the continued help)

Share this post


Link to post
Share on other sites
Ezbez    1164
While mostly tangential, I'd like to point out that jerky movement could be caused by other things than an uneven refresh rate. For example, if the square was moving at 0.667 pixels per frame then every third frame it could appear to not move.

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
Do you use D3DPRESENT_INTERVAL_ONE?
Also, check your graphics card control panel, and see what your VSync settings are. Make sure that you're not forcing VSync off.
Some frames can be buffered (usually 3, should also be available in the graphics card control panel), but that should only cause your first 3 frames to be calculated really fast, but still displayed at exactly 16.67ms intervals. You could use your own timer to check the time between frames and display it, and compare what you get with D3DPRESENT_INTERVAL_ONE and D3DPRESENT_INTERVAL_IMMEDIATE, to make sure VSync is actually enabled. I'm also not sure window mode always obeys the settings, try in fullscreen if you can't get it to work.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this