full_zbuffer.diff 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. This mod adds full z-buffer that mostly fixes the incorrect sprite visibility,
  2. however RAM consumption increases quite a bit. Note that visiblity inaccuracies
  3. may still occur as e.g. floor depth is not accurate and isn't used, but the game
  4. generally looks much better. By drummyfish, released under CC0 1.0, public
  5. domain.
  6. diff --git a/constants.h b/constants.h
  7. index 956baa0..da72f24 100644
  8. --- a/constants.h
  9. +++ b/constants.h
  10. @@ -352,7 +352,7 @@
  11. #define SFG_FONT_SIZE_BIG 1
  12. #endif
  13. -#define SFG_Z_BUFFER_SIZE SFG_GAME_RESOLUTION_X
  14. +#define SFG_Z_BUFFER_SIZE (SFG_GAME_RESOLUTION_X * SFG_GAME_RESOLUTION_Y)
  15. /**
  16. Step in which walls get higher, in raycastlib units.
  17. diff --git a/game.h b/game.h
  18. index 991058d..36bba8e 100755
  19. --- a/game.h
  20. +++ b/game.h
  21. @@ -951,6 +951,14 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel)
  22. :
  23. SFG_TRANSPARENT_COLOR;
  24. + uint8_t *zValue = SFG_game.zBuffer +
  25. + pixel->position.y * SFG_GAME_RESOLUTION_X + pixel->position.x;
  26. +
  27. + uint8_t zDistance = SFG_RCLUnitToZBuffer(pixel->depth);
  28. +
  29. + if (*zValue >= zDistance)
  30. + *zValue = zDistance;
  31. +
  32. shadow = pixel->hit.direction >> 1;
  33. }
  34. else // floor/ceiling
  35. @@ -1216,29 +1224,25 @@ void SFG_drawScaledSprite(
  36. for (int16_t x = x0, u = u0; x <= x1; ++x, ++u)
  37. {
  38. - if (SFG_game.zBuffer[x] >= zDistance)
  39. + for (int16_t y = y0, v = v0; y <= y1; ++y, ++v)
  40. {
  41. - int8_t columnTransparent = 1;
  42. + uint8_t color =
  43. + SFG_getTexel(image,SFG_game.spriteSamplingPoints[u],
  44. + SFG_game.spriteSamplingPoints[v]);
  45. - for (int16_t y = y0, v = v0; y <= y1; ++y, ++v)
  46. + if (color != SFG_TRANSPARENT_COLOR)
  47. {
  48. - uint8_t color =
  49. - SFG_getTexel(image,SFG_game.spriteSamplingPoints[u],
  50. - SFG_game.spriteSamplingPoints[v]);
  51. -
  52. - if (color != SFG_TRANSPARENT_COLOR)
  53. - {
  54. #if SFG_DIMINISH_SPRITES
  55. - color = palette_minusValue(color,minusValue);
  56. + color = palette_minusValue(color,minusValue);
  57. #endif
  58. - columnTransparent = 0;
  59. + uint8_t *zValue = SFG_game.zBuffer + y * SFG_GAME_RESOLUTION_X + x;
  60. + if (*zValue >= zDistance)
  61. + {
  62. SFG_setGamePixel(x,y,color);
  63. + *zValue = zDistance;
  64. }
  65. }
  66. -
  67. - if (!columnTransparent)
  68. - SFG_game.zBuffer[x] = zDistance;
  69. }
  70. }
  71. }
  72. @@ -4682,7 +4686,7 @@ void SFG_draw(void)
  73. }
  74. else
  75. {
  76. - for (int_fast16_t i = 0; i < SFG_Z_BUFFER_SIZE; ++i)
  77. + for (uint32_t i = 0; i < SFG_Z_BUFFER_SIZE; ++i)
  78. SFG_game.zBuffer[i] = 255;
  79. int16_t weaponBobOffset = 0;