desmume icon indicating copy to clipboard operation
desmume copied to clipboard

OpenGL regression

Open windwakr opened this issue 9 months ago • 1 comments

It looks like 3db6d56 caused a regression in the functionality of the OpenGL renderer. In Metroid Prime Hunters(NTR-AMHE-USA), for example, room segments visually float away as you move away from them. The software renderer is unaffected.

https://github.com/user-attachments/assets/f714c2af-495a-408d-a009-69922a0055d8

Tested on Windows 10 with a GTX 1650 gpu.

windwakr avatar Apr 19 '25 15:04 windwakr

The bug is related to how commit 3db6d56 flips the Y-coordinate of vertices in the vertex shader.

Rendering straight NDS vertices with OpenGL causes the final rendered framebuffer to be Y-flipped. Historically, DeSmuME would Y-flip the final rendered framebuffer as a final step before passing it along to the NDS 2D engine. Usually, this framebuffer Y-flip would happen on the GPU, but ancient GPUs aren't capable of doing that. In the case of ancient GPUs, the framebuffer Y-flip would happen on the CPU instead.

Therefore, as an optimization, the Y-coordinate of the vertices are being Y-flipped so that rendering occurs in an already flipped state. This completely eliminates the step for Y-flipping the final framebuffer, making for a performance win on all platforms, old and new.

However, there is an assumption that the Y-coordinate for the OpenGL viewport is set to zero. If it's not zero, then polygons will be shifted in Y, as can be seen in your Metroid Prime Hunters video. It just so happens that Metroid Prime Hunters is one of those extremely rare games that uses a non-standard viewport. Furthermore, this game even changes the viewport coordinates between 3D rendering passes.

I really don't want to bring back the old method of rendering the straight NDS vertices and then Y-flipping the final rendered framebuffer. Therefore, the best solution would be to account for the viewport's current Y-coordinate in the vertex shader. I'll take a look at it and get back to you later.

rogerman avatar Apr 19 '25 19:04 rogerman