1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-21 20:29:59 +01:00

Add floor depth

This commit is contained in:
Miloslav Číž 2018-09-13 11:02:01 +02:00
parent 97471546c1
commit eb78a2a569

View file

@ -719,7 +719,7 @@ void castRaysMultiHit(Camera cam, ArrayFunction arrayFunc,
// global helper variables, for precomputing stuff etc. // global helper variables, for precomputing stuff etc.
PixelFunction _pixelFunction = 0; PixelFunction _pixelFunction = 0;
Camera _camera; Camera _camera;
Unit _floorDepthStep = 0; Unit _horizontalDepthStep = 0;
Unit _startFloorHeight = 0; Unit _startFloorHeight = 0;
Unit _startCeilHeight = 0; Unit _startCeilHeight = 0;
int_maybe32_t _camResYLimit = 0; int_maybe32_t _camResYLimit = 0;
@ -727,8 +727,8 @@ Unit _middleRow = 0;
ArrayFunction _floorFunction = 0; ArrayFunction _floorFunction = 0;
ArrayFunction _ceilFunction = 0; ArrayFunction _ceilFunction = 0;
uint8_t _computeTextureCoords = 0; uint8_t _computeTextureCoords = 0;
Unit _fogStartYBottom = 0; Unit _fHorizontalDepthStart = 0;
Unit _fogStartYTop = 0; Unit _cHorizontalDepthStart = 0;
int16_t _cameraHeightScreen = 0; int16_t _cameraHeightScreen = 0;
/** /**
@ -823,13 +823,18 @@ for (uint_maybe32_t j = 0; j <= hitCount; ++j)
cZ1Screen = _middleRow + 1; cZ1Screen = _middleRow + 1;
} }
int_maybe32_t limit; Unit limit;
Unit verticalDistance;
#define VERTICAL_DEPTH_MULTIPLY 2
#define drawHorizontal(pref,l1,l2,comp,inc)\ #define drawHorizontal(pref,l1,l2,comp,inc)\
p.depth += absVal(pref##Z1World) * VERTICAL_DEPTH_MULTIPLY;\
limit = clamp(pref##Z1Screen,l1,l2);\ limit = clamp(pref##Z1Screen,l1,l2);\
for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\ for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\
{\ {\
p.position.y = i;\ p.position.y = i;\
p.depth += _horizontalDepthStep;\
_pixelFunction(&p);\ _pixelFunction(&p);\
}\ }\
if (pref##PosY comp limit)\ if (pref##PosY comp limit)\
@ -840,14 +845,19 @@ for (uint_maybe32_t j = 0; j <= hitCount; ++j)
// draw floor until wall // draw floor until wall
p.isFloor = 1; p.isFloor = 1;
p.depth = (_fHorizontalDepthStart - fPosY) * _horizontalDepthStep;
drawHorizontal(f,cPosY + 1,_camera.resolution.y,>,-) drawHorizontal(f,cPosY + 1,_camera.resolution.y,>,-)
// ^ purposfully allow outside screen bounds here // ^ purposfully allow outside screen bounds here
// draw ceiling until wall // draw ceiling until wall
p.isFloor = 0; p.isFloor = 0;
p.depth = (cPosY - _cHorizontalDepthStart) * _horizontalDepthStep;
drawHorizontal(c,-1,fPosY - 1,<,+) drawHorizontal(c,-1,fPosY - 1,<,+)
// ^ purposfully allow outside screen bounds here // ^ purposfully allow outside screen bounds here
#undef drawHorizontal
#undef VERTICAL_DEPTH_MULTIPLY
if (!drawingHorizon) // don't draw walls for horizon plane if (!drawingHorizon) // don't draw walls for horizon plane
{ {
#define drawVertical(pref,l1,l2,comp,inc)\ #define drawVertical(pref,l1,l2,comp,inc)\
@ -887,6 +897,8 @@ for (uint_maybe32_t j = 0; j <= hitCount; ++j)
p.isFloor = 0; p.isFloor = 0;
drawVertical(c,-1,fPosY - 1,<,+) drawVertical(c,-1,fPosY - 1,<,+)
} // ^ puposfully allow outside screen bounds here } // ^ puposfully allow outside screen bounds here
#undef drawVertical
} }
@ -1026,7 +1038,7 @@ for (uint_maybe32_t j = 0; j <= hitCount; ++j)
for (int_maybe32_t i = y; i > z1Screen; --i) for (int_maybe32_t i = y; i > z1Screen; --i)
{ {
p.position.y = i; p.position.y = i;
p.depth = (_fogStartYBottom - i) * _floorDepthStep + floorCameraDiff; p.depth = (_fHorizontalDepthStart - i) * _horizontalDepthStep + floorCameraDiff;
_pixelFunction(&p); _pixelFunction(&p);
} }
@ -1044,7 +1056,7 @@ for (uint_maybe32_t j = 0; j <= hitCount; ++j)
for (int_maybe32_t i = y2; i < z1ScreenCeil; ++i) for (int_maybe32_t i = y2; i < z1ScreenCeil; ++i)
{ {
p.position.y = i; p.position.y = i;
p.depth = (i - _fogStartYTop) * _floorDepthStep + ceilCameraDiff; p.depth = (i - _cHorizontalDepthStart) * _horizontalDepthStep + ceilCameraDiff;
_pixelFunction(&p); _pixelFunction(&p);
} }
@ -1123,7 +1135,7 @@ for (uint_maybe32_t j = 0; j <= hitCount; ++j)
for (int_maybe32_t i = y; i >= horizon; --i) for (int_maybe32_t i = y; i >= horizon; --i)
{ {
p.position.y = i; p.position.y = i;
p.depth = (_fogStartYBottom - i) * _floorDepthStep + floorCameraDiff; p.depth = (_fHorizontalDepthStart - i) * _horizontalDepthStep + floorCameraDiff;
_pixelFunction(&p); _pixelFunction(&p);
} }
@ -1140,7 +1152,7 @@ for (uint_maybe32_t j = 0; j <= hitCount; ++j)
for (int_maybe32_t i = y2; i < y; ++i) for (int_maybe32_t i = y2; i < y; ++i)
{ {
p.position.y = i; p.position.y = i;
p.depth = (i - _fogStartYTop) * _floorDepthStep + ceilCameraDiff; p.depth = (i - _cHorizontalDepthStart) * _horizontalDepthStep + ceilCameraDiff;
_pixelFunction(&p); _pixelFunction(&p);
} }
@ -1197,7 +1209,7 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
p.position.y = y; p.position.y = y;
_pixelFunction(&p); _pixelFunction(&p);
++y; ++y;
p.depth += _floorDepthStep; p.depth += _horizontalDepthStep;
} }
// draw wall // draw wall
@ -1221,14 +1233,14 @@ void _columnFunctionSimple(HitResult *hits, uint16_t hitCount, uint16_t x,
// draw floor // draw floor
p.isWall = 0; p.isWall = 0;
p.depth = _middleRow * _floorDepthStep; p.depth = _middleRow * _horizontalDepthStep;
while (y < _camera.resolution.y) while (y < _camera.resolution.y)
{ {
p.position.y = y; p.position.y = y;
_pixelFunction(&p); _pixelFunction(&p);
++y; ++y;
p.depth -= _floorDepthStep; p.depth -= _horizontalDepthStep;
} }
} }
@ -1246,8 +1258,8 @@ void render(Camera cam, ArrayFunction floorHeightFunc,
_middleRow = halfResY + cam.shear; _middleRow = halfResY + cam.shear;
_fogStartYBottom = _middleRow + halfResY; _fHorizontalDepthStart = _middleRow + halfResY;
_fogStartYTop = _middleRow - halfResY; _cHorizontalDepthStart = _middleRow - halfResY;
_computeTextureCoords = constraints.computeTextureCoords; _computeTextureCoords = constraints.computeTextureCoords;
@ -1263,7 +1275,7 @@ void render(Camera cam, ArrayFunction floorHeightFunc,
: UNIT_INFINITY; : UNIT_INFINITY;
// TODO // TODO
_floorDepthStep = (12 * UNITS_PER_SQUARE) / cam.resolution.y; _horizontalDepthStep = (12 * UNITS_PER_SQUARE) / cam.resolution.y;
castRaysMultiHit(cam,_floorCeilFunction,typeFunction, castRaysMultiHit(cam,_floorCeilFunction,typeFunction,
_columnFunction,constraints); _columnFunction,constraints);
@ -1284,7 +1296,7 @@ void renderSimple(Camera cam, ArrayFunction floorHeightFunc,
UNITS_PER_SQUARE; UNITS_PER_SQUARE;
// TODO // TODO
_floorDepthStep = (12 * UNITS_PER_SQUARE) / cam.resolution.y; _horizontalDepthStep = (12 * UNITS_PER_SQUARE) / cam.resolution.y;
constraints.maxHits = 1; constraints.maxHits = 1;