Sign in to follow this  
tnarol

[Direct3D] Please help me reduce flickering

Recommended Posts

Hi, I'm experiencing a disturbing flickering effect when drawing 1 pixel wide vertical lines that slowly move across the screen from a pixel to the next. I'm refreshing display every 100 ms using a single backbuffer where everything is redrawn. The lines are drawn using DrawPrimitiveUP (not using a vertex buffer). Flickering is more visible with colors like grey and white, so I'm wondering if this has a relationship with the screen ability to light all 3 colors (RGB). What can I try to improve things ? Thanks

Share this post


Link to post
Share on other sites
What do you mean by flickering? Is only the single-pixel line flickering, or the whole screen?

How do you "refresh display every 100 ms using a single backbuffer"? Are you clearing the buffer before drawing to it again?

What happens if you take a screenshot with PrintScreen? Does it look correct or does it have any artifacts on it?

Share this post


Link to post
Share on other sites
Hi,

Only the vertical lines are flickering. Other lines (not vertical) that I draw and move, don't have the same problem. I guess this is because these lines are being aliased in a different way at every refresh meaning their moves on pixels is smoother.

I am clearing the buffer, then rendering the scene, then presenting the buffer...

I don't know much about the management of buffers by Direct3D but I'm quite certain that the result of the clear is not displayed until I call the next Present() on my 3D device, in other terms the next image is completely rendered in the backbuffer when the display occurs. As a result I could check there is no missing line on a Printscreen.

Share this post


Link to post
Share on other sites
Are you forcing VSYNC off via your driver and/or application (using D3DPRESENT_INTERVAL_IMMEDIATE when creating your device)? Disabling VSYNC can introduce tearing which may well be what you're describing.

Alternatively, if you're hitting aliasing due to rasterization rules you might want to try enabling MSAA if your hardware supports it. Whilst this isn't necessarily a solution it might well allow you to isolate the cause of the problem - as the name suggests, MSAA should reduce/eliminate aliasing errors [smile]

Finally, have you tried running it against the reference rasterizer? When getting odd results its always a good idea to verify it isn't your hardware/drivers that are the problem...

hth
Jack

Share this post


Link to post
Share on other sites
This is because the present is not synced to the vertical retrace. The only way to fix this for sure is to run in fullscreen mode, with a present interval that allows for vsync.

You can, perhaps, sit in a tight loop checking GetRasterStatus() (or whatever the device scanline return function is called), and calling Present() when it approaches 80% of max, but that's a weak hack at best, and will not work right on all hardware/display combinations.

Share this post


Link to post
Share on other sites
Yes, my application is windowed and I'm using D3DPRESENT_INTERVAL_IMMEDIATE. I tryed changing this to D3DPRESENT_INTERVAL_ONE but it doesn't change anything. What else can I do if I don't want to run fullscreen ?

I don't thing my problem has something to do with rasterization rules because my line are strictly vertical and always drawn exactly on a line of pixels (no pixels aside are affected).

Share this post


Link to post
Share on other sites
Quote:
Original post by tnarol
Yes, my application is windowed and I'm using D3DPRESENT_INTERVAL_IMMEDIATE. I tryed changing this to D3DPRESENT_INTERVAL_ONE but it doesn't change anything. What else can I do if I don't want to run fullscreen ?
The values set for your presentation parameters don't tend to have any guarantee. VSYNC in particular tends to get overridden by some drivers (e.g. mine have "always off", "always on" or "application preference" options). Could be worth checking the properties for your device - force it on or make sure that the application has the ability to decide.

hth
Jack

Share this post


Link to post
Share on other sites
I have a Geforce FX 5200 and I found the following possibly relevant settings :
- Display timing
- Vertical Sync
- Mipmap detail level

Which one would you play with ?

Share this post


Link to post
Share on other sites
Please, try to describe the effect you are experiencing. By flickering do you mean that the line does not move 'smoothly', that is, it seems to disappear and reappear on the next pixel, or that it seems to be 'broken' (one piece of the line moves to the next position while the rest stays behind).

If it is the first effect, make sure you are moving the line a single pixel at a time. If you move it, say, by a fraction of a pixel every frame, you will encounter this behavior since the line cannot be represented when it lies between two pixels.

Moving by a whole pixel (which means making your program resolution dependent) will eliminate this. Otherwise, setting a higher resolution, or enabling supersampling antialiasing will lessen the effect (unfortuantely your card does not support supersampling aa).

If it is the second effect, you can try matching the update frequency to a fraction of the monitor's vertical refresh frequency. If your monitor updates at 85 Hz, that is every 11.76 msec, updating the line every 100 msec will result in visual 'tearing', since the update will fall between two screen refreshes. Try altering your program to update every 117.6 msec (although it is difficult to time so precisely). Vsyncing will effectively have the same effect, but it is _not_ possible to vsync when your program runs in a window (at least I've never encountered a driver that could work this kind of magic).

Note that the second kind of flickering never appears on TFTs, since they refresh the whole picture at once.

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