mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 21:41:03 +00:00
- Cull back facing triangles for the span drawers
This commit is contained in:
parent
fae514923a
commit
f9fb4a0a17
2 changed files with 12 additions and 2 deletions
|
@ -243,6 +243,15 @@ bool PolyTriangleDrawer::is_degenerate(const ShadedTriVertex *vert)
|
|||
return crosslengthsqr <= 1.e-6f;
|
||||
}
|
||||
|
||||
bool PolyTriangleDrawer::is_frontfacing(TriDrawTriangleArgs *args)
|
||||
{
|
||||
float a =
|
||||
args->v1->x * args->v2->y - args->v2->x * args->v1->y +
|
||||
args->v2->x * args->v3->y - args->v3->x * args->v2->y +
|
||||
args->v3->x * args->v1->y - args->v1->x * args->v3->y;
|
||||
return a <= 0.0f;
|
||||
}
|
||||
|
||||
void PolyTriangleDrawer::draw_shaded_triangle(const ShadedTriVertex *vert, bool ccw, TriDrawTriangleArgs *args, WorkerThreadData *thread)
|
||||
{
|
||||
// Reject triangle if degenerate
|
||||
|
@ -324,7 +333,7 @@ void PolyTriangleDrawer::draw_shaded_triangle(const ShadedTriVertex *vert, bool
|
|||
args->v1 = &clippedvert[numclipvert - 1];
|
||||
args->v2 = &clippedvert[i - 1];
|
||||
args->v3 = &clippedvert[i - 2];
|
||||
if (args->CalculateGradients())
|
||||
if (is_frontfacing(args) && args->CalculateGradients())
|
||||
ScreenTriangle::Draw(args, thread);
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +344,7 @@ void PolyTriangleDrawer::draw_shaded_triangle(const ShadedTriVertex *vert, bool
|
|||
args->v1 = &clippedvert[0];
|
||||
args->v2 = &clippedvert[i - 1];
|
||||
args->v3 = &clippedvert[i];
|
||||
if (args->CalculateGradients())
|
||||
if (!is_frontfacing(args) && args->CalculateGradients())
|
||||
ScreenTriangle::Draw(args, thread);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ private:
|
|||
static void draw_arrays(const PolyDrawArgs &args, WorkerThreadData *thread);
|
||||
static void draw_shaded_triangle(const ShadedTriVertex *vertices, bool ccw, TriDrawTriangleArgs *args, WorkerThreadData *thread);
|
||||
static bool is_degenerate(const ShadedTriVertex *vertices);
|
||||
static bool is_frontfacing(TriDrawTriangleArgs *args);
|
||||
|
||||
static int clipedge(const ShadedTriVertex *verts, ShadedTriVertex *clippedvert);
|
||||
|
||||
|
|
Loading…
Reference in a new issue