fix(render): fix item shadow caused by undefined behavior

* Replace byte cast with int8_t in Tesselator::normal()
* 4J calls this function with -1.0f as the first parameter sometimes, the previous cast caused it to become 0x00 and broke the shading in the inventory
* It was done a similar way on Vita, i just kanged it and made it more C++
This commit is contained in:
Anaël committed 2026-10-26 13:39:18 +01:00
1 parent c9d833be19
commit e7d819bd00
1 file changed
+8 -12
+8 -12
View File
@@ -1030,20 +1030,16 @@ uint32_t _ConvertF32toX11Y11Z10N(float x, float y, float z)
void Tesselator::normal(float x, float y, float z)
{
hasNormal = true;
#ifdef __PS3__
_normal = _ConvertF32toX11Y11Z10N(x,y,z);
#elif __PSVITA__
// AP - casting a negative value to 'byte' on Vita results in zero. changed to a signed 8 value
int8_t xx = (int8_t) (x * 127);
int8_t yy = (int8_t) (y * 127);
int8_t zz = (int8_t) (z * 127);
_normal = (xx & 0xff) | ((yy & 0xff) << 8) | ((zz & 0xff) << 16);
_normal = _ConvertF32toX11Y11Z10N(x, y, z);
#else
byte xx = static_cast<byte>(x * 127);
byte yy = static_cast<byte>(y * 127);
byte zz = static_cast<byte>(z * 127);
_normal = (xx & 0xff) | ((yy & 0xff) << 8) | ((zz & 0xff) << 16);
int8_t xx = static_cast<int8_t>(x * 127.0f);
int8_t yy = static_cast<int8_t>(y * 127.0f);
int8_t zz = static_cast<int8_t>(z * 127.0f);
_normal = (static_cast<uint32_t>(xx) & 0xff) |
((static_cast<uint32_t>(yy) & 0xff) << 8) |
((static_cast<uint32_t>(zz) & 0xff) << 16);
#endif
}