From d3e3112fdd478aae35da79c61686dc9fffbd6e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 1 Jun 2019 18:49:43 +0200 Subject: [PATCH] Fix z-test bug --- small3dlib.h | 12 ++++++++---- testSDL.c | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/small3dlib.h b/small3dlib.h index a4bbfc2..8ef3cce 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -167,6 +167,10 @@ triangles. */ #endif +#if S3L_PERSPECTIVE_CORRECTION +#define S3L_COMPUTE_DEPTH 1 // PC inevitably computes depth, so enable it +#endif + typedef int32_t S3L_Unit; /**< Units of measurement in 3D space. There is S3L_FRACTIONS_PER_UNIT in one spatial unit. By dividing the unit into fractions we @@ -1522,7 +1526,10 @@ void S3L_drawTriangle( p.x = x; #if S3L_COMPUTE_DEPTH - #if S3L_PERSPECTIVE_CORRECTION != 1 + #if S3L_PERSPECTIVE_CORRECTION == 1 + p.depth = (S3L_FRACTIONS_PER_UNIT * S3L_FRACTIONS_PER_UNIT) / + S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,x - lX,rX - lX)); + #else p.depth = S3L_getFastLerpValue(depthFLS); S3L_stepFastLerp(depthFLS); #endif @@ -1539,9 +1546,6 @@ void S3L_drawTriangle( #endif #if S3L_PERSPECTIVE_CORRECTION == 1 - p.depth = (S3L_FRACTIONS_PER_UNIT * S3L_FRACTIONS_PER_UNIT) / - S3L_nonZero(S3L_interpolate(lRecipZ,rRecipZ,x - lX,rX - lX)); - *barycentric0 = ( S3L_interpolateFrom0(rOverZ,i,rowLength) diff --git a/testSDL.c b/testSDL.c index 9ca7109..4e8d1bd 100644 --- a/testSDL.c +++ b/testSDL.c @@ -152,6 +152,8 @@ else setPixel(p->x,p->y,col * 120,dep,(2 - col) * 120); +// setPixel(p->x,p->y, (p->triangleID * 60) % 255, (p->triangleID * 170) % 255, (p->triangleID * 10) % 255 ); + //setPixel(p->x,p->y,sss, (p->triangleID * 37) % 255 ,128); //setPixel(p->x,p->y,p->modelID * 64,p->modelID * 128,255);