Avoid overflows

This commit is contained in:
Luke Benstead 2020-02-17 19:09:21 +00:00
parent 29cbdc75b7
commit 28f77969ea

View File

@ -340,9 +340,9 @@ GL_FORCE_INLINE void _glLightVertexDirectional(uint8_t* final, int8_t lid, float
F += (LdotN * MATERIAL.diffuse[X] * LIGHTS[lid].diffuse[X]); \
if(MATERIAL.exponent) \
F += FPOW(FI * NdotH, MATERIAL.exponent) * MATERIAL.specular[X] * LIGHTS[lid].specular[X]; \
FO = (uint8_t) (F * 255.0f); \
FO = (uint8_t) (_MIN(F * 255.0f, 255.0f)); \
\
final[T] += _MIN(FO, final[T] - FO); \
final[T] += _MIN(FO, 255 - final[T]); \
_PROCESS_COMPONENT(R8IDX, 0);
_PROCESS_COMPONENT(G8IDX, 1);
@ -361,9 +361,9 @@ GL_FORCE_INLINE void _glLightVertexPoint(uint8_t* final, int8_t lid, float LdotN
F += (LdotN * MATERIAL.diffuse[X] * LIGHTS[lid].diffuse[X]); \
if(MATERIAL.exponent) \
F += FPOW(FI * NdotH, MATERIAL.exponent) * MATERIAL.specular[X] * LIGHTS[lid].specular[X]; \
FO = (uint8_t) (F * att * 255.0f); \
FO = (uint8_t) (_MIN(F * att * 255.0f, 255.0f)); \
\
final[T] += _MIN(FO, final[T] - FO); \
final[T] += _MIN(FO, 255 - final[T]); \
_PROCESS_COMPONENT(R8IDX, 0);
_PROCESS_COMPONENT(G8IDX, 1);