| 1053 | } |
| 1054 | |
| 1055 | void Renderer::PrepareWeatherParticles(RenderView& view) |
| 1056 | { |
| 1057 | constexpr auto SNOW_CLUSTER_SPREAD = BLOCK(1.0f); |
| 1058 | constexpr auto RAIN_CLUSTER_SPREAD = BLOCK(1.0f); |
| 1059 | |
| 1060 | constexpr auto RAIN_WIDTH_NEAR = 1.5f; |
| 1061 | constexpr auto RAIN_WIDTH_FAR = 15.0f; |
| 1062 | |
| 1063 | for (const auto& part : Weather.GetParticles()) |
| 1064 | { |
| 1065 | if (!part.Enabled) |
| 1066 | continue; |
| 1067 | |
| 1068 | auto pos = Vector3::Lerp(part.PrevPosition, part.Position, GetInterpolationFactor()); |
| 1069 | auto size = Lerp(part.PrevSize, part.Size, GetInterpolationFactor()); |
| 1070 | |
| 1071 | // Underwater dust does not need clustering. |
| 1072 | if (part.Type == WeatherType::None) |
| 1073 | { |
| 1074 | if (!view.Camera.Frustum.SphereInFrustum(pos, size)) |
| 1075 | continue; |
| 1076 | |
| 1077 | if (!CheckIfSlotExists(ID_DEFAULT_SPRITES, "Underwater dust rendering")) |
| 1078 | continue; |
| 1079 | |
| 1080 | AddSpriteBillboard( |
| 1081 | &_sprites[Objects[ID_DEFAULT_SPRITES].meshIndex + SPR_UNDERWATERDUST], |
| 1082 | pos, |
| 1083 | Color(1.0f, 1.0f, 1.0f, part.Transparency()), |
| 1084 | 0.0f, 1.0f, Vector2(size), |
| 1085 | BlendMode::Additive, true, view); |
| 1086 | |
| 1087 | continue; |
| 1088 | } |
| 1089 | |
| 1090 | // Clamp cluster size to 1. |
| 1091 | int clusterSize = std::max(1, part.ClusterSize); |
| 1092 | |
| 1093 | // If particle is dying, immediately cancel the cluster. |
| 1094 | if (part.Stopped) |
| 1095 | clusterSize = 1; |
| 1096 | |
| 1097 | auto finalPos = pos; |
| 1098 | auto finalScale = size; |
| 1099 | |
| 1100 | for (int i = 0; i < clusterSize; i++) |
| 1101 | { |
| 1102 | // Combine particle index and cluster index for unique seeding. |
| 1103 | int uniqueSeed = part.UniqueID + i; |
| 1104 | |
| 1105 | if (i > 0) |
| 1106 | { |
| 1107 | // Use bits from uniqueSeed to determine distribution pattern. |
| 1108 | float spread = part.Type == WeatherType::Snow ? SNOW_CLUSTER_SPREAD : RAIN_CLUSTER_SPREAD; |
| 1109 | float offsetBase = spread * ((i + 1) / (float)clusterSize); |
| 1110 | |
| 1111 | // Use bits 0, 1, 2 for axis signs. |
| 1112 | // Snow Y axis is always negative, so that snowflakes don't sink into room geometry. |
nothing calls this directly
no test coverage detected