Z-buffer Accuracy in 16 bit.

Blitz3D Forums/Blitz3D Programming/Z-buffer Accuracy in 16 bit.

John Pickford(Posted 2003) [#1]
Since I moved Sticky Balls to full 3D (graphics not gameplay), I'm finding the z-buffer a problem in 16 bit modes.

The game relies on objects intersecting (balls & struts and balls falling\rising through the table). In 16 bit modes this looks really rubbish and ugly, I'm assuming this is to do with the lack of accuracy of the 16 bit z buffer.

Is there any way I tweak this to get the max precision?

Previous experience with the N64 leads me to belive 16bit has enough precision for the effect I'm looking for. The game world is tiny (a snooker table + surround).

Any ideas?


GfK(Posted 2003) [#2]
I had a similar problem once.

Allegedly, you can try fiddling with the 'near' camerarange; i.e. set it to 0.1 instead of 1. Someone told me about this solving a similar problem that he had been having (although my problem was more to do with alpha textures than anything else as it turned out).

Also, I've found in the past that messing with CameraZoom can totally stuff up the draw order in some cases, so it could be that too.

You could also try switching WBuffer on and off to see if that makes a difference.

If I'm barking up completely the wrong tree, feel free to post a screenshot of the prob. :)


John Pickford(Posted 2003) [#3]
Here's a pic of the problem. The highlighted bit is some yellow balls sinking through the table.




Floyd(Posted 2003) [#4]
The only thing I can think of is to make the ratio of camerafar to cameranear as small as possible.

You want the maximum near value and minimum far value which still displays everything.

Note that CameraZoom is involved in this. By moving the camera farther away and increasing the zoom you can make the ratio far/near smaller.


John Pickford(Posted 2003) [#5]
I thought I had done all that.

I tried .1 and that made it wores but 10 made it a lot better!

I'll test some more to see if this causes any knock-on effects.


Floyd(Posted 2003) [#6]
Here's a little of example of the effect.
The restricted camera range seems to work.

Use the up arrow key to bring the sphere out of the cube.

Graphics3D 800, 600, 16, 1
AmbientLight 255,255,255

c = CreateCube()
ScaleEntity c, 5,5,5
EntityColor c, 100, 20, 100

s = CreateSphere(12)
EntityColor s, 255, 255, 0
PositionEntity s, 0, 3.99, 0

cam = CreateCamera()
PositionEntity cam, 0, 10, -10
TurnEntity cam, 25,0,0

CameraZoom cam, 5

; Try again with small range, far/near = 16/4 = 4.

; CameraRange cam, 4, 16

Repeat
	RenderWorld
	Flip
	If KeyDown(200) Then MoveEntity s, 0,  .001, 0  ; up arrow
	If KeyDown(208) Then MoveEntity s, 0, -.001, 0  ; down	
Until KeyDown(1)



Beaker(Posted 2003) [#7]
Floyd is correct you really need to get those numbers as close to each other as possible.

Look here for more info:
Learn to Love your Z-Buffer


simonh(Posted 2003) [#8]
Scaling everything down usually helps.

That screenshot looks lovely by the way!


Beaker(Posted 2003) [#9]
Simon - scaling things down will only make it worse. You really need to limit the near and far range of the z-buffer using CameraRange.


WendellM(Posted 2003) [#10]
I (among others) have hit something like this before. As GfK mentioned, changing WBuffer (in addition to fiddling with CameraRange) can sometimes help: http://blitzbasic.com/bbs/posts.php?topic=17009