Fix rendering of fire effects when their intensity exceeds 1.0f

This had been overlooked for a long time because intensity defaults to 1.0f and is seldom changed. The underlying issue is that an intensity value higher than 1.0f produces fire_alpha values above 255, which the new graphics code doesn't deal with properly. That said, that code works fine for every other case, so the solution is to add a special case for when fire_alpha is used.
This commit is contained in:
Tamás Bálint Misius 2023-09-07 16:03:44 +02:00
parent 2dc468bcd1
commit 77071c524e
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
4 changed files with 22 additions and 1 deletions

View File

@ -64,6 +64,16 @@ struct alignas(alignof(uint32_t) > alignof(T) ? alignof(uint32_t) : alignof(T))
);
}
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
constexpr RGB<T> AddFire(RGB<T> other, int fireAlpha) const
{
return RGB<T>(
std::min(0xFF, Red + (fireAlpha * other.Red) / 0xFF),
std::min(0xFF, Green + (fireAlpha * other.Green) / 0xFF),
std::min(0xFF, Blue + (fireAlpha * other.Blue) / 0xFF)
);
}
// Decrement each component that is nonzero.
template<typename S = T, typename = std::enable_if_t<std::is_same_v<S, uint8_t>>>
constexpr RGB<T> Decay() const

View File

@ -13,6 +13,7 @@ struct RasterDrawMethods
void DrawPixel(Vec2<int>, RGB<uint8_t>);
void BlendPixel(Vec2<int>, RGBA<uint8_t>);
void AddPixel(Vec2<int>, RGBA<uint8_t>);
void AddFirePixel(Vec2<int>, RGB<uint8_t>, int fireAlpha);
void XorPixel(Vec2<int>);
void DrawLine(Vec2<int>, Vec2<int>, RGB<uint8_t>);

View File

@ -55,6 +55,16 @@ inline void RasterDrawMethods<Derived>::AddPixel(Vec2<int> pos, RGBA<uint8_t> co
}
}
template<typename Derived>
inline void RasterDrawMethods<Derived>::AddFirePixel(Vec2<int> pos, RGB<uint8_t> colour, int fireAlpha)
{
if (clipRect().Contains(pos))
{
pixel &px = (static_cast<Derived &>(*this).video)[pos];
px = RGB<uint8_t>::Unpack(px).AddFire(colour, fireAlpha).Pack();
}
}
template<typename Derived>
inline void RasterDrawMethods<Derived>::XorPixel(Vec2<int> pos)
{

View File

@ -1161,7 +1161,7 @@ void Renderer::render_fire()
a = fire_alpha[y+CELL][x+CELL];
if (findingElement)
a /= 2;
AddPixel({ i*CELL+x, j*CELL+y }, RGBA<uint8_t>(r, g, b, a));
AddFirePixel({ i*CELL+x, j*CELL+y }, RGB<uint8_t>(r, g, b), a);
}
r *= 8;
g *= 8;