Fix texturing

This commit is contained in:
Miloslav Číž 2019-09-28 02:08:28 +02:00
parent 0d91a4840a
commit 61693942b1
2 changed files with 24 additions and 14 deletions

8
main.c
View File

@ -96,9 +96,6 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel)
uint8_t color; uint8_t color;
uint8_t shadow = 0; uint8_t shadow = 0;
pixel->texCoords.y = -1 * pixel->texCoords.y;
// ^ raycastlib gives negative coords here, so make them positive
if (pixel->isWall) if (pixel->isWall)
{ {
uint8_t textureIndex = uint8_t textureIndex =
@ -114,12 +111,9 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel)
): ):
((pixel->hit.type & 0x38) >> 3); ((pixel->hit.type & 0x38) >> 3);
RCL_Unit textureV = pixel->height + pixel->texCoords.y; RCL_Unit textureV = pixel->texCoords.y;
if ((pixel->hit.type & SFG_TILE_PROPERTY_MASK) == if ((pixel->hit.type & SFG_TILE_PROPERTY_MASK) ==
SFG_TILE_PROPERTY_ELEVATOR)
textureV -= pixel->wallHeight;
else if ((pixel->hit.type & SFG_TILE_PROPERTY_MASK) ==
SFG_TILE_PROPERTY_SQUEEZER) SFG_TILE_PROPERTY_SQUEEZER)
textureV += pixel->wallHeight; textureV += pixel->wallHeight;

View File

@ -26,7 +26,7 @@
author: Miloslav "drummyfish" Ciz author: Miloslav "drummyfish" Ciz
license: CC0 1.0 license: CC0 1.0
version: 0.82 version: 0.84
*/ */
#include <stdint.h> #include <stdint.h>
@ -266,8 +266,8 @@ typedef struct
int8_t isFloor; ///< Whether the pixel is floor or ceiling. int8_t isFloor; ///< Whether the pixel is floor or ceiling.
int8_t isHorizon; ///< If the pixel belongs to horizon segment. int8_t isHorizon; ///< If the pixel belongs to horizon segment.
RCL_Unit depth; ///< Corrected depth. RCL_Unit depth; ///< Corrected depth.
RCL_Unit height; ///< World height (mostly for floor).
RCL_Unit wallHeight;///< Only for wall pixels, says its height. RCL_Unit wallHeight;///< Only for wall pixels, says its height.
RCL_Unit height; ///< World height (mostly for floor).
RCL_HitResult hit; ///< Corresponding ray hit. RCL_HitResult hit; ///< Corresponding ray hit.
RCL_Vector2D texCoords; /**< Normalized (0 to RCL_UNITS_PER_SQUARE - 1) RCL_Vector2D texCoords; /**< Normalized (0 to RCL_UNITS_PER_SQUARE - 1)
texture coordinates. */ texture coordinates. */
@ -1143,7 +1143,8 @@ static inline int16_t _RCL_drawWall(
RCL_Unit limit = RCL_clamp(yTo,limit1,limit2); RCL_Unit limit = RCL_clamp(yTo,limit1,limit2);
RCL_Unit wallLength = yTo - yFrom - 1; RCL_Unit wallLength = RCL_absVal(yTo - yFrom - 1);
wallLength = RCL_nonZero(wallLength); wallLength = RCL_nonZero(wallLength);
RCL_Unit wallPosition = RCL_absVal(yFrom - yCurrent) - increment; RCL_Unit wallPosition = RCL_absVal(yFrom - yCurrent) - increment;
@ -1159,6 +1160,19 @@ static inline int16_t _RCL_drawWall(
pixelInfo->texCoords.y = RCL_COMPUTE_WALL_TEXCOORDS ? pixelInfo->texCoords.y = RCL_COMPUTE_WALL_TEXCOORDS ?
wallPosition * coordStep : 0; wallPosition * coordStep : 0;
if (increment < 0)
{
coordStep *= -1;
pixelInfo->texCoords.y =
#if RCL_TEXTURE_VERTICAL_STRETCH == 1
RCL_UNITS_PER_SQUARE - pixelInfo->texCoords.y;
#else
height - pixelInfo->texCoords.y;
#endif
wallPosition = wallLength - wallPosition;
}
#if RCL_ACCURATE_WALL_TEXTURING == 1 #if RCL_ACCURATE_WALL_TEXTURING == 1
if (1) if (1)
#else #else
@ -1176,13 +1190,15 @@ static inline int16_t _RCL_drawWall(
#if RCL_COMPUTE_WALL_TEXCOORDS == 1 #if RCL_COMPUTE_WALL_TEXCOORDS == 1
#if RCL_TEXTURE_VERTICAL_STRETCH == 1 #if RCL_TEXTURE_VERTICAL_STRETCH == 1
pixelInfo->texCoords.y = (wallPosition * RCL_UNITS_PER_SQUARE) / wallLength; pixelInfo->texCoords.y =
(wallPosition * RCL_UNITS_PER_SQUARE) / wallLength;
#else #else
pixelInfo->texCoords.y = (wallPosition * height) / wallLength; pixelInfo->texCoords.y = (wallPosition * height) / wallLength;
#endif #endif
#endif #endif
wallPosition++; wallPosition += increment;
RCL_PIXEL_FUNCTION(pixelInfo); RCL_PIXEL_FUNCTION(pixelInfo);
} }
} }
@ -1237,9 +1253,9 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t
RCL_PixelInfo p; RCL_PixelInfo p;
p.position.x = x; p.position.x = x;
p.height = 0; p.height = 0;
p.wallHeight = 0;
p.texCoords.x = 0; p.texCoords.x = 0;
p.texCoords.y = 0; p.texCoords.y = 0;
p.wallHeight = 0;
// we'll be simulatenously drawing the floor and the ceiling now // we'll be simulatenously drawing the floor and the ceiling now
for (RCL_Unit j = 0; j <= hitCount; ++j) for (RCL_Unit j = 0; j <= hitCount; ++j)
@ -1378,7 +1394,7 @@ void _RCL_columnFunctionComplex(RCL_HitResult *hits, uint16_t hitCount, uint16_t
#if RCL_TEXTURE_VERTICAL_STRETCH == 1 #if RCL_TEXTURE_VERTICAL_STRETCH == 1
RCL_UNITS_PER_SQUARE RCL_UNITS_PER_SQUARE
#else #else
cZ2World - cZ1World cZ1World - cZ2World
#endif #endif
,1,&p); ,1,&p);