Page 1 of 1

Suggestion for fixing numerous z-fighting issues

Posted: Fri Oct 11, 2013 4:24 pm
by Suslik
Well probably everyone who played tome even a little notices that some effects(particles primarily) are rendered behind or above objects they should not be. Like doors and posters, mountains and such.

Reason is that currently t-engine renders sprites as follows: first it sorts them along global z-axis, then those which have equal z-component are sorted for screenspace y-axis.

No wonder it has artifacts because it's mathematically incorrect. I have not tested it yet, but common sense tells me that the only way to make them sort in a proper way is to sort the sprites along (z + y) component. Note that in such case z-component should be in range(0..1) for normal objects such as walls, doors, characters, on-character effects and such. For example if you want a door to be rendered above a wall and a character who stands in front of it should appear above both of them, then the wall should have z-coordinate 0.5, the door should have it for example 0.75, character z = 0.5, character effect under him z = 0.25 and above him are z = 0.75. Particles like explosion and fireball should have z = +inf.

In my case y is aligned from top to down and z is facing on the viewer. If you have differently oriented axes, just switch sorting formula for something like (y - z)