1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-24 21:09:57 +01:00

Improve sorting

This commit is contained in:
Miloslav Číž 2019-06-26 18:33:57 +02:00
parent cf00db0487
commit d0f873c136

View file

@ -2429,6 +2429,9 @@ void _S3L_projectVertex(
S3L_vec3Xmat4(result,projectionMatrix); S3L_vec3Xmat4(result,projectionMatrix);
result->w = result->z;
/* We'll keep the non-clamped z in w for sorting. */
result->z = result->z >= S3L_NEAR ? result->z : S3L_NEAR; result->z = result->z >= S3L_NEAR ? result->z : S3L_NEAR;
/* ^ This firstly prevents zero division in the follwoing z-divide and /* ^ This firstly prevents zero division in the follwoing z-divide and
secondly "pushes" vertices that are in front of near a little bit forward, secondly "pushes" vertices that are in front of near a little bit forward,
@ -2519,8 +2522,11 @@ void S3L_drawScene(S3L_Scene scene)
S3L_sortArray[S3L_sortArrayLength].modelIndex = modelIndex; S3L_sortArray[S3L_sortArrayLength].modelIndex = modelIndex;
S3L_sortArray[S3L_sortArrayLength].triangleIndex = triangleIndex; S3L_sortArray[S3L_sortArrayLength].triangleIndex = triangleIndex;
S3L_sortArray[S3L_sortArrayLength].sortValue = S3L_sortArray[S3L_sortArrayLength].sortValue =
(transformed0.z + transformed1.z + transformed2.z) >> 2; S3L_max(0,(transformed0.w + transformed1.w + transformed2.w)) >> 2;
/* ^ As a simple approximation we sort by the triangle center point, /* ^
The w component here stores non-clamped z.
As a simple approximation we sort by the triangle center point,
which is a mean coordinate -- we don't actually have to divide by 3 which is a mean coordinate -- we don't actually have to divide by 3
(or anything), that is unnecessary for sorting! We shift by 2 just (or anything), that is unnecessary for sorting! We shift by 2 just
as a fast operation to prevent overflow of the sum ver uint_16t. */ as a fast operation to prevent overflow of the sum ver uint_16t. */