Z-Order problems?

Blitz3D Forums/Blitz3D Programming/Z-Order problems?

Stevie G(Posted 2004) [#1]
If you've got a minute run this ...

Graphics3D 640,480,16,1

mirror = CreateMirror()
PositionEntity mirror,0,-.1,0
plane = CreatePlane()
PositionEntity plane,0,-.1,0
EntityColor plane,50,100,50
EntityAlpha plane,.75
light = CreateLight()
RotateEntity light,30,-45,0
camera=CreateCamera()
CameraZoom camera,6.75
PositionEntity camera,0,250,-250
PointEntity camera,plane
ground = quad()
ScaleMesh ground,45,1,45
EntityColor ground,50,50,100
EntityBlend ground,3
sphere = CreateSphere()
PositionMesh sphere,0,1,0
ScaleEntity sphere,4,4,4
EntityAlpha sphere,.5
UpdateNormals sphere
EntityShininess sphere,1

While Not KeyDown(1)

	TranslateEntity sphere,( KeyDown(205)-KeyDown(203) )*.25,0, (KeyDown(200)-KeyDown(208))*.25
	RenderWorld()
	Flip

Wend		


Function quad( parent=0, rx=0 ,s#=1 )

	mesh=CreateMesh(parent)
	surface=CreateSurface(mesh)
	AddVertex surface,-1,0,1,0,0
	AddVertex surface,1,0,1,1,0
	AddVertex surface,1,0,-1,1,1
	AddVertex surface,-1,0,-1,0,1
	AddTriangle surface,0,1,2
	AddTriangle surface,2,3,0
	RotateMesh mesh,rx,0,0	
	ScaleMesh mesh,s,s,s
		
	Return mesh
	
End Function



Can someone please explain why, when you move the sphere into the screen that the color switches to being much darker so quickly ? I've tried various camera ranges etc.. with no joy. I was beginning to think this was a bug .. please prove me wrong!!


DJWoodgate(Posted 2004) [#2]
I think it's because objects with alpha do not use the zbuffer and are drawn based on distance. So at the point when the sphere is more distant than the origin of the plane and ground it gets drawn first. In this case you could use entityorder so that the plane and ground are always drawn first.


Trixx(Posted 2004) [#3]
Yes, just like DJW said... just add EntityOrder sphere,-1


jfk EO-11110(Posted 2004) [#4]
MasterBeaker has released his Realtime Z-Sorter some time ago. It is the only solution known to mankind to fix this z-order issue with alpha objects. You'll find 2 of my demos in the code archive that are using it: realistic grass and forest. Although the first version of the grass demo doesn't use it and in the forest demo it is deactivated for some reason so you better use this version:
http://www.melog.ch/dl/grass_zorder_d.zip




sswift(Posted 2004) [#5]
If you want a single mesh with alpha to sort properly among itself then you need to look into how BSP trees are constructed, because you need to order the polygons a certain way to get the draw order to be right, and you may need to split some polygons to achieve this perfect draw order.

Imagine if you will a two sided cube with alpha. To draw it in the correct order, you would put all the inside faces into the mesh first, and then the outside faces. An inside face can never draw on top of an outside face, but the outside faces draw on top of the inside faces if you are outside the cube looking in.

But if you want multiple objects with alpha to sort properly amongst eachother, then you've got a problem which is currently not solveable in a satisfactory way. But give it a couple years and we will have zbuffers that work with transparency. I'm pretty sure they found a way to solve the problem.

Until then, your best bet is to use masking instead, if you're trying to render trees and grass.


Stevie G(Posted 2004) [#6]
Thanks for the tips guys. It had to be something as simple as that 'cos my single surface vertex alpha'd particles were working just fine (probably because the centre of the mesh was at the centre of the ground.

Anyway, I think using entityorder >0 on the plane & ground seems like the best idea as I don't want the z-buffer disabled for the objects on top of the ground.

I'm at work so can't check atm but someone please tell me that this won't affect the mirror 'cos I need it for the game I'm working on and I'm pretty sure I can't set any form of draworder on the mirror?


poopla(Posted 2004) [#7]
I dunno what the above Z-order fix does, we have to clear the surface's tri buffers in our particle system and rebuild
them with a quicksort. Works well however and doesn't kill a frame.


Rob(Posted 2004) [#8]
Is there a demo of your particle system?


Stevie G(Posted 2004) [#9]
The particle system is nothing fancy Rob, just does what it's paid for and nowt else. It may be of use to someone though.

It's a very simple game - pretty much a tank deathmatch with twin analogue controls ala Robotron, one for turret, other for tracks. Started it just last week and almost done.

I've designed it so that all graphics are generated in code etc.. so if anyone is interested I'll post what I have? Really just powerups / ai and a simple menu to add.