Fix various clipping glitches

This commit is contained in:
Luke Benstead 2022-06-11 21:27:09 +01:00
parent 53c54997c3
commit 4827fd4c5b

View File

@ -74,7 +74,6 @@ GL_FORCE_INLINE void _glSubmitHeaderOrVertex(const Vertex* v) {
#ifndef NDEBUG
assert(!isnan(v->xyz[2]));
assert(!isnan(v->w));
assert(v->xyz[2] > 0.0f);
#endif
uint32_t *s = (uint32_t*) v;
@ -118,15 +117,20 @@ GL_FORCE_INLINE void _glClipEdge(const Vertex* v1, const Vertex* v2, Vertex* vou
const float d0 = v1->w + v1->xyz[2];
const float d1 = v2->w + v2->xyz[2];
float t = MATH_Fast_Divide(d0, (d0 - d1));
const float epsilon = (d0 < d1) ? -0.00001f : 0.00001f;
vout->xyz[0] = MATH_fmac(v2->xyz[0] - v1->xyz[0], t, v1->xyz[0]);
vout->xyz[1] = MATH_fmac(v2->xyz[1] - v1->xyz[1], t, v1->xyz[1]);
vout->xyz[2] = MATH_fmac(v2->xyz[2] - v1->xyz[2], t, v1->xyz[2]);
vout->w = MATH_fmac(v2->w - v1->w, t, v1->w);
float t = MATH_Fast_Divide(d0, (d0 - d1)) + epsilon;
vout->uv[0] = MATH_fmac(v2->uv[0] - v1->uv[0], t, v1->uv[0]);
vout->uv[1] = MATH_fmac(v2->uv[1] - v1->uv[1], t, v1->uv[1]);
t = (t > 1.0f) ? 1.0f : t;
t = (t < 0.0f) ? 0.0f : t;
vout->xyz[0] = __builtin_fmaf(v2->xyz[0] - v1->xyz[0], t, v1->xyz[0]);
vout->xyz[1] = __builtin_fmaf(v2->xyz[1] - v1->xyz[1], t, v1->xyz[1]);
vout->xyz[2] = __builtin_fmaf(v2->xyz[2] - v1->xyz[2], t, v1->xyz[2]);
vout->w = __builtin_fmaf(v2->w - v1->w, t, v1->w);
vout->uv[0] = __builtin_fmaf(v2->uv[0] - v1->uv[0], t, v1->uv[0]);
vout->uv[1] = __builtin_fmaf(v2->uv[1] - v1->uv[1], t, v1->uv[1]);
interpolateColour(v1->bgra, v2->bgra, t, vout->bgra);
}
@ -176,7 +180,7 @@ void SceneListSubmit(void* src, int n) {
if(tri_count < 3) {
if(likely(glIsVertex(vertex->flags))) {
triangle[tri_count].v = vertex;
triangle[tri_count].visible = vertex->w > 0 && vertex->xyz[2] > -vertex->w;
triangle[tri_count].visible = vertex->xyz[2] > -vertex->w;
tri_count++;
strip_count++;
} else {