Distance related Flickering?

Archives Forums/Blitz3D Bug Reports/Distance related Flickering?

Kryzon(Posted 2009) [#1]
Hello everyone,
I would like to inform an issue that has been bothering me for a while now.
It seems that when polygons are very close together and very far away from the camera, the rasterizer has problems in deciding which pixel is in front of the other. I don't know if this is exclusive to B3D or Direct3D 7.

Anyhow, following with the appropriate bug-report thread format, here is a quick code portraying the problem first hand:

Graphics3D 800,600,0,2

camera = CreateCamera()
MoveEntity camera,0,0,-10

cube1 = CreateCube()
ScaleEntity cube1,5,5,1
EntityColor cube1,255,128,0
MoveEntity cube1,0,0,-0.0005 ;<------- VERY close distance.
TurnEntity cube1,10,0,5

cube2 = CreateCube()
ScaleEntity cube2,5,5,1
EntityColor cube2,0,0,255
TurnEntity cube2,10,0,5

AmbientLight 190,190,190

While Not KeyHit(1)

MoveEntity camera,0,0,KeyDown(200)*0.5-KeyDown(208)*0.5

RenderWorld()

Text 4,4,"Move the camera with Up and Down arrows."
Text 4,20,"Move the camera away from the meshes to see the flickering."
If EntityDistance(camera,cube1) > 75 Then Text 100,150,"Flickering should be happening right about now."

Flip
Wend

End


Just copy, paste & run. The directions are included within.

I had a lot of problem with this when I was making a castle that had windows that were separate meshes; when the camera was far away from the castle, the windows kept flickering.


big10p(Posted 2009) [#2]
This isn't a bug but a limitation of the z-buffer. The z-buffer doesn't have a linear accuracy - it works by giving greater accuracy the nearer to the camera objects are. That's why the cubes in your demo start 'z fighting' when they get far enough away from the camera for the z-buffer accuracy to drop off.

You should be able to reduce the effect by using a smaller camera range. You could also try using WBuffer instead but that didn't seem to make much difference on my old machine, TBH.


Kryzon(Posted 2009) [#3]
The WBuffer sounded really promising, but like you said, made no difference whatsoever.

So no work-around for that?

(camera range is out of the question. I'd have to use false-perspective and other tricks to make objects appear farther away than they really are...)


lo-tekk(Posted 2009) [#4]
Read this world famous article: Learning to Love your Z-buffer.

http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html


Kryzon(Posted 2009) [#5]
Oh, now I get what big10p meant with "smaller camera range" :)

Thanks for that article lo-tekk, it surely explains a lot.