From 94bcb8e29408d7f063a92e88a1ff4e0155e5412e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 3 Sep 2018 09:39:46 +0200 Subject: [PATCH] Fix fog bug --- raycastlib.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/raycastlib.h b/raycastlib.h index 4a5fde5..a341170 100644 --- a/raycastlib.h +++ b/raycastlib.h @@ -544,6 +544,8 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) PixelInfo p; p.position.x = x; + #define VERTICAL_DEPTH_MULTIPLY 2 + // we'll be simulatenously drawing the floor and the ceiling now for (uint_maybe32_t j = 0; j < hitCount; ++j) { @@ -598,7 +600,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) p.isWall = 0; - Unit floorCameraDiff = absVal(worldZPrev) * 4; + Unit floorCameraDiff = absVal(worldZPrev) * VERTICAL_DEPTH_MULTIPLY; for (int_maybe32_t i = y; i > z1Screen; --i) { @@ -609,7 +611,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) // draw ceiling until wall - Unit ceilCameraDiff = absVal(worldZPrevCeil) * 4; + Unit ceilCameraDiff = absVal(worldZPrevCeil) * VERTICAL_DEPTH_MULTIPLY; for (int_maybe32_t i = y2; i < z1ScreenCeil; ++i) { @@ -655,9 +657,8 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) p.isWall = 0; - Unit floorCameraDiff = absVal(worldZPrev) * 4; - - uint16_t horizon = y <= y2 ? y : _middleRow; + Unit floorCameraDiff = absVal(worldZPrev) * VERTICAL_DEPTH_MULTIPLY; + uint16_t horizon = y2 < _middleRow ? _middleRow : y2; for (int_maybe32_t i = y; i >= horizon; --i) { @@ -669,7 +670,8 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) // draw ceiling until horizon - Unit ceilCameraDiff = absVal(worldZPrevCeil) * 4; + Unit ceilCameraDiff = absVal(worldZPrevCeil) * VERTICAL_DEPTH_MULTIPLY; + horizon = y > _middleRow ? _middleRow : y; for (int_maybe32_t i = y2; i < horizon; ++i) { @@ -679,6 +681,7 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray) _pixelFunction(p); } + #undef VERTICAL_DEPTH_MULTIPLY } void render(Camera cam, ArrayFunction arrayFunc, PixelFunction pixelFunc,