From 7f14de23ac468813d6d326dd209ed2aa0570a0cd Mon Sep 17 00:00:00 2001 From: shidemuri <68622956+shidemuri@users.noreply.github.com> Date: Fri, 12 Jun 2026 21:52:26 -0400 Subject: [PATCH 1/3] initial software renderer fixes --- src/graphics/Software.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/graphics/Software.cpp b/src/graphics/Software.cpp index 21a99912..e4f3073d 100644 --- a/src/graphics/Software.cpp +++ b/src/graphics/Software.cpp @@ -447,6 +447,12 @@ void Software::Draw(PrimitiveType type, i32 start, i32 count) ZunVec3 v2 = ProjectToNDC(*(ZunVec3 *)((u8 *)vertexData + vertexStride * (index + 2)), modelview, projection, viewZ2, invw2); + if(invw0 < 0 || invw1 < 0 || invw2 < 0) + { + index += increment; + continue; + } + ZunVec2 tc0, tc1, tc2; Diffuse diffuse0, diffuse1, diffuse2; u32 *texels; @@ -568,7 +574,7 @@ 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; From 7ae91499f3f9955d99737a73fc446f982680b591 Mon Sep 17 00:00:00 2001 From: shidemuri <68622956+shidemuri@users.noreply.github.com> Date: Sat, 13 Jun 2026 14:48:08 -0400 Subject: [PATCH 2/3] fix stage 2 background disappearing --- src/graphics/Software.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/graphics/Software.cpp b/src/graphics/Software.cpp index e4f3073d..f2483323 100644 --- a/src/graphics/Software.cpp +++ b/src/graphics/Software.cpp @@ -369,8 +369,13 @@ 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; } @@ -447,12 +452,6 @@ void Software::Draw(PrimitiveType type, i32 start, i32 count) ZunVec3 v2 = ProjectToNDC(*(ZunVec3 *)((u8 *)vertexData + vertexStride * (index + 2)), modelview, projection, viewZ2, invw2); - if(invw0 < 0 || invw1 < 0 || invw2 < 0) - { - index += increment; - continue; - } - ZunVec2 tc0, tc1, tc2; Diffuse diffuse0, diffuse1, diffuse2; u32 *texels; From 202d9b997bf3687de720c4128be1bafb90a901a5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 13 Jun 2026 18:58:56 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/graphics/Software.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/graphics/Software.cpp b/src/graphics/Software.cpp index f2483323..e92a72d1 100644 --- a/src/graphics/Software.cpp +++ b/src/graphics/Software.cpp @@ -370,12 +370,14 @@ inline ZunVec3 Software::ProjectToNDC(ZunVec3 vertex, ZunMatrix mv, ZunMatrix p, clip = p * clip; ZunVec3 ndc = {clip.x, clip.y, clip.z}; - //this is probably incorrect but at least it prevents background on stage 2 from breaking without adding complexity + // 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 { + } + else + { ndc /= clip.w; W = 1.0f / clip.w; } @@ -573,7 +575,8 @@ void Software::Draw(PrimitiveType type, i32 start, i32 count) f32 depth; if (useDepthTest) { - depth = ZUN_MAX(ZUN_MIN(((ndcZ * clipW) * 0.5f + 0.5f) * depthDif + depthNear, depthFar), 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;