- Fix dynamic light clamping issue in truecolor drawers

This commit is contained in:
Magnus Norddahl 2017-07-23 23:45:43 +02:00
parent bf4d7234e1
commit 1ce3b4c79c
4 changed files with 12 additions and 0 deletions

View file

@ -355,6 +355,10 @@ namespace swrenderer
lit.b += (light_color.b * attenuation) >> 8; lit.b += (light_color.b * attenuation) >> 8;
} }
lit.r = MIN<uint32_t>(lit.r, 256);
lit.g = MIN<uint32_t>(lit.g, 256);
lit.b = MIN<uint32_t>(lit.b, 256);
fgcolor.r = MIN<uint32_t>(fgcolor.r + ((material.r * lit.r) >> 8), 255); fgcolor.r = MIN<uint32_t>(fgcolor.r + ((material.r * lit.r) >> 8), 255);
fgcolor.g = MIN<uint32_t>(fgcolor.g + ((material.g * lit.g) >> 8), 255); fgcolor.g = MIN<uint32_t>(fgcolor.g + ((material.g * lit.g) >> 8), 255);
fgcolor.b = MIN<uint32_t>(fgcolor.b + ((material.b * lit.b) >> 8), 255); fgcolor.b = MIN<uint32_t>(fgcolor.b + ((material.b * lit.b) >> 8), 255);

View file

@ -399,6 +399,8 @@ namespace swrenderer
lit = _mm_add_epi16(lit, _mm_srli_epi16(_mm_mullo_epi16(light_color, attenuation), 8)); lit = _mm_add_epi16(lit, _mm_srli_epi16(_mm_mullo_epi16(light_color, attenuation), 8));
} }
lit = _mm_min_epi16(lit, _mm_set1_epi16(256));
fgcolor = _mm_add_epi16(fgcolor, _mm_srli_epi16(_mm_mullo_epi16(material, lit), 8)); fgcolor = _mm_add_epi16(fgcolor, _mm_srli_epi16(_mm_mullo_epi16(material, lit), 8));
fgcolor = _mm_min_epi16(fgcolor, _mm_set1_epi16(255)); fgcolor = _mm_min_epi16(fgcolor, _mm_set1_epi16(255));
return fgcolor; return fgcolor;

View file

@ -269,6 +269,10 @@ namespace swrenderer
lit.b += (light_color.b * attenuation) >> 8; lit.b += (light_color.b * attenuation) >> 8;
} }
lit.r = MIN<uint32_t>(lit.r, 256);
lit.g = MIN<uint32_t>(lit.g, 256);
lit.b = MIN<uint32_t>(lit.b, 256);
fgcolor.r = MIN<uint32_t>(fgcolor.r + ((material.r * lit.r) >> 8), 255); fgcolor.r = MIN<uint32_t>(fgcolor.r + ((material.r * lit.r) >> 8), 255);
fgcolor.g = MIN<uint32_t>(fgcolor.g + ((material.g * lit.g) >> 8), 255); fgcolor.g = MIN<uint32_t>(fgcolor.g + ((material.g * lit.g) >> 8), 255);
fgcolor.b = MIN<uint32_t>(fgcolor.b + ((material.b * lit.b) >> 8), 255); fgcolor.b = MIN<uint32_t>(fgcolor.b + ((material.b * lit.b) >> 8), 255);

View file

@ -315,6 +315,8 @@ namespace swrenderer
lit = _mm_add_epi16(lit, _mm_srli_epi16(_mm_mullo_epi16(light_color, attenuation), 8)); lit = _mm_add_epi16(lit, _mm_srli_epi16(_mm_mullo_epi16(light_color, attenuation), 8));
} }
lit = _mm_min_epi16(lit, _mm_set1_epi16(256));
fgcolor = _mm_add_epi16(fgcolor, _mm_srli_epi16(_mm_mullo_epi16(material, lit), 8)); fgcolor = _mm_add_epi16(fgcolor, _mm_srli_epi16(_mm_mullo_epi16(material, lit), 8));
fgcolor = _mm_min_epi16(fgcolor, _mm_set1_epi16(255)); fgcolor = _mm_min_epi16(fgcolor, _mm_set1_epi16(255));
return fgcolor; return fgcolor;