From 28f77969eab54acc19b4d58c114870fd132dd97c Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Mon, 17 Feb 2020 19:09:21 +0000 Subject: [PATCH] Avoid overflows --- GL/lighting.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GL/lighting.c b/GL/lighting.c index 2ae13d9..b6dfe42 100644 --- a/GL/lighting.c +++ b/GL/lighting.c @@ -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);