Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/graphics/Software.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,14 @@ inline ZunVec3 Software::ProjectToNDC(ZunVec3 vertex, ZunMatrix mv, ZunMatrix p,
viewZ = clip.z;
clip = p * clip;
ZunVec3 ndc = {clip.x, clip.y, clip.z};
if (clip.w != 0)

// this is probably incorrect but at least it prevents background on stage 2 from breaking without adding complexity
if (clip.w <= 0)
{
W = 1.0f;
return ndc;
}
else
{
ndc /= clip.w;
W = 1.0f / clip.w;
Expand Down Expand Up @@ -568,7 +575,8 @@ void Software::Draw(PrimitiveType type, i32 start, i32 count)
f32 depth;
if (useDepthTest)
{
depth = ((ndcZ * clipW) * 0.5f + 0.5f) * depthDif + depthNear;
depth = ZUN_MAX(ZUN_MIN(((ndcZ * clipW) * 0.5f + 0.5f) * depthDif + depthNear, depthFar),
depthNear);
if (depthFunc == DEPTH_FUNC_LEQUAL && depth > depthBuffer[pixelCoord])
{
continue;
Expand Down