mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-21 20:29:59 +01:00
Optimize texture coords
This commit is contained in:
parent
00e5cff5b1
commit
0caeb1c1ac
1 changed files with 26 additions and 11 deletions
37
raycastlib.h
37
raycastlib.h
|
@ -1000,18 +1000,33 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
||||||
Unit wallLength = pref##Z2Screen - pref##Z1Screen - 1;\
|
Unit wallLength = pref##Z2Screen - pref##Z1Screen - 1;\
|
||||||
wallLength = wallLength != 0 ? wallLength : 1;\
|
wallLength = wallLength != 0 ? wallLength : 1;\
|
||||||
Unit wallPosition = absVal(pref##Z1Screen - pref##PosY) inc (-1);\
|
Unit wallPosition = absVal(pref##Z1Screen - pref##PosY) inc (-1);\
|
||||||
for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\
|
Unit coordStep = UNITS_PER_SQUARE / wallLength;\
|
||||||
{\
|
p.texCoords.y = wallPosition * coordStep;\
|
||||||
p.position.y = i;\
|
if (coordStep < MIN_TEXTURE_STEP) /* two versions of the loop */ \
|
||||||
p.hit = hit;\
|
for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\
|
||||||
if (COMPUTE_WALL_TEXCOORDS == 1)\
|
{ /* more expensive texture coord computing */\
|
||||||
{\
|
p.position.y = i;\
|
||||||
p.texCoords.x = hit.textureCoord;\
|
p.hit = hit;\
|
||||||
p.texCoords.y = (wallPosition * UNITS_PER_SQUARE) / wallLength;\
|
if (COMPUTE_WALL_TEXCOORDS == 1)\
|
||||||
|
{\
|
||||||
|
p.texCoords.x = hit.textureCoord;\
|
||||||
|
p.texCoords.y = (wallPosition * UNITS_PER_SQUARE)/wallLength;\
|
||||||
|
}\
|
||||||
|
wallPosition++;\
|
||||||
|
_pixelFunction(&p);\
|
||||||
|
}\
|
||||||
|
else\
|
||||||
|
for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\
|
||||||
|
{ /* cheaper texture coord computing */\
|
||||||
|
p.position.y = i;\
|
||||||
|
p.hit = hit;\
|
||||||
|
if (COMPUTE_WALL_TEXCOORDS == 1)\
|
||||||
|
{\
|
||||||
|
p.texCoords.x = hit.textureCoord;\
|
||||||
|
p.texCoords.y += coordStep;\
|
||||||
|
}\
|
||||||
|
_pixelFunction(&p);\
|
||||||
}\
|
}\
|
||||||
wallPosition++;\
|
|
||||||
_pixelFunction(&p);\
|
|
||||||
}\
|
|
||||||
if (pref##PosY comp limit)\
|
if (pref##PosY comp limit)\
|
||||||
pref##PosY = limit;\
|
pref##PosY = limit;\
|
||||||
pref##Z1World = pref##Z2World; /* for the next iteration */\
|
pref##Z1World = pref##Z2World; /* for the next iteration */\
|
||||||
|
|
Loading…
Reference in a new issue