From 440dc68b5e99c78683956fbaa314b7f6950c465c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Tue, 12 Sep 2023 18:41:44 +0200 Subject: [PATCH] Fix PMODE_SPARK producing black spots PMODE_SPARK does weird colour ops with alpha values larger than 255, so of course it looks odd with the new code that expects alpha to be at most 255. The solution is to do the work on the spot. Other effects may also be affected by this new assumption. --- src/graphics/Renderer.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp index 1f47d9452..c06bce565 100644 --- a/src/graphics/Renderer.cpp +++ b/src/graphics/Renderer.cpp @@ -172,7 +172,6 @@ void Renderer::render_parts() { int deca, decr, decg, decb, cola, colr, colg, colb, firea, firer, fireg, fireb, pixel_mode, q, i, t, nx, ny, x, y; int orbd[4] = {0, 0, 0, 0}, orbl[4] = {0, 0, 0, 0}; - float gradv, flicker; Particle * parts; Element *elements; if(!sim) @@ -259,7 +258,7 @@ void Renderer::render_parts() } if((elements[t].Properties & PROP_HOT_GLOW) && sim->parts[i].temp>(elements[t].HighTemperature-800.0f)) { - gradv = 3.1415/(2*elements[t].HighTemperature-(elements[t].HighTemperature-800.0f)); + auto gradv = 3.1415/(2*elements[t].HighTemperature-(elements[t].HighTemperature-800.0f)); auto caddress = int((sim->parts[i].temp>elements[t].HighTemperature)?elements[t].HighTemperature-(elements[t].HighTemperature-800.0f):sim->parts[i].temp-(elements[t].HighTemperature-800.0f)); colr += int(sin(gradv*caddress) * 226); colg += int(sin(gradv*caddress*4.55 +TPT_PI_DBL) * 34); @@ -299,7 +298,7 @@ void Renderer::render_parts() } else if(colour_mode & COLOUR_LIFE) { - gradv = 0.4f; + auto gradv = 0.4f; if (!(sim->parts[i].life<5)) q = int(sqrt((float)sim->parts[i].life)); else @@ -589,20 +588,25 @@ void Renderer::render_parts() } if(pixel_mode & PMODE_SPARK) { - flicker = float(rng()%20); - gradv = 4*sim->parts[i].life + flicker; + auto flicker = float(rng()%20); + auto gradv = 4*sim->parts[i].life + flicker; for (x = 0; gradv>0.5; x++) { - AddPixel({ nx+x, ny }, RGBA(colr, colg, colb, int(gradv))); - AddPixel({ nx-x, ny }, RGBA(colr, colg, colb, int(gradv))); - AddPixel({ nx, ny+x }, RGBA(colr, colg, colb, int(gradv))); - AddPixel({ nx, ny-x }, RGBA(colr, colg, colb, int(gradv))); + auto col = RGBA( + std::min(0xFF, colr * int(gradv) / 255), + std::min(0xFF, colg * int(gradv) / 255), + std::min(0xFF, colb * int(gradv) / 255) + ); + AddPixel({ nx+x, ny }, col); + AddPixel({ nx-x, ny }, col); + AddPixel({ nx, ny+x }, col); + AddPixel({ nx, ny-x }, col); gradv = gradv/1.5f; } } if(pixel_mode & PMODE_FLARE) { - flicker = float(rng()%20); - gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17; + auto flicker = float(rng()%20); + auto gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17; BlendPixel({ nx, ny }, RGBA(colr, colg, colb, int((gradv*4)>255?255:(gradv*4)) )); BlendPixel({ nx+1, ny }, RGBA(colr, colg, colb,int( (gradv*2)>255?255:(gradv*2)) )); BlendPixel({ nx-1, ny }, RGBA(colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) )); @@ -623,8 +627,8 @@ void Renderer::render_parts() } if(pixel_mode & PMODE_LFLARE) { - flicker = float(rng()%20); - gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17; + auto flicker = float(rng()%20); + auto gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17; BlendPixel({ nx, ny }, RGBA(colr, colg, colb, int((gradv*4)>255?255:(gradv*4)) )); BlendPixel({ nx+1, ny }, RGBA(colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) )); BlendPixel({ nx-1, ny }, RGBA(colr, colg, colb, int((gradv*2)>255?255:(gradv*2)) ));