Skip to content

FREESCAPE: Depth rendering based on the original implementation#7049

Merged
neuromancer merged 13 commits intoscummvm:masterfrom
neuromancer:freescape-nozbuffer
Mar 1, 2026
Merged

FREESCAPE: Depth rendering based on the original implementation#7049
neuromancer merged 13 commits intoscummvm:masterfrom
neuromancer:freescape-nozbuffer

Conversation

@neuromancer
Copy link
Contributor

@neuromancer neuromancer commented Nov 22, 2025

This PR contains the on-going work to replace the current approach to compute depth information, from z-buffer to the painter's algorithm similar to the original implementation. Despite the freescape game are from an era where GPUs where not even invented, modern OpenGL have a lot of trouble to correctly render the levels correctly using their z-buffer. The reason for that is coplanar triangles produce z-fighting. There are many tricks to minimize it, but it is very hard to completely remove it. On the first game, Driller, this is not bad, but later games like Castle Master, it is very easy to note these artifacts.

The solution, is of course, follow the original implementation that sorted bounding boxes according some kind of distance. In this PR, we used the annotated assembly code from @santiontanon to reimplement it.

Let's see how it changed, these are screenshots from master playing Castle Master for ZX Spectrum:

scummvm-castlemaster-zx-00000 scummvm-castlemaster-zx-00001

And this is with the sorting code:

scummvm-castlemaster-zx-00002 scummvm-castlemaster-zx-00003

And finally, the original implementation (apologies for the low quality!)

patio

hall

Finally, regardless of the state, this PR should NOT merged before tagging of 3.0.0. It will be featured in 3.0.1.

@lephilousophe
Copy link
Member

I have a quick question: do you still need to disable DEPTH_TEST everywhere?
It's guaranteed disabled by OpenGL spec so, if you don't use it anymore, you just don't need to touch it.

@neuromancer
Copy link
Contributor Author

Good catch: yes, no need to disable it, except when it is enabled for some specific cases.

@sev-
Copy link
Member

sev- commented Jan 3, 2026

Sounds and looks logical to me

@neuromancer
Copy link
Contributor Author

This PR is currently blocked by a few artifacts that I need to debug in the code, where the sorting results in boundind boxes that are not correct and very visible glitches.

added command to print sort order, show occlusion boxes and improved iso command to isolate multiple objects and only sort and render isolated objects.
@neuromancer
Copy link
Contributor Author

@dhruv0154 kindly improved the debug console and fixed the outstanding artifacts. This PR will be in testing for a bit in case there are more artifacts and then merged.

@neuromancer neuromancer marked this pull request as ready for review February 14, 2026 19:12
@neuromancer neuromancer merged commit 9b0c32e into scummvm:master Mar 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants