fgsfdsfgs / sm64-port

PS2, PS3, OG Xbox and DOS ports of sm64-port.
https://discord.gg/7bcNTPK
242 stars 38 forks source link

[Software] Color buffer should be cleared in sequences that do not have a skybox #67

Closed DrUm78 closed 2 years ago

DrUm78 commented 2 years ago

Software: SM64 decompilation fork: https://github.com/DrUm78/sm64-funkey Hardware: FunKey S device (armv7 a7)

During indoor sliding sequences (solo or against the penguin) skybox is not drawn and creates a severe graphic glitch with software renderer (the FunKey S does not have any gpu). This bug happens the same way everywhere in the game when setting "draw_sky false" in sm64config.txt, so it seems to be related to the "sky draw" function.

Steps to reproduce:

  1. Compile it for the FunKey S (armv7 a7)
  2. Reach one of the sliding sequences or simply wait for the sequence in the attract mode
  3. Notice that the skybox is very glitchy and has this "duplication" effect
  4. Set "draw_sky false" in sm64config.txt and notice that the same occurs everywhere in the game

Video footage: https://drive.google.com/file/d/1V45Cr2E5a4YB7AfgNtM4lqs26_2CLkBW/view?usp=sharing

Same happens on RS-97: https://youtu.be/NqOECYL70mg?t=66

fgsfdsfgs commented 2 years ago

This is because there's no skybox at all in these cases. The software renderer does not clear the color buffer at the start of each frame, leading to the garbage you see, because I assumed there's gonna be either a skybox or a wall in the way at all times, so always clearing the color buffer is a waste of CPU time. I guess I forgot about these cases. The proper fix would be to check if there's no skybox and issue color clears if that is the case.

DrUm78 commented 2 years ago

Thanks for the fast answer. Yeah that makes sense now. I hope you will be able to fix it soon, thanks. 🤞

DrUm78 commented 2 years ago

I had a look into the code in skybox.c but that is way beyond my coding skill I fear. Would it be as easy as checking if a skybox exists then clearing the color buffer if not, all this in one part of the code only? If so, any hint how I could fix it on my side? Some levels are quite unplayable with this broken display.

Thanks in advance.

fgsfdsfgs commented 2 years ago

This should be fixed in a590e0e.

DrUm78 commented 2 years ago

Awesome thanks! I just needed to modify this to make it work, otherwise that does not fix the bug: https://github.com/fgsfdsfgs/sm64-port/commit/a590e0ea340450de68d55d64d2b094a7b2179caf#r75618529

Thank you again.

fgsfdsfgs commented 2 years ago

It works on my machine. Or at least it does with draw_sky false. Make sure to do a clean build.

DrUm78 commented 2 years ago

Yeah I use make distclean before. With your code, it only works with draw_sky false (I use 'true' here). Works in both cases with if (sSkyboxEmpty = TRUE) but maybe that's more cpu expensive.

fgsfdsfgs commented 2 years ago

Oh yeah, it won't actually work when there's no skybox at all. Hold on. upd: Turns out it's more due to the fillrect function not working correctly, as the game itself is supposed to clear the screen when there's no skybox.

fgsfdsfgs commented 2 years ago

Should work correctly now with 32bd7b3c.

DrUm78 commented 2 years ago

Works fine both with draw_sky false and draw_sky true, thanks again for your amazing work on the software renderer part.