mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-24 20:59:58 +01:00
Optimize texture coords
This commit is contained in:
parent
00e5cff5b1
commit
0caeb1c1ac
1 changed files with 26 additions and 11 deletions
17
raycastlib.h
17
raycastlib.h
|
@ -1000,8 +1000,11 @@ 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);\
|
||||||
|
Unit coordStep = UNITS_PER_SQUARE / wallLength;\
|
||||||
|
p.texCoords.y = wallPosition * coordStep;\
|
||||||
|
if (coordStep < MIN_TEXTURE_STEP) /* two versions of the loop */ \
|
||||||
for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\
|
for (i = pref##PosY inc 1; i comp##= limit; inc##inc i)\
|
||||||
{\
|
{ /* more expensive texture coord computing */\
|
||||||
p.position.y = i;\
|
p.position.y = i;\
|
||||||
p.hit = hit;\
|
p.hit = hit;\
|
||||||
if (COMPUTE_WALL_TEXCOORDS == 1)\
|
if (COMPUTE_WALL_TEXCOORDS == 1)\
|
||||||
|
@ -1012,6 +1015,18 @@ void _columnFunction(HitResult *hits, uint16_t hitCount, uint16_t x, Ray ray)
|
||||||
wallPosition++;\
|
wallPosition++;\
|
||||||
_pixelFunction(&p);\
|
_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);\
|
||||||
|
}\
|
||||||
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