Z-Order problems with EntityAlpha?!

Blitz3D Forums/Blitz3D Programming/Z-Order problems with EntityAlpha?!

Picklesworth(Posted 2006) [#1]
Okay... this is probably partly my fault, and reasonably fixable.

I have a bunch of flattened, wide cylinders suspended in midair, and they are all semi transparent.

When viewed at various camera angles, the drawing order for these objects becomes confused, and they end up looking really weird.

It takes a bit of camera moving to notice, but it's definietly there and a really big graphical problem.

I have tried using Beaker/Fredborg's z-sorting code, but it looks like it solves a different problem from mine.


This is the creation function for the platforms:
b.board=New board
	b\obj=Object_Create()
	;#Region Visual
	b\obj\vis\mesh=CreateCylinder(64)
	ScaleMesh(b\obj\vis\mesh,size,0.05,size)
	EntityPickMode(b\obj\vis\mesh,2)
	
	Texture=CreateTexture(64,64)
	SetBuffer TextureBuffer(Texture)
	For y=0 To 1:For x=0 To 1
		If ( x + y ) Mod 2 = 0 Color 128,32,128 Else Color 64,16,64 
		Rect x*32,y*32,32,32,1
	Next:Next			
	SetBuffer BackBuffer()
	ScaleTexture Texture,0.1,0.1
	TextureBlend Texture,2
	
	EntityTexture(b\obj\vis\mesh,Texture)


(And don't ask about the thousands of linked type instances... I do have a reason for it to be like that, and I've been meaning to do it for ages.)


You can download the program to see it for yourself:
http://crumbsoftware.f2o.org/files/zsortproblem.zip


What is going on here, and how can I fix this?

Is Beaker's zsorting fix actually the fix for this? If so, am I doing it properly by using ZOrder_Init with each individual platform? (It didn't seem to work).

The cylinders need to all be independantly moveable. There will never be an event where one sticks through another, so I guess I could, if I must, use a solution with linepicks :(
Unless someone else already has...


DJWoodgate(Posted 2006) [#2]
Blitz decides the draw order of alpha objects based on the distance of the objects origin from the camera because alpha objects do not write to the Zbuffer. That's what is going on. Beakers fix has nothing to do with this problem, at least not at this level. It is intended to sort overlapping polys in the same surface based on distance from camera. Your platforms do not need this.


_PJ_(Posted 2006) [#3]
Try sticking an EntityOrder entity,0
Just a thought, it might kick the z-buffer back into the right order.


DJWoodgate(Posted 2006) [#4]
As far as the Zbuffer is concerned alpha objects do not exist. Alpha objects do not write to the Zbuffer. They just read from it, so they have no problem drawing in front of or behind non alpha objects. That is why blitz orders their drawing manually based on their distance from the camera. This can fail to achieve the desired result when they overlap and an alpha object further from the camera extends in front of an alpha object which has its origin closer to the camera. I think Entityorder forgoes use of the Zbuffer altogether, so I suspect it is not going to be of much use in this context.

Not sure what you had in mind with your linepick approach. I think it may be possible to get overlapping alpha objects to draw in the right order, but I suspect it is way more trouble than it is worth since you have to work around the default behaviour.


Beaker(Posted 2006) [#5]
There are a few possible solutions to this:

You could try splitting the platform meshes up into 4 quarters and moving the handles for them to the outer edge of the platform.

Alternatively: you could override the drawing order for each mesh by parsing the vertices of each and determining which has a vert closest to the camera. This one would be drawn last.

Not sure how succesful each of these solutions would be. I suspect the first one would be best.

Good luck.


Ross C(Posted 2006) [#6]
What about multiple rendering passes?


Picklesworth(Posted 2006) [#7]
So... If I could reposition the object's origin so that it's always in view, to "trick" Blitz (with a slight risk of objects bouncing around in weird ways).

Or, I could give up entityalpha() altogether and use a different approach with refraction, tinting, and other fun stuff based around the cube mapped reflections.

I think I'll try checking the verts first, and probably use multirendering to sort it all if entityorder doesn't work.

Or I could just remove alpha, and save it for another day.


Thanks for the help :)
I'll try all of these.