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

Work on near culling

This commit is contained in:
Miloslav Číž 2019-06-01 18:14:39 +02:00
parent fbab60d893
commit 2371750e24

View file

@ -143,6 +143,18 @@
engines. */ engines. */
#endif #endif
#ifndef S3L_STRICT_NEAR_CULLING
#define S3L_STRICT_NEAR_CULLING 1 /**< If on, any triangle that only partially
intersects the near plane will be culled.
This can prevent errorneous rendering and
artifacts, but also makes triangles close to
the camera disappear. */
#endif
#if S3L_STRICT_NEAR_CULLING
#define S3L_NEAR_CLAMPING 0 // This would be useless.
#endif
#ifndef S3L_PERSPECTIVE_CORRECTION #ifndef S3L_PERSPECTIVE_CORRECTION
#define S3L_PERSPECTIVE_CORRECTION 0 /**< Specifies what type of perspective #define S3L_PERSPECTIVE_CORRECTION 0 /**< Specifies what type of perspective
correction (PC) to use. Remember this is an expensive correction (PC) to use. Remember this is an expensive
@ -1180,6 +1192,10 @@ void S3L_drawTriangle(
p.modelID = modelID; p.modelID = modelID;
p.triangleID = triangleID; p.triangleID = triangleID;
point0.z = point0.z >= S3L_NEAR ? point0.z : S3L_NEAR;
point1.z = point1.z >= S3L_NEAR ? point1.z : S3L_NEAR;
point2.z = point2.z >= S3L_NEAR ? point2.z : S3L_NEAR;
S3L_Vec4 *tPointPP, *lPointPP, *rPointPP; /* points in projction plane space S3L_Vec4 *tPointPP, *lPointPP, *rPointPP; /* points in projction plane space
(in Units, normalized by (in Units, normalized by
S3L_FRACTIONS_PER_UNIT) */ S3L_FRACTIONS_PER_UNIT) */
@ -1665,8 +1681,14 @@ static inline int8_t S3L_triangleIsVisible(
#define clipTest(c,cmp,v)\ #define clipTest(c,cmp,v)\
(p0.c cmp (v) && p1.c cmp (v) && p2.c cmp (v)) (p0.c cmp (v) && p1.c cmp (v) && p2.c cmp (v))
if ( // completely outside frustum? if ( // outside frustum?
clipTest(z,<=,S3L_NEAR) ||
#if S3L_STRICT_NEAR_CULLING
p0.z < S3L_NEAR || p1.z < S3L_NEAR || p2.z < S3L_NEAR ||
// ^ partially in front of NEAR?
#else
clipTest(z,<=,S3L_NEAR) || // completely in front of NEAR?
#endif
clipTest(x,<,-1 * S3L_FRACTIONS_PER_UNIT) || clipTest(x,<,-1 * S3L_FRACTIONS_PER_UNIT) ||
clipTest(x,>,S3L_FRACTIONS_PER_UNIT) || clipTest(x,>,S3L_FRACTIONS_PER_UNIT) ||
clipTest(y,<,-1 * S3L_PROJECTION_PLANE_HEIGHT / 2) || clipTest(y,<,-1 * S3L_PROJECTION_PLANE_HEIGHT / 2) ||