Fix subsampling

This commit is contained in:
Miloslav Číž 2019-10-14 02:29:13 +02:00
parent 5085b0e793
commit c517fc5dc8
2 changed files with 14 additions and 6 deletions

17
main.c
View File

@ -188,7 +188,10 @@ void SFG_init();
#define SFG_FONT_SIZE_BIG 1 #define SFG_FONT_SIZE_BIG 1
#endif #endif
uint8_t SFG_zBuffer[SFG_GAME_RESOLUTION_X]; #define SFG_Z_BUFFER_SIZE \
(SFG_GAME_RESOLUTION_X / SFG_RAYCASTING_SUBSAMPLE + 1)
uint8_t SFG_zBuffer[SFG_Z_BUFFER_SIZE];
#define SFG_RCL_UNIT_TO_Z_BUFFER(x) (x / RCL_UNITS_PER_SQUARE) #define SFG_RCL_UNIT_TO_Z_BUFFER(x) (x / RCL_UNITS_PER_SQUARE)
@ -379,7 +382,8 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel)
uint8_t shadow = 0; uint8_t shadow = 0;
if (pixel->position.y == SFG_GAME_RESOLUTION_Y / 2) if (pixel->position.y == SFG_GAME_RESOLUTION_Y / 2)
SFG_zBuffer[pixel->position.x] = SFG_RCL_UNIT_TO_Z_BUFFER(pixel->depth); SFG_zBuffer[pixel->position.x / SFG_RAYCASTING_SUBSAMPLE] =
SFG_RCL_UNIT_TO_Z_BUFFER(pixel->depth);
if (pixel->isHorizon && pixel->depth > RCL_UNITS_PER_SQUARE * 16) if (pixel->isHorizon && pixel->depth > RCL_UNITS_PER_SQUARE * 16)
{ {
@ -648,7 +652,7 @@ void SFG_drawScaledSprite(
for (int16_t x = x0, u = u0; x <= x1; ++x, ++u) for (int16_t x = x0, u = u0; x <= x1; ++x, ++u)
{ {
if (SFG_zBuffer[x] > zDistance) if (SFG_zBuffer[x / SFG_RAYCASTING_SUBSAMPLE] >= zDistance)
{ {
int8_t columnTransparent = 1; int8_t columnTransparent = 1;
@ -671,7 +675,7 @@ void SFG_drawScaledSprite(
} }
if (!columnTransparent) if (!columnTransparent)
SFG_zBuffer[x] = zDistance; SFG_zBuffer[x / SFG_RAYCASTING_SUBSAMPLE] = zDistance;
} }
} }
} }
@ -1302,7 +1306,7 @@ void SFG_draw()
} }
else else
{ {
for (uint16_t i = 0; i < SFG_GAME_RESOLUTION_X; ++i) for (uint16_t i = 0; i < SFG_Z_BUFFER_SIZE; ++i)
SFG_zBuffer[i] = 255; SFG_zBuffer[i] = 255;
int16_t weaponBobOffset; int16_t weaponBobOffset;
@ -1352,7 +1356,8 @@ int16_t weaponBobOffset;
SFG_player.camera); SFG_player.camera);
if (p.depth > 0) if (p.depth > 0)
SFG_drawScaledSprite(SFG_sprites[0],p.position.x,p.position.y, SFG_drawScaledSprite(SFG_sprites[0],
p.position.x * SFG_RAYCASTING_SUBSAMPLE,p.position.y,
RCL_perspectiveScale(SFG_GAME_RESOLUTION_Y / 2,p.depth), RCL_perspectiveScale(SFG_GAME_RESOLUTION_Y / 2,p.depth),
p.depth / (RCL_UNITS_PER_SQUARE * 2),p.depth); p.depth / (RCL_UNITS_PER_SQUARE * 2),p.depth);
} }

View File

@ -37,6 +37,9 @@
#undef SFG_RAYCASTING_MAX_HITS #undef SFG_RAYCASTING_MAX_HITS
#define SFG_RAYCASTING_MAX_HITS 6 #define SFG_RAYCASTING_MAX_HITS 6
#undef SFG_RAYCASTING_SUBSAMPLE
#define SFG_RAYCASTING_SUBSAMPLE 2
#include "Pokitto.h" #include "Pokitto.h"
#include "palette.h" #include "palette.h"