| 414 | } |
| 415 | |
| 416 | void Renderer::PrepareFires(RenderView& view) |
| 417 | { |
| 418 | for (const auto& fire : Fires) |
| 419 | { |
| 420 | auto oldFade = fire.PrevFade == 1 ? 1.0f : (float)(255 - fire.PrevFade) / 255.0f; |
| 421 | auto fade = fire.fade == 1 ? 1.0f : (float)(255 - fire.fade) / 255.0f; |
| 422 | fade = Lerp(oldFade, fade, GetInterpolationFactor()); |
| 423 | |
| 424 | for (int i = 0; i < MAX_SPARKS_FIRE; i++) |
| 425 | { |
| 426 | auto* spark = &FireSparks[i]; |
| 427 | if (spark->on) |
| 428 | { |
| 429 | // Calculate original flame color. |
| 430 | auto color = Vector4::Lerp( |
| 431 | Vector4( |
| 432 | spark->PrevColor.x / 255.0f * fade, |
| 433 | spark->PrevColor.y / 255.0f * fade, |
| 434 | spark->PrevColor.z / 255.0f * fade, |
| 435 | 1.0f), |
| 436 | Vector4( |
| 437 | spark->color.x / 255.0f * fade, |
| 438 | spark->color.y / 255.0f * fade, |
| 439 | spark->color.z / 255.0f * fade, |
| 440 | 1.0f), |
| 441 | GetInterpolationFactor()); |
| 442 | |
| 443 | // Influence flame color with object color via chroma modulation. |
| 444 | if (fire.color != Vector4::One) |
| 445 | { |
| 446 | auto color3 = Vector3(color.x, color.y, color.z); |
| 447 | color = Vector4::Lerp(color, fire.color * Luma(color3), Chroma(color3) * 1.5f); |
| 448 | } |
| 449 | |
| 450 | AddSpriteBillboard( |
| 451 | &_sprites[spark->def], |
| 452 | Vector3::Lerp( |
| 453 | Vector3( |
| 454 | fire.PrevPosition.x + spark->PrevPosition.x * fire.PrevSize / 2, |
| 455 | fire.PrevPosition.y + spark->PrevPosition.y * fire.PrevSize / 2, |
| 456 | fire.PrevPosition.z + spark->PrevPosition.z * fire.PrevSize / 2), |
| 457 | Vector3( |
| 458 | fire.position.x + spark->position.x * fire.size / 2, |
| 459 | fire.position.y + spark->position.y * fire.size / 2, |
| 460 | fire.position.z + spark->position.z * fire.size / 2), |
| 461 | GetInterpolationFactor()), |
| 462 | color, |
| 463 | TO_RAD(Lerp(spark->PrevRotAng << 4, spark->rotAng << 4, GetInterpolationFactor())), |
| 464 | Lerp(spark->PrevScalar, spark->scalar, GetInterpolationFactor()), |
| 465 | Vector2::Lerp( |
| 466 | Vector2(fire.PrevSize * spark->PrevSize, fire.PrevSize * spark->PrevSize), |
| 467 | Vector2(fire.size * spark->size, fire.size * spark->size), |
| 468 | GetInterpolationFactor()), |
| 469 | BlendMode::Additive, true, view); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | } |