Add pitstop audio cue, original explosions/smoke, authentic HUD, and Modern lighting/shadows
This commit is contained in:
1 parent
3a377b0534
commit
197bfbc973
21 files changed
+1917
-236
No files matched your search
@@ -106,6 +106,12 @@ bool AudioEngine::init(const Vfs& vfs, const GameConfig& cfg, bool open_device)
|
|||||||
engine_sample_ = sound_bank_.find_gameplay("ENGINE1.WAV");
|
engine_sample_ = sound_bank_.find_gameplay("ENGINE1.WAV");
|
||||||
if (!engine_sample_) engine_sample_ = sound_bank_.find_gameplay("TESTENG3.WAV");
|
if (!engine_sample_) engine_sample_ = sound_bank_.find_gameplay("TESTENG3.WAV");
|
||||||
scrape_sample_ = sound_bank_.find_gameplay("SCRAPE2.WAV");
|
scrape_sample_ = sound_bank_.find_gameplay("SCRAPE2.WAV");
|
||||||
|
refuel_sample_ = sound_bank_.find_gameplay("REFUEL.WAV");
|
||||||
|
refuel_pos_ = 0.0;
|
||||||
|
refuel_env_ = 0.0f;
|
||||||
|
pit_active_.store(false, std::memory_order_relaxed);
|
||||||
|
pit_charging_.store(false, std::memory_order_relaxed);
|
||||||
|
pit_fill_ratio_.store(1.0f, std::memory_order_relaxed);
|
||||||
|
|
||||||
active_backend_ = cfg.music_backend;
|
active_backend_ = cfg.music_backend;
|
||||||
requested_backend_ = cfg.music_backend;
|
requested_backend_ = cfg.music_backend;
|
||||||
@@ -152,6 +158,11 @@ void AudioEngine::shutdown() {
|
|||||||
SDL_CloseAudioDevice(dev_id_);
|
SDL_CloseAudioDevice(dev_id_);
|
||||||
dev_id_ = 0;
|
dev_id_ = 0;
|
||||||
}
|
}
|
||||||
|
pit_active_.store(false, std::memory_order_relaxed);
|
||||||
|
pit_charging_.store(false, std::memory_order_relaxed);
|
||||||
|
pit_fill_ratio_.store(1.0f, std::memory_order_relaxed);
|
||||||
|
refuel_env_ = 0.0f;
|
||||||
|
refuel_pos_ = 0.0;
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,6 +265,12 @@ void AudioEngine::set_engine_state(bool active, float speed_ratio, bool boosting
|
|||||||
scrape_amount_.store(std::clamp(scrape_amount, 0.0f, 1.0f), std::memory_order_relaxed);
|
scrape_amount_.store(std::clamp(scrape_amount, 0.0f, 1.0f), std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioEngine::set_pitstop_state(bool on_pad, bool charging, float fill_ratio) {
|
||||||
|
pit_active_.store(on_pad, std::memory_order_relaxed);
|
||||||
|
pit_charging_.store(charging, std::memory_order_relaxed);
|
||||||
|
pit_fill_ratio_.store(std::clamp(fill_ratio, 0.0f, 1.0f), std::memory_order_relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
const assets::XmiSequence& AudioEngine::xmi_sequence(MusicBackend b, MusicTrackId t) const {
|
const assets::XmiSequence& AudioEngine::xmi_sequence(MusicBackend b, MusicTrackId t) const {
|
||||||
int slot = map_track_slot(t);
|
int slot = map_track_slot(t);
|
||||||
return (b == MusicBackend::SoundFont) ? wt_seqs_[slot] : opl_seqs_[slot];
|
return (b == MusicBackend::SoundFont) ? wt_seqs_[slot] : opl_seqs_[slot];
|
||||||
@@ -492,6 +509,37 @@ void AudioEngine::render_internal(float* stereo_out, int frames) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool pit_on = pit_active_.load(std::memory_order_relaxed);
|
||||||
|
const bool pit_chg = pit_charging_.load(std::memory_order_relaxed);
|
||||||
|
const float pit_fill = std::clamp(pit_fill_ratio_.load(std::memory_order_relaxed), 0.0f, 1.0f);
|
||||||
|
const float target_pit_env = pit_on ? (pit_chg ? 1.0f : 0.45f) : 0.0f;
|
||||||
|
if ((refuel_env_ > 0.001f || target_pit_env > 0.001f) && refuel_sample_ &&
|
||||||
|
!refuel_sample_->pcm_mono.empty()) {
|
||||||
|
const auto& pcm = refuel_sample_->pcm_mono;
|
||||||
|
const size_t len = pcm.size();
|
||||||
|
const double pitch = pit_chg ? (0.78 + 0.52 * static_cast<double>(pit_fill)) : 1.28;
|
||||||
|
const double step = (static_cast<double>(refuel_sample_->sample_rate) / kSampleRate) * pitch;
|
||||||
|
const float base_gain = 0.48f * svol;
|
||||||
|
const float env_step = 1.0f / (0.030f * static_cast<float>(kSampleRate));
|
||||||
|
for (int f = 0; f < cur; ++f) {
|
||||||
|
if (refuel_env_ < target_pit_env) {
|
||||||
|
refuel_env_ = std::min(target_pit_env, refuel_env_ + env_step);
|
||||||
|
} else if (refuel_env_ > target_pit_env) {
|
||||||
|
refuel_env_ = std::max(target_pit_env, refuel_env_ - env_step);
|
||||||
|
}
|
||||||
|
size_t i0 = static_cast<size_t>(refuel_pos_) % len;
|
||||||
|
size_t i1 = (i0 + 1) % len;
|
||||||
|
float frac = static_cast<float>(refuel_pos_ - std::floor(refuel_pos_));
|
||||||
|
float s = (pcm[i0] + (pcm[i1] - pcm[i0]) * frac) * base_gain * refuel_env_;
|
||||||
|
sfx_bus[f * 2 + 0] += s;
|
||||||
|
sfx_bus[f * 2 + 1] += s;
|
||||||
|
refuel_pos_ += step;
|
||||||
|
if (refuel_pos_ >= static_cast<double>(len)) {
|
||||||
|
refuel_pos_ -= static_cast<double>(len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < cur * 2; ++i) {
|
for (int i = 0; i < cur * 2; ++i) {
|
||||||
out_ptr[i] += std::tanh(sfx_bus[i] * 1.1f) * 0.88f;
|
out_ptr[i] += std::tanh(sfx_bus[i] * 1.1f) * 0.88f;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ public:
|
|||||||
// Continuous player engine pitch/volume modulation
|
// Continuous player engine pitch/volume modulation
|
||||||
void set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount);
|
void set_engine_state(bool active, float speed_ratio, bool boosting, float scrape_amount);
|
||||||
|
|
||||||
|
// Continuous pitstop pad hum / rising-pitch recharge cue
|
||||||
|
void set_pitstop_state(bool on_pad, bool charging, float fill_ratio);
|
||||||
|
|
||||||
// Offline render hook for deterministic unit testing
|
// Offline render hook for deterministic unit testing
|
||||||
void mix_offline(float* stereo_out, int frames);
|
void mix_offline(float* stereo_out, int frames);
|
||||||
|
|
||||||
@@ -141,8 +144,11 @@ private:
|
|||||||
std::array<uint64_t, 64> last_play_sample_intro_{};
|
std::array<uint64_t, 64> last_play_sample_intro_{};
|
||||||
const assets::SoundSample* engine_sample_ = nullptr;
|
const assets::SoundSample* engine_sample_ = nullptr;
|
||||||
const assets::SoundSample* scrape_sample_ = nullptr;
|
const assets::SoundSample* scrape_sample_ = nullptr;
|
||||||
|
const assets::SoundSample* refuel_sample_ = nullptr;
|
||||||
double engine_pos_ = 0.0;
|
double engine_pos_ = 0.0;
|
||||||
double scrape_pos_ = 0.0;
|
double scrape_pos_ = 0.0;
|
||||||
|
double refuel_pos_ = 0.0;
|
||||||
|
float refuel_env_ = 0.0f;
|
||||||
|
|
||||||
// Lock-free SPSC command ring buffer (game thread -> audio thread)
|
// Lock-free SPSC command ring buffer (game thread -> audio thread)
|
||||||
std::array<AudioCommand, kCmdQueueSize> cmd_ring_{};
|
std::array<AudioCommand, kCmdQueueSize> cmd_ring_{};
|
||||||
@@ -158,6 +164,9 @@ private:
|
|||||||
std::atomic<float> engine_speed_ratio_{0.0f};
|
std::atomic<float> engine_speed_ratio_{0.0f};
|
||||||
std::atomic<bool> engine_boosting_{false};
|
std::atomic<bool> engine_boosting_{false};
|
||||||
std::atomic<float> scrape_amount_{0.0f};
|
std::atomic<float> scrape_amount_{0.0f};
|
||||||
|
std::atomic<bool> pit_active_{false};
|
||||||
|
std::atomic<bool> pit_charging_{false};
|
||||||
|
std::atomic<float> pit_fill_ratio_{1.0f};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace top_octane::audio
|
} // namespace top_octane::audio
|
||||||
+481
-120
@@ -71,6 +71,64 @@ const char* camera_label(int cam) {
|
|||||||
return "CHASE";
|
return "CHASE";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void append_charger_lights(const assets::LevelData& level, double time_s,
|
||||||
|
std::vector<render::DynamicLight>& out) {
|
||||||
|
float pulse = 0.88f + 0.12f * std::sin(static_cast<float>(time_s) * 3.8f);
|
||||||
|
for (const auto& pad : level.pads) {
|
||||||
|
Vec3 col(0.22f, 0.70f, 1.00f); // Fuel blue
|
||||||
|
if (pad.type == assets::ChargerType::Shield) col = Vec3(0.15f, 1.00f, 0.48f);
|
||||||
|
else if (pad.type == assets::ChargerType::Ammo) col = Vec3(1.00f, 0.82f, 0.20f);
|
||||||
|
float y = level.sample_height_world(pad.cx, pad.cz) + 0.90f;
|
||||||
|
float rad = std::max(pad.half_x, pad.half_z) + 3.4f;
|
||||||
|
out.push_back({Vec3(pad.cx, y, pad.cz), rad, col, 0.72f * pulse});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<render::DynamicLight> select_viewport_lights(
|
||||||
|
const std::vector<render::DynamicLight>& candidates, const Vec3& focus, float max_dist) {
|
||||||
|
struct Scored {
|
||||||
|
float score = 0.0f;
|
||||||
|
size_t idx = 0;
|
||||||
|
};
|
||||||
|
std::vector<Scored> ranked;
|
||||||
|
ranked.reserve(candidates.size());
|
||||||
|
for (size_t i = 0; i < candidates.size(); ++i) {
|
||||||
|
const auto& l = candidates[i];
|
||||||
|
float d2 = (l.pos - focus).len_sq();
|
||||||
|
float lim = max_dist + l.radius;
|
||||||
|
if (d2 > lim * lim) continue;
|
||||||
|
ranked.push_back({l.intensity / (1.0f + 0.018f * d2), i});
|
||||||
|
}
|
||||||
|
constexpr size_t kMaxLights = 12;
|
||||||
|
if (ranked.size() > kMaxLights) {
|
||||||
|
std::partial_sort(ranked.begin(), ranked.begin() + kMaxLights, ranked.end(),
|
||||||
|
[](const Scored& a, const Scored& b) { return a.score > b.score; });
|
||||||
|
ranked.resize(kMaxLights);
|
||||||
|
}
|
||||||
|
std::vector<render::DynamicLight> out;
|
||||||
|
out.reserve(ranked.size());
|
||||||
|
for (const auto& s : ranked) {
|
||||||
|
out.push_back(candidates[s.idx]);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool write_backbuffer_ppm(const std::string& path, int w, int h) {
|
||||||
|
if (w <= 0 || h <= 0 || path.empty()) return false;
|
||||||
|
std::vector<uint8_t> rgb(static_cast<size_t>(w) * static_cast<size_t>(h) * 3u);
|
||||||
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
|
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, rgb.data());
|
||||||
|
std::FILE* f = std::fopen(path.c_str(), "wb");
|
||||||
|
if (!f) return false;
|
||||||
|
std::fprintf(f, "P6\n%d %d\n255\n", w, h);
|
||||||
|
const size_t row_bytes = static_cast<size_t>(w) * 3u;
|
||||||
|
for (int y = h - 1; y >= 0; --y) {
|
||||||
|
std::fwrite(rgb.data() + static_cast<size_t>(y) * row_bytes, 1, row_bytes, f);
|
||||||
|
}
|
||||||
|
std::fclose(f);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
bool GameApp::init(const LaunchOptions& opts) {
|
bool GameApp::init(const LaunchOptions& opts) {
|
||||||
@@ -81,6 +139,7 @@ bool GameApp::init(const LaunchOptions& opts) {
|
|||||||
|
|
||||||
cfg_.load(vfs_.pref_dir() / "config.ini");
|
cfg_.load(vfs_.pref_dir() / "config.ini");
|
||||||
if (opts.force_classic) cfg_.classic_mode = true;
|
if (opts.force_classic) cfg_.classic_mode = true;
|
||||||
|
if (opts.force_modern) cfg_.classic_mode = false;
|
||||||
if (opts.force_fullscreen) cfg_.fullscreen = true;
|
if (opts.force_fullscreen) cfg_.fullscreen = true;
|
||||||
if (opts.force_backend >= 0 && opts.force_backend <= 2) {
|
if (opts.force_backend >= 0 && opts.force_backend <= 2) {
|
||||||
cfg_.music_backend = static_cast<MusicBackend>(opts.force_backend);
|
cfg_.music_backend = static_cast<MusicBackend>(opts.force_backend);
|
||||||
@@ -205,7 +264,9 @@ bool GameApp::init(const LaunchOptions& opts) {
|
|||||||
|
|
||||||
void GameApp::shutdown() {
|
void GameApp::shutdown() {
|
||||||
cancel_name_edit();
|
cancel_name_edit();
|
||||||
|
if (opts_.smoke_test_frames == 0) {
|
||||||
save_all_user_data();
|
save_all_user_data();
|
||||||
|
}
|
||||||
audio_.shutdown();
|
audio_.shutdown();
|
||||||
input_.shutdown();
|
input_.shutdown();
|
||||||
ui_ren_.shutdown();
|
ui_ren_.shutdown();
|
||||||
@@ -320,18 +381,21 @@ void GameApp::enter_state(ScreenState s) {
|
|||||||
intro_turbo_played_ = false;
|
intro_turbo_played_ = false;
|
||||||
intro_explode_played_ = false;
|
intro_explode_played_ = false;
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
ensure_music(audio::MusicTrackId::TitleIntro, true, true);
|
ensure_music(audio::MusicTrackId::TitleIntro, true, true);
|
||||||
} else if (s == ScreenState::Title || s == ScreenState::MainMenu ||
|
} else if (s == ScreenState::Title || s == ScreenState::MainMenu ||
|
||||||
s == ScreenState::ChampionshipMenu || s == ScreenState::TrackSelect ||
|
s == ScreenState::ChampionshipMenu || s == ScreenState::TrackSelect ||
|
||||||
s == ScreenState::VehicleSelect || s == ScreenState::Highscores) {
|
s == ScreenState::VehicleSelect || s == ScreenState::Highscores) {
|
||||||
in_race_session_ = false;
|
in_race_session_ = false;
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
if (active_music_track_ != static_cast<int>(audio::MusicTrackId::TitleIntro)) {
|
if (active_music_track_ != static_cast<int>(audio::MusicTrackId::TitleIntro)) {
|
||||||
ensure_music(audio::MusicTrackId::Menu, true, false);
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
||||||
}
|
}
|
||||||
} else if (s == ScreenState::Options) {
|
} else if (s == ScreenState::Options) {
|
||||||
if (!in_race_session_) {
|
if (!in_race_session_) {
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
if (active_music_track_ != static_cast<int>(audio::MusicTrackId::TitleIntro)) {
|
if (active_music_track_ != static_cast<int>(audio::MusicTrackId::TitleIntro)) {
|
||||||
ensure_music(audio::MusicTrackId::Menu, true, false);
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
||||||
}
|
}
|
||||||
@@ -339,6 +403,7 @@ void GameApp::enter_state(ScreenState s) {
|
|||||||
} else if (s == ScreenState::PostRace) {
|
} else if (s == ScreenState::PostRace) {
|
||||||
in_race_session_ = false;
|
in_race_session_ = false;
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
ensure_music(audio::MusicTrackId::Menu, true, false);
|
ensure_music(audio::MusicTrackId::Menu, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,6 +472,7 @@ void GameApp::start_race_session() {
|
|||||||
post_race_record_flags_ = 0;
|
post_race_record_flags_ = 0;
|
||||||
in_race_session_ = true;
|
in_race_session_ = true;
|
||||||
state_ = ScreenState::Racing;
|
state_ = ScreenState::Racing;
|
||||||
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
|
|
||||||
ensure_music(static_cast<audio::MusicTrackId>(1 + (selected_track_ - 1) % 4), true, true);
|
ensure_music(static_cast<audio::MusicTrackId>(1 + (selected_track_ - 1) % 4), true, true);
|
||||||
}
|
}
|
||||||
@@ -437,6 +503,7 @@ void GameApp::handle_sim_events() {
|
|||||||
}
|
}
|
||||||
const char* wav = nullptr;
|
const char* wav = nullptr;
|
||||||
float base_gain = 0.45f;
|
float base_gain = 0.45f;
|
||||||
|
float pitch = 1.0f;
|
||||||
float cd_sec = 0.08f;
|
float cd_sec = 0.08f;
|
||||||
switch (ev.sound) {
|
switch (ev.sound) {
|
||||||
case sim::SimSoundCue::StartBeep: wav = "START1.WAV"; base_gain = 0.50f; cd_sec = 0.15f; break;
|
case sim::SimSoundCue::StartBeep: wav = "START1.WAV"; base_gain = 0.50f; cd_sec = 0.15f; break;
|
||||||
@@ -455,20 +522,21 @@ void GameApp::handle_sim_events() {
|
|||||||
case sim::SimSoundCue::Boost: wav = "BOOST.WAV"; base_gain = 0.44f; cd_sec = 0.45f; break;
|
case sim::SimSoundCue::Boost: wav = "BOOST.WAV"; base_gain = 0.44f; cd_sec = 0.45f; break;
|
||||||
case sim::SimSoundCue::Pickup: wav = "PICKUP.WAV"; base_gain = 0.44f; cd_sec = 0.12f; break;
|
case sim::SimSoundCue::Pickup: wav = "PICKUP.WAV"; base_gain = 0.44f; cd_sec = 0.12f; break;
|
||||||
case sim::SimSoundCue::Powerup: wav = "POWERUP.WAV"; base_gain = 0.52f; cd_sec = 0.15f; break;
|
case sim::SimSoundCue::Powerup: wav = "POWERUP.WAV"; base_gain = 0.52f; cd_sec = 0.15f; break;
|
||||||
case sim::SimSoundCue::Refuel: wav = "REFUEL.WAV"; base_gain = 0.28f; cd_sec = 0.35f; break;
|
case sim::SimSoundCue::Refuel: wav = "REFUEL.WAV"; base_gain = 0.42f; cd_sec = 0.35f; break;
|
||||||
case sim::SimSoundCue::LockOn: wav = "LOCKON4.WAV"; base_gain = 0.38f; cd_sec = 0.35f; break;
|
case sim::SimSoundCue::LockOn: wav = "LOCKON4.WAV"; base_gain = 0.38f; cd_sec = 0.35f; break;
|
||||||
case sim::SimSoundCue::Warning: wav = "WARNING.WAV"; base_gain = 0.40f; cd_sec = 0.50f; break;
|
case sim::SimSoundCue::Warning: wav = "WARNING.WAV"; base_gain = 0.40f; cd_sec = 0.50f; break;
|
||||||
case sim::SimSoundCue::Stunt180: wav = "STUNT180.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
case sim::SimSoundCue::Stunt180: wav = "STUNT180.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
||||||
case sim::SimSoundCue::Stunt360: wav = "STUNT360.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
case sim::SimSoundCue::Stunt360: wav = "STUNT360.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
||||||
case sim::SimSoundCue::Stunt720: wav = "STUNT720.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
case sim::SimSoundCue::Stunt720: wav = "STUNT720.WAV"; base_gain = 0.52f; cd_sec = 0.30f; break;
|
||||||
case sim::SimSoundCue::SwitchTrigger: wav = "SWITCH.WAV"; base_gain = 0.45f; cd_sec = 0.30f; break;
|
case sim::SimSoundCue::SwitchTrigger: wav = "SWITCH.WAV"; base_gain = 0.45f; cd_sec = 0.30f; break;
|
||||||
|
case sim::SimSoundCue::PitComplete: wav = "POWERUP.WAV"; base_gain = 0.46f; pitch = 1.15f; cd_sec = 0.25f; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
if (wav) {
|
if (wav) {
|
||||||
if (ev.pos.len_sq() < 0.01f) {
|
if (ev.pos.len_sq() < 0.01f) {
|
||||||
audio_.play_sfx(wav, base_gain, 1.0f, 0.0f, false, cd_sec);
|
audio_.play_sfx(wav, base_gain, pitch, 0.0f, false, cd_sec);
|
||||||
} else {
|
} else {
|
||||||
audio_.play_sfx_3d(wav, ev.pos, listener_pos, listener_right, base_gain, 1.0f, cd_sec);
|
audio_.play_sfx_3d(wav, ev.pos, listener_pos, listener_right, base_gain, pitch, cd_sec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -512,9 +580,24 @@ void GameApp::update_racing_step(float dt) {
|
|||||||
audio_.set_engine_state(c0.recovery_state == sim::RecoveryState::Active,
|
audio_.set_engine_state(c0.recovery_state == sim::RecoveryState::Active,
|
||||||
spd_ratio, c0.boost_timer > 0.05f, c0.scrape_intensity);
|
spd_ratio, c0.boost_timer > 0.05f, c0.scrape_intensity);
|
||||||
}
|
}
|
||||||
|
bool any_pit = false;
|
||||||
|
bool any_charging = false;
|
||||||
|
float fill_ratio = 1.0f;
|
||||||
|
for (const auto& c : race_sim_.crafts()) {
|
||||||
|
if (!c.is_human || c.recovery_state != sim::RecoveryState::Active) continue;
|
||||||
|
if (c.on_pit_mask != 0) {
|
||||||
|
any_pit = true;
|
||||||
|
}
|
||||||
|
if (c.active_recharge_mask != 0) {
|
||||||
|
any_charging = true;
|
||||||
|
fill_ratio = std::min(fill_ratio, c.pit_fill_ratio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
audio_.set_pitstop_state(any_pit, any_charging, fill_ratio);
|
||||||
|
|
||||||
if (race_sim_.race_finished()) {
|
if (race_sim_.race_finished()) {
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
post_race_record_flags_ = hiscores_.submit_race(selected_track_, race_sim_.crafts());
|
post_race_record_flags_ = hiscores_.submit_race(selected_track_, race_sim_.crafts());
|
||||||
if (selected_mode_ == sim::GameMode::CloneRace && !race_sim_.crafts().empty() &&
|
if (selected_mode_ == sim::GameMode::CloneRace && !race_sim_.crafts().empty() &&
|
||||||
race_sim_.crafts()[0].finished) {
|
race_sim_.crafts()[0].finished) {
|
||||||
@@ -1022,6 +1105,7 @@ int GameApp::run() {
|
|||||||
if (state_ == ScreenState::Racing) {
|
if (state_ == ScreenState::Racing) {
|
||||||
if (input_.menu_input().pause) {
|
if (input_.menu_input().pause) {
|
||||||
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
audio_.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
|
audio_.set_pitstop_state(false, false, 1.0f);
|
||||||
enter_state(ScreenState::Paused);
|
enter_state(ScreenState::Paused);
|
||||||
} else {
|
} else {
|
||||||
for (int s = 0; s < steps; ++s) {
|
for (int s = 0; s < steps; ++s) {
|
||||||
@@ -1036,6 +1120,13 @@ int GameApp::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render_frame(static_cast<float>(clock_.alpha()));
|
render_frame(static_cast<float>(clock_.alpha()));
|
||||||
|
if (!opts_.screenshot_path.empty() && smoke_left == 1) {
|
||||||
|
if (write_backbuffer_ppm(opts_.screenshot_path, win_w_, win_h_)) {
|
||||||
|
LOG_INFO("Saved screenshot to %s (%dx%d)", opts_.screenshot_path.c_str(), win_w_, win_h_);
|
||||||
|
} else {
|
||||||
|
LOG_WARN("Failed to write screenshot: %s", opts_.screenshot_path.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
SDL_GL_SwapWindow(window_);
|
SDL_GL_SwapWindow(window_);
|
||||||
|
|
||||||
if (smoke_left > 0) {
|
if (smoke_left > 0) {
|
||||||
@@ -1045,7 +1136,7 @@ int GameApp::run() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// Exercise both Modern & Classic modes during automated smoke test
|
// Exercise both Modern & Classic modes during automated smoke test
|
||||||
if (smoke_left == opts_.smoke_test_frames / 2) {
|
if (opts_.screenshot_path.empty() && smoke_left == opts_.smoke_test_frames / 2) {
|
||||||
cfg_.classic_mode = !cfg_.classic_mode;
|
cfg_.classic_mode = !cfg_.classic_mode;
|
||||||
}
|
}
|
||||||
if (--smoke_left == 0) {
|
if (--smoke_left == 0) {
|
||||||
@@ -1069,7 +1160,10 @@ void GameApp::render_frame(float alpha) {
|
|||||||
std::sin(viewer_pitch_),
|
std::sin(viewer_pitch_),
|
||||||
std::cos(viewer_yaw_) * std::cos(viewer_pitch_));
|
std::cos(viewer_yaw_) * std::cos(viewer_pitch_));
|
||||||
cam.target = cam.eye + look;
|
cam.target = cam.eye + look;
|
||||||
world_ren_.render_world_view(cam, {}, {}, 0, 1, cfg_);
|
std::vector<render::DynamicLight> tv_all;
|
||||||
|
append_charger_lights(viewer_level_, ui_time_, tv_all);
|
||||||
|
auto tv_lights = select_viewport_lights(tv_all, cam.eye, cfg_.draw_distance);
|
||||||
|
world_ren_.render_world_view(cam, {}, {}, 0, 1, cfg_, tv_lights, {});
|
||||||
world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_);
|
world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_);
|
||||||
|
|
||||||
ui_ren_.begin(win_w_, win_h_);
|
ui_ren_.begin(win_w_, win_h_);
|
||||||
@@ -1085,6 +1179,10 @@ void GameApp::render_frame(float alpha) {
|
|||||||
std::vector<render::ModelInstance> models;
|
std::vector<render::ModelInstance> models;
|
||||||
models.reserve(race_sim_.crafts().size() + race_sim_.pickups().size() +
|
models.reserve(race_sim_.crafts().size() + race_sim_.pickups().size() +
|
||||||
race_sim_.props().size() + race_sim_.projectiles().size() + 4);
|
race_sim_.props().size() + race_sim_.projectiles().size() + 4);
|
||||||
|
std::vector<render::CraftShadow> craft_shadows;
|
||||||
|
craft_shadows.reserve(race_sim_.crafts().size());
|
||||||
|
std::vector<render::DynamicLight> all_lights;
|
||||||
|
all_lights.reserve(race_sim_.level().pads.size() + race_sim_.crafts().size() + 16);
|
||||||
|
|
||||||
for (const auto& c : race_sim_.crafts()) {
|
for (const auto& c : race_sim_.crafts()) {
|
||||||
sim::CraftPose p = sim::interpolate_pose(c, alpha);
|
sim::CraftPose p = sim::interpolate_pose(c, alpha);
|
||||||
@@ -1093,6 +1191,20 @@ void GameApp::render_frame(float alpha) {
|
|||||||
float vscale = sim::kVehicleSpecs[std::clamp(c.vehicle_idx, 0, 5)].visual_scale;
|
float vscale = sim::kVehicleSpecs[std::clamp(c.vehicle_idx, 0, 5)].visual_scale;
|
||||||
models.push_back({sim::model_key_for(c.vehicle_idx, c.team_idx), p.pos,
|
models.push_back({sim::model_key_for(c.vehicle_idx, c.team_idx), p.pos,
|
||||||
p.yaw, p.pitch, p.roll, vscale, tint});
|
p.yaw, p.pitch, p.roll, vscale, tint});
|
||||||
|
if (c.recovery_state == sim::RecoveryState::Active ||
|
||||||
|
c.recovery_state == sim::RecoveryState::Repairing ||
|
||||||
|
c.recovery_state == sim::RecoveryState::Destroyed) {
|
||||||
|
craft_shadows.push_back({p.pos, 0.82f + 0.35f * vscale});
|
||||||
|
}
|
||||||
|
if (c.recovery_state == sim::RecoveryState::Active) {
|
||||||
|
Vec3 fwd(std::sin(p.yaw), 0.0f, std::cos(p.yaw));
|
||||||
|
Vec3 jet_pos = p.pos - fwd * 0.55f + Vec3(0.0f, 0.14f, 0.0f);
|
||||||
|
if (c.boost_timer > 0.0f) {
|
||||||
|
all_lights.push_back({jet_pos, 6.5f, Vec3(0.40f, 0.88f, 1.00f), 1.35f});
|
||||||
|
} else if (c.speed_horizontal() > 2.5f) {
|
||||||
|
all_lights.push_back({jet_pos, 3.8f, Vec3(0.28f, 0.68f, 1.00f), 0.45f});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (race_sim_.has_clone_ghost()) {
|
if (race_sim_.has_clone_ghost()) {
|
||||||
sim::CraftPose gp = race_sim_.interpolated_clone_pose(alpha);
|
sim::CraftPose gp = race_sim_.interpolated_clone_pose(alpha);
|
||||||
@@ -1118,23 +1230,49 @@ void GameApp::render_frame(float alpha) {
|
|||||||
else if (pk.subtype <= 5) pcol = Vec4(0.3f, 0.7f, 1.0f, 1.0f); // shield
|
else if (pk.subtype <= 5) pcol = Vec4(0.3f, 0.7f, 1.0f, 1.0f); // shield
|
||||||
else if (pk.subtype <= 9) pcol = Vec4(1.0f, 0.9f, 0.2f, 1.0f); // ammo
|
else if (pk.subtype <= 9) pcol = Vec4(1.0f, 0.9f, 0.2f, 1.0f); // ammo
|
||||||
else pcol = Vec4(1.0f, 0.35f, 0.9f, 1.0f); // weapon/booster upgrade
|
else pcol = Vec4(1.0f, 0.35f, 0.9f, 1.0f); // weapon/booster upgrade
|
||||||
models.push_back({"CONE0-0", pk.pos + Vec3(0, bob, 0), rot, 0.0f, 0.0f, 0.65f, pcol});
|
Vec3 ppos = pk.pos + Vec3(0, bob, 0);
|
||||||
|
models.push_back({"CONE0-0", ppos, rot, 0.0f, 0.0f, 0.65f, pcol});
|
||||||
|
all_lights.push_back({ppos + Vec3(0.0f, 0.25f, 0.0f), 3.4f, Vec3(pcol.x, pcol.y, pcol.z), 0.46f});
|
||||||
}
|
}
|
||||||
for (const auto& pj : race_sim_.projectiles()) {
|
for (const auto& pj : race_sim_.projectiles()) {
|
||||||
if (!pj.active || !pj.is_missile) continue;
|
if (!pj.active) continue;
|
||||||
|
if (pj.is_missile) {
|
||||||
models.push_back({"CONE0-1", pj.pos, pj.yaw, -kHalfPi, 0.0f, 0.5f, Vec4(1.0f, 0.3f, 0.2f, 1)});
|
models.push_back({"CONE0-1", pj.pos, pj.yaw, -kHalfPi, 0.0f, 0.5f, Vec4(1.0f, 0.3f, 0.2f, 1)});
|
||||||
|
all_lights.push_back({pj.pos, 5.8f, Vec3(1.0f, 0.44f, 0.14f), 1.15f});
|
||||||
|
} else {
|
||||||
|
all_lights.push_back({pj.pos, 2.8f, Vec3(1.0f, 0.85f, 0.32f), 0.55f});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<render::ParticleQuad> parts;
|
std::vector<render::ParticleQuad> parts;
|
||||||
parts.reserve(race_sim_.particles().size() + race_sim_.pickups().size());
|
parts.reserve(race_sim_.particles().size() + race_sim_.projectiles().size());
|
||||||
|
std::vector<Vec3> fire_clusters;
|
||||||
for (const auto& pb : race_sim_.particles()) {
|
for (const auto& pb : race_sim_.particles()) {
|
||||||
parts.push_back({pb.pos, pb.size, pb.color});
|
bool additive = (pb.kind == sim::ParticleKind::AdditiveGlow ||
|
||||||
|
pb.kind == sim::ParticleKind::Fireball);
|
||||||
|
parts.push_back({pb.pos, pb.size, pb.color, static_cast<float>(pb.kind), pb.seed, additive});
|
||||||
|
if (pb.kind == sim::ParticleKind::Fireball && pb.color.w > 0.15f) {
|
||||||
|
bool merged = false;
|
||||||
|
for (const auto& fp : fire_clusters) {
|
||||||
|
if ((pb.pos - fp).len_sq() < 4.84f) {
|
||||||
|
merged = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!merged) {
|
||||||
|
fire_clusters.push_back(pb.pos);
|
||||||
|
all_lights.push_back({pb.pos, 10.5f, Vec3(1.0f, 0.54f, 0.14f),
|
||||||
|
1.65f * std::clamp(pb.color.w, 0.25f, 1.0f)});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (const auto& pj : race_sim_.projectiles()) {
|
for (const auto& pj : race_sim_.projectiles()) {
|
||||||
if (!pj.active || pj.is_missile) continue;
|
if (!pj.active || pj.is_missile) continue;
|
||||||
parts.push_back({pj.pos, 0.28f, Vec4(1.0f, 0.9f, 0.35f, 1.0f)});
|
parts.push_back({pj.pos, 0.28f, Vec4(1.0f, 0.9f, 0.35f, 1.0f), 0.0f, 0.0f, true});
|
||||||
}
|
}
|
||||||
|
append_charger_lights(race_sim_.level(), ui_time_, all_lights);
|
||||||
|
|
||||||
|
float draw_dist = cfg_.classic_mode ? 38.0f : cfg_.draw_distance;
|
||||||
int split_count = (selected_mode_ == sim::GameMode::SplitScreen && race_sim_.crafts().size() >= 2) ? 2 : 1;
|
int split_count = (selected_mode_ == sim::GameMode::SplitScreen && race_sim_.crafts().size() >= 2) ? 2 : 1;
|
||||||
std::array<render::RenderCamera, 2> cams{};
|
std::array<render::RenderCamera, 2> cams{};
|
||||||
for (int vp = 0; vp < split_count; ++vp) {
|
for (int vp = 0; vp < split_count; ++vp) {
|
||||||
@@ -1182,33 +1320,45 @@ void GameApp::render_frame(float alpha) {
|
|||||||
}
|
}
|
||||||
float min_cam_y = race_sim_.level().sample_height_world(cams[vp].eye.x, cams[vp].eye.z) + 0.4f;
|
float min_cam_y = race_sim_.level().sample_height_world(cams[vp].eye.x, cams[vp].eye.z) + 0.4f;
|
||||||
if (cams[vp].eye.y < min_cam_y) cams[vp].eye.y = min_cam_y;
|
if (cams[vp].eye.y < min_cam_y) cams[vp].eye.y = min_cam_y;
|
||||||
world_ren_.render_world_view(cams[vp], models, parts, vp, split_count, cfg_);
|
auto vp_lights = select_viewport_lights(all_lights, cams[vp].target, draw_dist);
|
||||||
|
world_ren_.render_world_view(cams[vp], models, parts, vp, split_count, cfg_, vp_lights, craft_shadows);
|
||||||
}
|
}
|
||||||
world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_);
|
world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_);
|
||||||
|
|
||||||
|
// Compute screen-space 2D HUD viewport bounds (respects Classic 4:3 pillarbox!)
|
||||||
|
int frame_x = 0, frame_y_gl = 0, frame_w = win_w_, frame_h = win_h_;
|
||||||
|
if (cfg_.classic_mode) {
|
||||||
|
float win_aspect = static_cast<float>(win_w_) / static_cast<float>(std::max(win_h_, 1));
|
||||||
|
constexpr float kTargetAspect = 4.0f / 3.0f;
|
||||||
|
if (win_aspect > kTargetAspect) {
|
||||||
|
frame_w = static_cast<int>(static_cast<float>(win_h_) * kTargetAspect);
|
||||||
|
frame_x = (win_w_ - frame_w) / 2;
|
||||||
|
} else {
|
||||||
|
frame_h = static_cast<int>(static_cast<float>(win_w_) / kTargetAspect);
|
||||||
|
frame_y_gl = (win_h_ - frame_h) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ui_ren_.begin(win_w_, win_h_);
|
ui_ren_.begin(win_w_, win_h_);
|
||||||
for (int vp = 0; vp < split_count; ++vp) {
|
for (int vp = 0; vp < split_count; ++vp) {
|
||||||
int vh = (split_count == 2) ? (win_h_ / 2) : win_h_;
|
int vh = (split_count == 2) ? (frame_h / 2) : frame_h;
|
||||||
int vy = (split_count == 2 && vp == 0) ? 0 : (split_count == 2 ? vh : 0);
|
int gl_vy = (split_count == 2)
|
||||||
int gl_vy = (split_count == 2 && vp == 0) ? (win_h_ - vh) : 0;
|
? ((vp == 0) ? (frame_y_gl + frame_h - vh) : frame_y_gl)
|
||||||
|
: frame_y_gl;
|
||||||
if (hud_visible_) {
|
if (hud_visible_) {
|
||||||
// Draw HUD inside screen coordinates [0..win_w_] x [vy..vy+vh]
|
render_hud_viewport(race_sim_.crafts()[vp], cams[vp], frame_x, gl_vy, frame_w, vh,
|
||||||
render_hud_viewport(race_sim_.crafts()[vp], cams[vp], 0, gl_vy, win_w_, vh,
|
|
||||||
vp == 0 && cfg_.show_minimap);
|
vp == 0 && cfg_.show_minimap);
|
||||||
} else if (race_sim_.countdown_active()) {
|
} else if (race_sim_.countdown_active() || race_sim_.crafts()[vp].race_time < 0.85f) {
|
||||||
float hs = std::clamp(static_cast<float>(vh) / 720.0f, 0.55f, 1.5f);
|
float hs = std::clamp(static_cast<float>(vh) / 480.0f, 0.55f, 1.8f);
|
||||||
int top_y = win_h_ - (gl_vy + vh);
|
int top_y = win_h_ - (gl_vy + vh);
|
||||||
int c = static_cast<int>(std::ceil(race_sim_.countdown_timer()));
|
float cx = static_cast<float>(frame_x) + static_cast<float>(frame_w) * 0.5f;
|
||||||
ui_ren_.draw_text_centered(static_cast<float>(win_w_) * 0.5f,
|
render_countdown_lights(cx, static_cast<float>(top_y) + 126.0f * hs, hs);
|
||||||
static_cast<float>(top_y) + static_cast<float>(vh) * 0.25f,
|
|
||||||
4.8f * hs, std::to_string(c),
|
|
||||||
Vec4(1.0f, 1.0f, 1.0f, 1.0f), true, render::UiFont::Panel);
|
|
||||||
}
|
}
|
||||||
if (split_count == 2 && vp == 0) {
|
if (split_count == 2 && vp == 0) {
|
||||||
ui_ren_.draw_rect(0, static_cast<float>(vh - 2), static_cast<float>(win_w_), 4.0f,
|
int div_y = win_h_ - (frame_y_gl + vh);
|
||||||
Vec4(0.1f, 0.1f, 0.15f, 1.0f));
|
ui_ren_.draw_rect(static_cast<float>(frame_x), static_cast<float>(div_y - 2),
|
||||||
|
static_cast<float>(frame_w), 4.0f, Vec4(0.1f, 0.1f, 0.15f, 1.0f));
|
||||||
}
|
}
|
||||||
(void)vy;
|
|
||||||
}
|
}
|
||||||
if (state_ == ScreenState::Paused) {
|
if (state_ == ScreenState::Paused) {
|
||||||
render_menus();
|
render_menus();
|
||||||
@@ -1246,122 +1396,300 @@ void GameApp::render_hud_viewport(const sim::CraftState& craft, const render::Re
|
|||||||
int vx, int vy, int vw, int vh, bool show_minimap) {
|
int vx, int vy, int vw, int vh, bool show_minimap) {
|
||||||
const auto& str = get_strings(cfg_.language);
|
const auto& str = get_strings(cfg_.language);
|
||||||
int top_y = win_h_ - (vy + vh);
|
int top_y = win_h_ - (vy + vh);
|
||||||
float s = std::clamp(static_cast<float>(vh) / 720.0f, 0.55f, 1.5f);
|
bool split_view = (selected_mode_ == sim::GameMode::SplitScreen && race_sim_.crafts().size() >= 2);
|
||||||
|
float hs = std::min(static_cast<float>(vw) / 640.0f,
|
||||||
|
static_cast<float>(vh) / (split_view ? 410.0f : 475.0f));
|
||||||
|
hs = std::clamp(hs, 0.55f, 2.4f);
|
||||||
|
float s = std::clamp(static_cast<float>(vh) / 720.0f, 0.55f, 1.6f);
|
||||||
|
|
||||||
// 1. Missile lock-on targeting diamond
|
float ox = static_cast<float>(vx) + (static_cast<float>(vw) - 640.0f * hs) * 0.5f;
|
||||||
|
float oy = static_cast<float>(top_y) + 2.0f * hs;
|
||||||
|
|
||||||
|
auto draw_panel = [&](int spr, float x640, float y480, const Vec4& tint = Vec4(1, 1, 1, 1)) {
|
||||||
|
ui_ren_.draw_bank_sprite("panel", spr, ox + x640 * hs, oy + y480 * hs, hs, tint);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. Missile Lock-On Target Reticle (#258..#267)
|
||||||
if (craft.lock_target_id >= 0 && craft.lock_target_id < static_cast<int>(race_sim_.crafts().size())) {
|
if (craft.lock_target_id >= 0 && craft.lock_target_id < static_cast<int>(race_sim_.crafts().size())) {
|
||||||
const auto& tgt = race_sim_.crafts()[craft.lock_target_id];
|
const auto& tgt = race_sim_.crafts()[craft.lock_target_id];
|
||||||
if (tgt.recovery_state == sim::RecoveryState::Active) {
|
if (tgt.recovery_state == sim::RecoveryState::Active) {
|
||||||
float aspect = static_cast<float>(vw) / static_cast<float>(std::max(vh, 1));
|
float aspect = static_cast<float>(vw) / static_cast<float>(std::max(vh, 1));
|
||||||
|
if (split_view) aspect = std::max(aspect, 1.0f);
|
||||||
float fov = cfg_.classic_mode ? 62.0f : cfg_.fov_deg;
|
float fov = cfg_.classic_mode ? 62.0f : cfg_.fov_deg;
|
||||||
Mat4 vp_mat = Mat4::perspective(deg_to_rad(fov), aspect, cam.z_near, cam.z_far) *
|
Mat4 vp_mat = Mat4::perspective(deg_to_rad(fov), aspect, cam.z_near, cam.z_far) *
|
||||||
Mat4::look_at(cam.eye, cam.target, cam.up);
|
Mat4::look_at(cam.eye, cam.target, cam.up);
|
||||||
float sx = 0, sy = 0;
|
float sx = 0.0f, sy = 0.0f;
|
||||||
if (project_world_to_screen(tgt.curr_pose.pos, vp_mat, vx, vy, vw, vh, win_h_, sx, sy)) {
|
if (project_world_to_screen(tgt.curr_pose.pos, vp_mat, vx, vy, vw, vh, win_h_, sx, sy)) {
|
||||||
Vec4 rcol = (craft.lock_progress >= 1.0f) ? Vec4(1.0f, 0.2f, 0.15f, 0.95f)
|
bool locked = (craft.lock_progress >= 1.0f);
|
||||||
: Vec4(1.0f, 0.85f, 0.2f, 0.85f);
|
float pulse = locked ? (0.75f + 0.25f * std::sin(static_cast<float>(ui_time_) * 16.0f)) : 0.92f;
|
||||||
float r = 24.0f * (1.5f - 0.5f * craft.lock_progress) * s;
|
Vec4 tint(1.0f, 1.0f, 1.0f, pulse);
|
||||||
ui_ren_.draw_rect_outline(sx - r, sy - r, r * 2.0f, r * 2.0f, 2.0f, rcol);
|
float rs = std::max(1.25f, hs * 1.15f);
|
||||||
if (craft.lock_progress >= 1.0f) {
|
int box_spr = locked ? 259 : 258;
|
||||||
ui_ren_.draw_text_centered(sx, sy - r - 18.0f * s, 1.5f * s, "LOCK", rcol);
|
ui_ren_.draw_bank_sprite("panel", box_spr, sx - 10.5f * rs, sy - 9.5f * rs, rs, tint);
|
||||||
|
|
||||||
|
float spread = (1.0f - craft.lock_progress) * 26.0f * rs + 11.5f * rs;
|
||||||
|
ui_ren_.draw_bank_sprite("panel", locked ? 261 : 260, sx - 10.5f * rs, sy - spread - 4.0f * rs, rs, tint);
|
||||||
|
ui_ren_.draw_bank_sprite("panel", locked ? 263 : 262, sx - 10.5f * rs, sy + spread, rs, tint);
|
||||||
|
ui_ren_.draw_bank_sprite("panel", locked ? 265 : 264, sx - spread - 4.0f * rs, sy - 9.5f * rs, rs, tint);
|
||||||
|
ui_ren_.draw_bank_sprite("panel", locked ? 267 : 266, sx + spread, sy - 9.5f * rs, rs, tint);
|
||||||
|
|
||||||
|
if (locked) {
|
||||||
|
ui_ren_.draw_text_centered(sx, sy - spread - 20.0f * s, 1.15f * s, "LOCK",
|
||||||
|
Vec4(1.0f, 0.25f, 0.18f, pulse), true, render::UiFont::Panel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Top-left Race Info (POS, LAP, TIME)
|
// 2. Authentic Top Visor Curved Segmented Gauges (HIOCTANE.EXE PANEL0-1 tables)
|
||||||
float pad = 16.0f * s;
|
struct SegSpec {
|
||||||
float top_box_w = 300.0f * s;
|
int16_t x;
|
||||||
float top_box_h = 78.0f * s;
|
int16_t y;
|
||||||
ui_ren_.draw_rect(pad, top_y + pad, top_box_w, top_box_h, Vec4(0.02f, 0.04f, 0.1f, 0.68f));
|
int16_t spr;
|
||||||
ui_ren_.draw_rect_outline(pad, top_y + pad, top_box_w, top_box_h, 2.0f, Vec4(0.25f, 0.65f, 1.0f, 0.8f));
|
int thr;
|
||||||
char line1[64], line2[64];
|
};
|
||||||
if (selected_mode_ == sim::GameMode::DeathMatch) {
|
auto draw_arc = [&](const SegSpec* segs, int count, int val_10000,
|
||||||
std::snprintf(line1, sizeof(line1), "POS %d/%zu KILLS %d/%d",
|
const Vec4& lit_tint, float back_alpha) {
|
||||||
craft.placement, race_sim_.crafts().size(),
|
Vec4 dim_tint(0.14f, 0.17f, 0.24f, back_alpha);
|
||||||
craft.kills, race_sim_.setup().deathmatch_kill_limit);
|
for (int i = 0; i < count; ++i) {
|
||||||
} else {
|
draw_panel(segs[i].spr, static_cast<float>(segs[i].x), static_cast<float>(segs[i].y), dim_tint);
|
||||||
std::snprintf(line1, sizeof(line1), "POS %d/%zu LAP %d/%d",
|
|
||||||
craft.placement, race_sim_.crafts().size(),
|
|
||||||
std::min(craft.lap, race_sim_.setup().total_laps),
|
|
||||||
race_sim_.setup().total_laps);
|
|
||||||
}
|
}
|
||||||
std::snprintf(line2, sizeof(line2), "TIME %s", format_time(craft.race_time).c_str());
|
for (int i = 0; i < count; ++i) {
|
||||||
ui_ren_.draw_text_fit(pad + 10.0f * s, top_y + pad + 10.0f * s, top_box_w - 20.0f * s,
|
if (val_10000 > segs[i].thr) {
|
||||||
1.75f * s, line1, Vec4(1, 0.9f, 0.25f, 1));
|
draw_panel(segs[i].spr, static_cast<float>(segs[i].x), static_cast<float>(segs[i].y), lit_tint);
|
||||||
ui_ren_.draw_text_fit(pad + 10.0f * s, top_y + pad + 34.0f * s, top_box_w - 20.0f * s,
|
|
||||||
1.55f * s, line2, Vec4(0.85f, 0.95f, 1, 1));
|
|
||||||
if (craft.best_lap_time > 0.0f) {
|
|
||||||
ui_ren_.draw_text_fit(pad + 10.0f * s, top_y + pad + 55.0f * s, top_box_w - 20.0f * s,
|
|
||||||
1.40f * s, "BEST " + format_time(craft.best_lap_time), Vec4(0.4f, 1.0f, 0.6f, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Bottom-left Vehicle Resource Bars + Speedometer
|
|
||||||
float hud_w = 330.0f * s;
|
|
||||||
float hud_h = 108.0f * s;
|
|
||||||
float hud_y = static_cast<float>(top_y + vh) - hud_h - pad;
|
|
||||||
ui_ren_.draw_rect(pad, hud_y, hud_w, hud_h, Vec4(0.02f, 0.04f, 0.1f, 0.72f));
|
|
||||||
ui_ren_.draw_rect_outline(pad, hud_y, hud_w, hud_h, 2.0f, Vec4(0.25f, 0.65f, 1.0f, 0.8f));
|
|
||||||
|
|
||||||
auto draw_bar = [&](float bx, float by, const char* lbl, float val, float maxv, const Vec4& col,
|
|
||||||
bool charging) {
|
|
||||||
Vec4 lbl_col = charging
|
|
||||||
? ((static_cast<int>(craft.race_time * 10.0f) & 1) ? Vec4(1.0f, 1.0f, 1.0f, 1.0f)
|
|
||||||
: Vec4(0.45f, 1.0f, 0.55f, 1.0f))
|
|
||||||
: Vec4(0.85f, 0.9f, 1.0f, 1);
|
|
||||||
ui_ren_.draw_text_fit(bx, by, 72.0f * s, 1.45f * s, lbl, lbl_col);
|
|
||||||
float bar_x = bx + 78.0f * s;
|
|
||||||
float bar_w = 215.0f * s;
|
|
||||||
float bar_h = 12.0f * s;
|
|
||||||
ui_ren_.draw_rect(bar_x, by, bar_w, bar_h, Vec4(0.12f, 0.12f, 0.18f, 0.9f));
|
|
||||||
if (charging) {
|
|
||||||
ui_ren_.draw_rect_outline(bar_x, by, bar_w, bar_h, 1.0f, Vec4(0.45f, 1.0f, 0.55f, 0.9f));
|
|
||||||
}
|
}
|
||||||
float frac = std::clamp(val / std::max(maxv, 1.0f), 0.0f, 1.0f);
|
|
||||||
ui_ren_.draw_rect(bar_x + 1, by + 1, (bar_w - 2) * frac, bar_h - 2, col);
|
|
||||||
};
|
};
|
||||||
draw_bar(pad + 10.0f * s, hud_y + 10.0f * s, "SHLD", craft.shield, craft.max_shield,
|
|
||||||
Vec4(0.2f, 0.75f, 1.0f, 1), (craft.active_recharge_mask & 1u) != 0);
|
|
||||||
draw_bar(pad + 10.0f * s, hud_y + 30.0f * s, "FUEL", craft.fuel, craft.max_fuel,
|
|
||||||
Vec4(1.0f, 0.65f, 0.15f, 1), (craft.active_recharge_mask & 2u) != 0);
|
|
||||||
draw_bar(pad + 10.0f * s, hud_y + 50.0f * s, "AMMO", craft.ammo, craft.max_ammo,
|
|
||||||
Vec4(0.95f, 0.9f, 0.25f, 1), (craft.active_recharge_mask & 4u) != 0);
|
|
||||||
|
|
||||||
int kmh = static_cast<int>(craft.speed_horizontal() * 14.5f);
|
static constexpr SegSpec kFuelArc[17] = {
|
||||||
char spd_buf[64];
|
{514, 4, 17, 0}, {488, 4, 16, 384}, {464, 4, 15, 768}, {440, 4, 14, 1152},
|
||||||
std::snprintf(spd_buf, sizeof(spd_buf), "%3d KPH G%d M%d B%d",
|
{414, 4, 13, 1536}, {390, 4, 12, 1920}, {366, 4, 11, 2304}, {342, 4, 10, 2688},
|
||||||
kmh, craft.minigun_level, craft.missile_level, craft.booster_level);
|
{324, 4, 9, 3072}, {306, 4, 8, 3456}, {286, 4, 7, 3840}, {264, 4, 6, 4224},
|
||||||
ui_ren_.draw_text_fit(pad + 10.0f * s, hud_y + 74.0f * s, hud_w - 20.0f * s,
|
{240, 4, 5, 4608}, {216, 4, 4, 5376}, {182, 4, 3, 6528}, {136, 4, 2, 7680},
|
||||||
1.65f * s, spd_buf, Vec4(1, 1, 1, 1));
|
{82, 4, 1, 8832},
|
||||||
|
};
|
||||||
|
static constexpr SegSpec kSpeedWaveDim[19] = {
|
||||||
|
{120, 16, 18, 0}, {142, 16, 19, 526}, {162, 16, 20, 1052}, {186, 16, 21, 1578},
|
||||||
|
{206, 16, 22, 2104}, {228, 16, 23, 2630}, {246, 16, 24, 3156}, {268, 16, 25, 3682},
|
||||||
|
{288, 16, 26, 4208}, {306, 16, 27, 4734}, {324, 16, 28, 5260}, {342, 16, 29, 5786},
|
||||||
|
{364, 16, 30, 6312}, {388, 16, 31, 6838}, {414, 16, 32, 7364}, {438, 16, 33, 7890},
|
||||||
|
{462, 16, 34, 8416}, {484, 16, 35, 8942}, {508, 16, 36, 9468},
|
||||||
|
};
|
||||||
|
static constexpr SegSpec kSpeedWaveLit[19] = {
|
||||||
|
{120, 16, 37, 0}, {142, 16, 38, 526}, {162, 16, 39, 1052}, {186, 16, 40, 1578},
|
||||||
|
{206, 16, 41, 2104}, {228, 16, 42, 2630}, {246, 16, 43, 3156}, {268, 16, 44, 3682},
|
||||||
|
{288, 16, 45, 4208}, {306, 16, 46, 4734}, {324, 16, 47, 5260}, {342, 16, 48, 5786},
|
||||||
|
{364, 16, 49, 6312}, {388, 16, 50, 6838}, {414, 16, 51, 7364}, {438, 16, 52, 7890},
|
||||||
|
{462, 16, 53, 8416}, {484, 16, 54, 8942}, {508, 16, 55, 9468},
|
||||||
|
};
|
||||||
|
static constexpr SegSpec kSpeedBar[16] = {
|
||||||
|
{128, 26, 56, 0}, {148, 26, 57, 384}, {168, 26, 58, 768}, {188, 26, 59, 1152},
|
||||||
|
{208, 26, 60, 1536}, {230, 26, 61, 1920}, {248, 26, 62, 2304}, {268, 26, 63, 2688},
|
||||||
|
{288, 26, 64, 3072}, {306, 26, 65, 3456}, {324, 26, 66, 3840}, {342, 26, 67, 4608},
|
||||||
|
{360, 26, 68, 5376}, {380, 26, 69, 6528}, {418, 26, 70, 7680}, {454, 26, 71, 8832},
|
||||||
|
};
|
||||||
|
static constexpr SegSpec kShieldArc[6] = {
|
||||||
|
{4, 4, 72, 0}, {42, 4, 73, 1666}, {68, 4, 74, 3332},
|
||||||
|
{76, 4, 75, 4998}, {96, 4, 76, 6664}, {114, 4, 77, 8330},
|
||||||
|
};
|
||||||
|
static constexpr SegSpec kAmmoArc[6] = {
|
||||||
|
{596, 4, 91, 0}, {554, 4, 90, 1666}, {526, 4, 89, 3332},
|
||||||
|
{506, 4, 88, 4998},{488, 4, 87, 6664}, {460, 4, 86, 8330},
|
||||||
|
};
|
||||||
|
static constexpr SegSpec kRightWingRed[16] = {
|
||||||
|
{502, 28, 92, 0}, {518, 28, 93, 625}, {524, 28, 94, 1250}, {530, 28, 95, 1875},
|
||||||
|
{536, 28, 96, 2500}, {542, 28, 97, 3125}, {548, 28, 98, 3750}, {554, 28, 99, 4375},
|
||||||
|
{566, 28, 100, 5000},{578, 28, 101, 5625},{586, 28, 102, 6250}, {594, 28, 103, 6875},
|
||||||
|
{602, 28, 104, 7500},{610, 28, 105, 8125},{618, 28, 106, 8750}, {626, 28, 107, 9375},
|
||||||
|
};
|
||||||
|
|
||||||
// 4. Top-right Track Minimap
|
float shield_frac = cfg_.damage_enabled ? std::clamp(craft.shield / std::max(craft.max_shield, 1.0f), 0.0f, 1.0f) : 1.0f;
|
||||||
if (show_minimap) {
|
float fuel_frac = cfg_.fuel_enabled ? std::clamp(craft.fuel / std::max(craft.max_fuel, 1.0f), 0.0f, 1.0f) : 1.0f;
|
||||||
float mm_size = 138.0f * s;
|
float ammo_frac = cfg_.weapons_enabled ? std::clamp(craft.ammo / std::max(craft.max_ammo, 1.0f), 0.0f, 1.0f) : 1.0f;
|
||||||
render_minimap(craft, static_cast<float>(vw) - mm_size - pad, static_cast<float>(top_y) + pad, mm_size);
|
|
||||||
|
auto status_tint = [&](float frac, uint8_t bit_mask) -> Vec4 {
|
||||||
|
if ((craft.active_recharge_mask & bit_mask) != 0) {
|
||||||
|
float p = 0.80f + 0.20f * std::sin(static_cast<float>(ui_time_) * 12.0f);
|
||||||
|
return Vec4(1.25f * p, 1.35f * p, 1.25f * p, 1.0f);
|
||||||
|
}
|
||||||
|
if (frac < 0.20f && frac > 0.0f) {
|
||||||
|
float blink = 0.55f + 0.45f * std::sin(static_cast<float>(ui_time_) * 10.0f);
|
||||||
|
return Vec4(1.0f, 0.72f, 0.72f, blink);
|
||||||
|
}
|
||||||
|
return Vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Draw Speed Wave + Fuel + Shield + Ammo + Speedometer + Right Boost/Lock Wing
|
||||||
|
const auto& spec = sim::kVehicleSpecs[std::clamp(craft.vehicle_idx, 0, 5)];
|
||||||
|
float boost_mult = 1.0f + 0.14f * static_cast<float>(craft.booster_level - 1);
|
||||||
|
float max_ref_spd = spec.top_speed + spec.boost_bonus * boost_mult;
|
||||||
|
float spd_frac = std::clamp(craft.speed_horizontal() / std::max(max_ref_spd, 1.0f), 0.0f, 1.0f);
|
||||||
|
|
||||||
|
draw_arc(kFuelArc, 17, static_cast<int>(fuel_frac * 10000.0f), status_tint(fuel_frac, 2u), 0.26f);
|
||||||
|
draw_arc(kSpeedWaveDim, 19, static_cast<int>(spd_frac * 10000.0f), Vec4(1.0f, 1.0f, 1.0f, 0.95f), 0.22f);
|
||||||
|
if (craft.boost_timer > 0.0f) {
|
||||||
|
int wave_val = static_cast<int>(std::clamp(spd_frac + 0.25f, 0.35f, 1.0f) * 10000.0f);
|
||||||
|
for (int i = 0; i < 19; ++i) {
|
||||||
|
if (wave_val > kSpeedWaveLit[i].thr) {
|
||||||
|
draw_panel(kSpeedWaveLit[i].spr, static_cast<float>(kSpeedWaveLit[i].x),
|
||||||
|
static_cast<float>(kSpeedWaveLit[i].y), Vec4(1.0f, 1.0f, 1.0f, 0.98f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
draw_arc(kSpeedBar, 16, static_cast<int>(spd_frac * 10000.0f), Vec4(1.0f, 1.0f, 1.0f, 1.0f), 0.25f);
|
||||||
|
draw_arc(kShieldArc, 6, static_cast<int>(shield_frac * 10000.0f), status_tint(shield_frac, 1u), 0.30f);
|
||||||
|
draw_arc(kAmmoArc, 6, static_cast<int>(ammo_frac * 10000.0f), status_tint(ammo_frac, 4u), 0.30f);
|
||||||
|
|
||||||
|
// Right wing orange/red bar shows Missile Lock Charge (when locking) or Booster overdrive charge
|
||||||
|
float right_frac = (craft.lock_target_id >= 0 && craft.lock_progress > 0.02f)
|
||||||
|
? craft.lock_progress
|
||||||
|
: (craft.boost_timer > 0.0f ? std::clamp(craft.boost_timer / 2.5f, 0.0f, 1.0f)
|
||||||
|
: spd_frac * 0.7f);
|
||||||
|
Vec4 right_tint = (craft.lock_progress >= 1.0f)
|
||||||
|
? Vec4(1.3f, 0.9f, 0.9f, 0.7f + 0.3f * std::sin(static_cast<float>(ui_time_) * 16.0f))
|
||||||
|
: Vec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
draw_arc(kRightWingRed, 16, static_cast<int>(right_frac * 10000.0f), right_tint, 0.25f);
|
||||||
|
|
||||||
|
// 3. Giant Metallic Position Counter (#108..#117, #138 '/', #128..#137)
|
||||||
|
int place = std::clamp(craft.placement, 0, 9);
|
||||||
|
int total_c = std::clamp(static_cast<int>(race_sim_.crafts().size()), 1, 9);
|
||||||
|
draw_panel(108 + place, 4.0f, 32.0f);
|
||||||
|
draw_panel(138, 56.0f, 76.0f);
|
||||||
|
draw_panel(128 + total_c, 86.0f, 76.0f);
|
||||||
|
|
||||||
|
// 4. Weapon & Booster Upgrade Bars (#268..#276)
|
||||||
|
draw_panel(268, 148.0f, 70.0f);
|
||||||
|
draw_panel(271, 264.0f, 70.0f);
|
||||||
|
draw_panel(274, 362.0f, 70.0f);
|
||||||
|
for (int p = 0; p < 3; ++p) {
|
||||||
|
Vec4 gun_t = (craft.minigun_level > p) ? Vec4(1, 1, 1, 1) : Vec4(0.25f, 0.25f, 0.30f, 0.45f);
|
||||||
|
Vec4 msl_t = (craft.missile_level > p) ? Vec4(1, 1, 1, 1) : Vec4(0.25f, 0.25f, 0.30f, 0.45f);
|
||||||
|
Vec4 bst_t = (craft.booster_level > p) ? Vec4(1, 1, 1, 1) : Vec4(0.25f, 0.25f, 0.30f, 0.45f);
|
||||||
|
draw_panel(270, 218.0f + p * 14.0f, 70.0f, gun_t);
|
||||||
|
draw_panel(273, 316.0f + p * 14.0f, 70.0f, msl_t);
|
||||||
|
draw_panel((p == 2) ? 276 : 275, 412.0f + p * 14.0f, 70.0f, bst_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Center Warnings & Banners
|
// 5. Lap Counter (or DeathMatch Kill Limit) under Left Wing (#227 + small red digits #139..#150)
|
||||||
float cx = static_cast<float>(vw) * 0.5f;
|
int cur_a = (selected_mode_ == sim::GameMode::DeathMatch)
|
||||||
float cy = static_cast<float>(top_y) + static_cast<float>(vh) * 0.25f;
|
? std::clamp(craft.kills, 0, 99)
|
||||||
if (race_sim_.countdown_active()) {
|
: std::clamp(std::min(craft.lap, race_sim_.setup().total_laps), 1, 99);
|
||||||
int c = static_cast<int>(std::ceil(race_sim_.countdown_timer()));
|
int max_b = (selected_mode_ == sim::GameMode::DeathMatch)
|
||||||
ui_ren_.draw_text_centered(cx, cy, 4.8f * s, std::to_string(c),
|
? std::clamp(race_sim_.setup().deathmatch_kill_limit, 1, 99)
|
||||||
Vec4(1.0f, 1.0f, 1.0f, 1.0f), true, render::UiFont::Panel);
|
: std::clamp(race_sim_.setup().total_laps, 1, 99);
|
||||||
|
draw_panel(227, 128.0f, 94.0f);
|
||||||
|
draw_panel(139 + (cur_a / 10) % 10, 178.0f, 96.0f);
|
||||||
|
draw_panel(139 + (cur_a % 10), 192.0f, 96.0f);
|
||||||
|
draw_panel(150, 204.0f, 96.0f);
|
||||||
|
draw_panel(139 + (max_b / 10) % 10, 218.0f, 96.0f);
|
||||||
|
draw_panel(139 + (max_b % 10), 232.0f, 96.0f);
|
||||||
|
|
||||||
|
// 6. Top-Right Red Skull & Kills Counter (#228 + medium red digits #118..#127)
|
||||||
|
int kills_clamped = std::clamp(craft.kills, 0, 99);
|
||||||
|
draw_panel(228, 554.0f, 68.0f);
|
||||||
|
draw_panel(118 + (kills_clamped / 10) % 10, 586.0f, 68.0f);
|
||||||
|
draw_panel(118 + (kills_clamped % 10), 612.0f, 68.0f);
|
||||||
|
|
||||||
|
// 7. Recharging Hazard Banner (#198/#199) or Low-Resource Alert below upgrade bars
|
||||||
|
if (craft.active_recharge_mask != 0) {
|
||||||
|
int stripe_spr = (static_cast<int>(ui_time_ * 6.0) & 1) ? 198 : 199;
|
||||||
|
draw_panel(stripe_spr, 260.0f, 98.0f);
|
||||||
|
draw_panel(stripe_spr == 198 ? 199 : 198, 492.0f, 98.0f);
|
||||||
|
const char* rmsg = "RECHARGING";
|
||||||
|
Vec4 rcol(0.35f, 1.0f, 0.55f, 1.0f);
|
||||||
|
if (craft.active_recharge_mask & 1u) {
|
||||||
|
rmsg = "SHIELD CHARGING";
|
||||||
|
rcol = Vec4(0.35f, 1.0f, 0.55f, 1.0f);
|
||||||
|
} else if (craft.active_recharge_mask & 2u) {
|
||||||
|
rmsg = "FUEL CHARGING";
|
||||||
|
rcol = Vec4(0.42f, 0.85f, 1.0f, 1.0f);
|
||||||
|
} else if (craft.active_recharge_mask & 4u) {
|
||||||
|
rmsg = "AMMO CHARGING";
|
||||||
|
rcol = Vec4(1.0f, 0.90f, 0.25f, 1.0f);
|
||||||
|
}
|
||||||
|
ui_ren_.draw_text_centered_fit(ox + 401.0f * hs, oy + 99.0f * hs, 174.0f * hs, 1.15f * hs,
|
||||||
|
rmsg, rcol, true, render::UiFont::Panel);
|
||||||
|
} else if (cfg_.damage_enabled && shield_frac < 0.20f) {
|
||||||
|
if ((static_cast<int>(ui_time_ * 6.0) & 1) == 0) {
|
||||||
|
ui_ren_.draw_text_centered_fit(ox + 398.0f * hs, oy + 99.0f * hs, 220.0f * hs, 1.2f * hs,
|
||||||
|
"SHIELD LOW", Vec4(1.0f, 0.28f, 0.25f, 1.0f), true, render::UiFont::Panel);
|
||||||
|
}
|
||||||
|
} else if (cfg_.fuel_enabled && fuel_frac < 0.18f) {
|
||||||
|
if ((static_cast<int>(ui_time_ * 6.0) & 1) == 0) {
|
||||||
|
ui_ren_.draw_text_centered_fit(ox + 398.0f * hs, oy + 99.0f * hs, 220.0f * hs, 1.2f * hs,
|
||||||
|
"FUEL LOW", Vec4(1.0f, 0.65f, 0.2f, 1.0f), true, render::UiFont::Panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. Bottom-Left Compact Telemetry Card (Speed KPH using #151..#160 silver digits + TIME / BEST)
|
||||||
|
float pad = 14.0f * s;
|
||||||
|
float card_w = (split_view ? 206.0f : 232.0f) * s;
|
||||||
|
float card_h = (craft.best_lap_time > 0.0f) ? (80.0f * s) : (58.0f * s);
|
||||||
|
float card_x = static_cast<float>(vx) + pad;
|
||||||
|
float card_y = static_cast<float>(top_y + vh) - card_h - pad;
|
||||||
|
ui_ren_.draw_rect(card_x, card_y, card_w, card_h, Vec4(0.02f, 0.04f, 0.10f, 0.64f));
|
||||||
|
ui_ren_.draw_rect_outline(card_x, card_y, card_w, card_h, 2.0f, Vec4(0.28f, 0.68f, 1.0f, 0.78f));
|
||||||
|
|
||||||
|
int kmh = std::clamp(static_cast<int>(craft.speed_horizontal() * 14.5f), 0, 999);
|
||||||
|
float ds = (split_view ? 0.85f : 1.0f) * s;
|
||||||
|
ui_ren_.draw_bank_sprite("panel", 151 + (kmh / 100) % 10, card_x + 10.0f * s, card_y + 7.0f * s, ds);
|
||||||
|
ui_ren_.draw_bank_sprite("panel", 151 + (kmh / 10) % 10, card_x + 25.0f * s, card_y + 7.0f * s, ds);
|
||||||
|
ui_ren_.draw_bank_sprite("panel", 151 + (kmh % 10), card_x + 40.0f * s, card_y + 7.0f * s, ds);
|
||||||
|
ui_ren_.draw_text_fit(card_x + 60.0f * s, card_y + 9.0f * s, card_w - 68.0f * s, 1.65f * s,
|
||||||
|
"KPH", Vec4(0.75f, 0.90f, 1.0f, 1.0f), true, render::UiFont::MenuSmall);
|
||||||
|
std::string time_str = (craft.race_time > 0.0f) ? format_time(craft.race_time) : "00:00.00";
|
||||||
|
ui_ren_.draw_text_fit(card_x + 10.0f * s, card_y + 34.0f * s, card_w - 20.0f * s, 1.60f * s,
|
||||||
|
"TIME " + time_str, Vec4(0.92f, 0.97f, 1.0f, 1.0f),
|
||||||
|
true, render::UiFont::MenuSmall);
|
||||||
|
if (craft.best_lap_time > 0.0f) {
|
||||||
|
ui_ren_.draw_text_fit(card_x + 10.0f * s, card_y + 55.0f * s, card_w - 20.0f * s, 1.40f * s,
|
||||||
|
"BEST " + format_time(craft.best_lap_time), Vec4(0.42f, 1.0f, 0.65f, 1.0f),
|
||||||
|
true, render::UiFont::MenuSmall);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. Bottom-Right Minimap (kept completely clear of top visor gauges!)
|
||||||
|
if (show_minimap) {
|
||||||
|
float mm_size = (split_view ? 110.0f : 152.0f) * s;
|
||||||
|
render_minimap(craft, static_cast<float>(vx + vw) - mm_size - pad,
|
||||||
|
static_cast<float>(top_y + vh) - mm_size - pad, mm_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 10. Center Start Traffic Lights (#281..#286), Wrong-Way Warning & Banners
|
||||||
|
float cx = static_cast<float>(vx) + static_cast<float>(vw) * 0.5f;
|
||||||
|
float cy = oy + 126.0f * hs;
|
||||||
|
if (race_sim_.countdown_active() || (!race_sim_.countdown_active() && craft.race_time < 0.85f)) {
|
||||||
|
render_countdown_lights(cx, cy, hs);
|
||||||
} else if (craft.wrong_way) {
|
} else if (craft.wrong_way) {
|
||||||
ui_ren_.draw_text_centered_fit(cx, cy, static_cast<float>(vw) * 0.8f, 2.8f * s,
|
ui_ren_.draw_text_centered_fit(cx, cy + 28.0f * s, static_cast<float>(vw) * 0.75f, 2.6f * s,
|
||||||
str.wrong_way, Vec4(1.0f, 0.2f, 0.2f, 1.0f));
|
str.wrong_way, Vec4(1.0f, 0.22f, 0.20f, 1.0f), true, render::UiFont::MenuLarge);
|
||||||
} else {
|
} else {
|
||||||
int pi = (craft.player_index == 1) ? 1 : 0;
|
int pi = (craft.player_index == 1) ? 1 : 0;
|
||||||
if (hud_banner_timer_[pi] > 0.0f && !hud_banner_[pi].empty()) {
|
if (hud_banner_timer_[pi] > 0.0f && !hud_banner_[pi].empty()) {
|
||||||
ui_ren_.draw_text_centered_fit(cx, cy, static_cast<float>(vw) * 0.8f, 2.6f * s,
|
ui_ren_.draw_text_centered_fit(cx, cy + 26.0f * s, static_cast<float>(vw) * 0.75f, 2.4f * s,
|
||||||
hud_banner_[pi], Vec4(1.0f, 0.92f, 0.25f, 1.0f));
|
hud_banner_[pi], Vec4(1.0f, 0.92f, 0.25f, 1.0f),
|
||||||
|
true, render::UiFont::MenuLarge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameApp::render_countdown_lights(float cx, float ly, float hs) {
|
||||||
|
float ct = race_sim_.countdown_timer();
|
||||||
|
bool counting = race_sim_.countdown_active();
|
||||||
|
ui_ren_.draw_bank_sprite("panel", (counting && ct > 1.0f) ? 282 : 281, cx - 102.0f * hs, ly, hs);
|
||||||
|
ui_ren_.draw_bank_sprite("panel", (counting && ct <= 2.0f) ? 284 : 283, cx - 32.0f * hs, ly, hs);
|
||||||
|
ui_ren_.draw_bank_sprite("panel", (!counting) ? 286 : 285, cx + 38.0f * hs, ly, hs);
|
||||||
|
if (counting) {
|
||||||
|
int c = std::clamp(static_cast<int>(std::ceil(ct)), 1, 9);
|
||||||
|
ui_ren_.draw_bank_sprite("panel", 108 + c, cx - 25.0f * hs, ly + 36.0f * hs, hs);
|
||||||
|
} else {
|
||||||
|
ui_ren_.draw_text_centered(cx, ly + 42.0f * hs, 2.8f * hs, "GO!",
|
||||||
|
Vec4(0.35f, 1.0f, 0.45f, 1.0f), true, render::UiFont::MenuLarge);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GameApp::render_minimap(const sim::CraftState& focus, float mx, float my, float size) {
|
void GameApp::render_minimap(const sim::CraftState& focus, float mx, float my, float size) {
|
||||||
ui_ren_.draw_rect(mx, my, size, size, Vec4(0.02f, 0.04f, 0.09f, 0.72f));
|
ui_ren_.draw_rect(mx, my, size, size, Vec4(0.02f, 0.04f, 0.09f, 0.70f));
|
||||||
ui_ren_.draw_rect_outline(mx, my, size, size, 2.0f, Vec4(0.25f, 0.65f, 1.0f, 0.8f));
|
ui_ren_.draw_rect_outline(mx, my, size, size, 2.0f, Vec4(0.28f, 0.68f, 1.0f, 0.82f));
|
||||||
|
|
||||||
const auto& lvl = race_sim_.level();
|
const auto& lvl = race_sim_.level();
|
||||||
const auto& wps = lvl.main_waypoints;
|
const auto& wps = lvl.main_waypoints;
|
||||||
@@ -1373,7 +1701,7 @@ void GameApp::render_minimap(const sim::CraftState& focus, float mx, float my, f
|
|||||||
min_z = std::min(min_z, w.z); max_z = std::max(max_z, w.z);
|
min_z = std::min(min_z, w.z); max_z = std::max(max_z, w.z);
|
||||||
}
|
}
|
||||||
float span = std::max({max_x - min_x, max_z - min_z, 10.0f});
|
float span = std::max({max_x - min_x, max_z - min_z, 10.0f});
|
||||||
float pad = 12.0f;
|
float pad = size * 0.10f;
|
||||||
float scale = (size - 2.0f * pad) / span;
|
float scale = (size - 2.0f * pad) / span;
|
||||||
float ox = mx + (size - (max_x - min_x) * scale) * 0.5f;
|
float ox = mx + (size - (max_x - min_x) * scale) * 0.5f;
|
||||||
float oy = my + (size - (max_z - min_z) * scale) * 0.5f;
|
float oy = my + (size - (max_z - min_z) * scale) * 0.5f;
|
||||||
@@ -1382,20 +1710,53 @@ void GameApp::render_minimap(const sim::CraftState& focus, float mx, float my, f
|
|||||||
return Vec2(ox + (wx - min_x) * scale, oy + (wz - min_z) * scale);
|
return Vec2(ox + (wx - min_x) * scale, oy + (wz - min_z) * scale);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Dark outer casing + bright slate track ribbon
|
||||||
for (size_t i = 0; i < wps.size(); ++i) {
|
for (size_t i = 0; i < wps.size(); ++i) {
|
||||||
Vec2 p0 = to_mm(wps[i].x, wps[i].z);
|
Vec2 p0 = to_mm(wps[i].x, wps[i].z);
|
||||||
Vec2 p1 = to_mm(wps[(i + 1) % wps.size()].x, wps[(i + 1) % wps.size()].z);
|
Vec2 p1 = to_mm(wps[(i + 1) % wps.size()].x, wps[(i + 1) % wps.size()].z);
|
||||||
ui_ren_.draw_line(p0.x, p0.y, p1.x, p1.y, 2.0f, Vec4(0.45f, 0.6f, 0.75f, 0.9f));
|
ui_ren_.draw_line(p0.x, p0.y, p1.x, p1.y, 4.5f, Vec4(0.08f, 0.14f, 0.22f, 0.95f));
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < wps.size(); ++i) {
|
||||||
|
Vec2 p0 = to_mm(wps[i].x, wps[i].z);
|
||||||
|
Vec2 p1 = to_mm(wps[(i + 1) % wps.size()].x, wps[(i + 1) % wps.size()].z);
|
||||||
|
ui_ren_.draw_line(p0.x, p0.y, p1.x, p1.y, 2.2f, Vec4(0.50f, 0.70f, 0.88f, 0.95f));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& c : race_sim_.crafts()) {
|
// Start/finish orthogonal tick
|
||||||
Vec2 p = to_mm(c.curr_pose.pos.x, c.curr_pose.pos.z);
|
Vec2 sf0 = to_mm(wps[0].x, wps[0].z);
|
||||||
Vec4 dot_col = (c.id == focus.id) ? Vec4(1.0f, 0.9f, 0.1f, 1.0f)
|
Vec2 sf1 = to_mm(wps[1].x, wps[1].z);
|
||||||
: (c.is_human ? Vec4(0.2f, 1.0f, 0.4f, 1.0f)
|
Vec2 td = (sf1 - sf0).normalized();
|
||||||
: Vec4(1.0f, 0.3f, 0.3f, 1.0f));
|
Vec2 perp(-td.y, td.x);
|
||||||
float r = (c.id == focus.id) ? 3.5f : 2.5f;
|
ui_ren_.draw_line(sf0.x - perp.x * 5.0f, sf0.y - perp.y * 5.0f,
|
||||||
ui_ren_.draw_rect(p.x - r, p.y - r, r * 2.0f, r * 2.0f, dot_col);
|
sf0.x + perp.x * 5.0f, sf0.y + perp.y * 5.0f, 2.5f, Vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
|
||||||
|
// Pitstop bay markers (Shield emerald, Fuel cyan, Ammo gold)
|
||||||
|
for (const auto& cp : lvl.pads) {
|
||||||
|
Vec2 mp = to_mm(cp.cx, cp.cz);
|
||||||
|
Vec4 pc(0.25f, 0.72f, 1.0f, 0.95f);
|
||||||
|
if (cp.type == assets::ChargerType::Shield) pc = Vec4(0.20f, 1.0f, 0.45f, 0.95f);
|
||||||
|
else if (cp.type == assets::ChargerType::Ammo) pc = Vec4(1.0f, 0.85f, 0.22f, 0.95f);
|
||||||
|
ui_ren_.draw_rect(mp.x - 2.5f, mp.y - 2.5f, 5.0f, 5.0f, pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Opponent craft markers
|
||||||
|
for (const auto& c : race_sim_.crafts()) {
|
||||||
|
if (c.id == focus.id) continue;
|
||||||
|
Vec2 p = to_mm(c.curr_pose.pos.x, c.curr_pose.pos.z);
|
||||||
|
Vec4 dot_col = c.is_human ? Vec4(0.2f, 1.0f, 0.4f, 1.0f) : Vec4(1.0f, 0.3f, 0.28f, 1.0f);
|
||||||
|
ui_ren_.draw_rect(p.x - 2.5f, p.y - 2.5f, 5.0f, 5.0f, dot_col);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Focus craft directional heading chevron
|
||||||
|
Vec2 fp = to_mm(focus.curr_pose.pos.x, focus.curr_pose.pos.z);
|
||||||
|
Vec2 fwd(std::sin(focus.curr_pose.yaw), std::cos(focus.curr_pose.yaw));
|
||||||
|
Vec2 side(-fwd.y, fwd.x);
|
||||||
|
Vec2 tip = fp + fwd * 5.5f;
|
||||||
|
Vec2 bl = fp - fwd * 3.5f + side * 4.0f;
|
||||||
|
Vec2 br = fp - fwd * 3.5f - side * 4.0f;
|
||||||
|
ui_ren_.draw_line(tip.x, tip.y, bl.x, bl.y, 2.2f, Vec4(1.0f, 0.92f, 0.15f, 1.0f));
|
||||||
|
ui_ren_.draw_line(tip.x, tip.y, br.x, br.y, 2.2f, Vec4(1.0f, 0.92f, 0.15f, 1.0f));
|
||||||
|
ui_ren_.draw_line(bl.x, bl.y, br.x, br.y, 2.0f, Vec4(1.0f, 0.72f, 0.10f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameApp::render_menus() {
|
void GameApp::render_menus() {
|
||||||
|
|||||||
@@ -24,10 +24,12 @@ struct LaunchOptions {
|
|||||||
int start_track = 0; // 1..6 to jump straight into race
|
int start_track = 0; // 1..6 to jump straight into race
|
||||||
bool track_viewer = false;
|
bool track_viewer = false;
|
||||||
bool force_classic = false;
|
bool force_classic = false;
|
||||||
|
bool force_modern = false;
|
||||||
bool force_fullscreen = false;
|
bool force_fullscreen = false;
|
||||||
int force_backend = -1; // 0=opl3, 1=sf, 2=custom
|
int force_backend = -1; // 0=opl3, 1=sf, 2=custom
|
||||||
bool skip_intro = false;
|
bool skip_intro = false;
|
||||||
int smoke_test_frames = 0; // >0: run N real frames and exit cleanly
|
int smoke_test_frames = 0; // >0: run N real frames and exit cleanly
|
||||||
|
std::string screenshot_path; // optional PPM output on final smoke frame
|
||||||
};
|
};
|
||||||
|
|
||||||
class GameApp {
|
class GameApp {
|
||||||
@@ -74,6 +76,7 @@ private:
|
|||||||
void render_frame(float alpha);
|
void render_frame(float alpha);
|
||||||
void render_hud_viewport(const sim::CraftState& craft, const render::RenderCamera& cam,
|
void render_hud_viewport(const sim::CraftState& craft, const render::RenderCamera& cam,
|
||||||
int vx, int vy, int vw, int vh, bool show_minimap);
|
int vx, int vy, int vw, int vh, bool show_minimap);
|
||||||
|
void render_countdown_lights(float cx, float ly, float hs);
|
||||||
void render_minimap(const sim::CraftState& focus, float mx, float my, float size);
|
void render_minimap(const sim::CraftState& focus, float mx, float my, float size);
|
||||||
void render_menus();
|
void render_menus();
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ void print_usage(const char* argv0) {
|
|||||||
<< " --track <1..6> Launch straight into race on track 1..6\n"
|
<< " --track <1..6> Launch straight into race on track 1..6\n"
|
||||||
<< " --track-viewer <1..6> Open interactive 3D track viewer for track 1..6\n"
|
<< " --track-viewer <1..6> Open interactive 3D track viewer for track 1..6\n"
|
||||||
<< " --classic Start in 4:3 Classic palette visual mode\n"
|
<< " --classic Start in 4:3 Classic palette visual mode\n"
|
||||||
|
<< " --modern Start in Modern HDR lighting visual mode\n"
|
||||||
<< " --fullscreen Start in borderless fullscreen\n"
|
<< " --fullscreen Start in borderless fullscreen\n"
|
||||||
<< " --music-backend <opl3|sf|custom> Select music synth backend\n"
|
<< " --music-backend <opl3|sf|custom> Select music synth backend\n"
|
||||||
<< " --skip-intro Skip INTRO.DAT movie\n"
|
<< " --skip-intro Skip INTRO.DAT movie\n"
|
||||||
<< " --smoke-test <frames> Render N frames and exit cleanly\n"
|
<< " --smoke-test <frames> Render N frames and exit cleanly\n"
|
||||||
|
<< " --screenshot <path.ppm> Save final smoke frame as RGB PPM\n"
|
||||||
<< " --help Show this help\n";
|
<< " --help Show this help\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +42,8 @@ int main(int argc, char** argv) {
|
|||||||
opts.track_viewer = true;
|
opts.track_viewer = true;
|
||||||
} else if (std::strcmp(argv[i], "--classic") == 0) {
|
} else if (std::strcmp(argv[i], "--classic") == 0) {
|
||||||
opts.force_classic = true;
|
opts.force_classic = true;
|
||||||
|
} else if (std::strcmp(argv[i], "--modern") == 0) {
|
||||||
|
opts.force_modern = true;
|
||||||
} else if (std::strcmp(argv[i], "--fullscreen") == 0) {
|
} else if (std::strcmp(argv[i], "--fullscreen") == 0) {
|
||||||
opts.force_fullscreen = true;
|
opts.force_fullscreen = true;
|
||||||
} else if (std::strcmp(argv[i], "--music-backend") == 0 && i + 1 < argc) {
|
} else if (std::strcmp(argv[i], "--music-backend") == 0 && i + 1 < argc) {
|
||||||
@@ -51,6 +55,8 @@ int main(int argc, char** argv) {
|
|||||||
opts.skip_intro = true;
|
opts.skip_intro = true;
|
||||||
} else if (std::strcmp(argv[i], "--smoke-test") == 0 && i + 1 < argc) {
|
} else if (std::strcmp(argv[i], "--smoke-test") == 0 && i + 1 < argc) {
|
||||||
opts.smoke_test_frames = std::atoi(argv[++i]);
|
opts.smoke_test_frames = std::atoi(argv[++i]);
|
||||||
|
} else if (std::strcmp(argv[i], "--screenshot") == 0 && i + 1 < argc) {
|
||||||
|
opts.screenshot_path = argv[++i];
|
||||||
} else {
|
} else {
|
||||||
LOG_WARN("Unknown argument: %s", argv[i]);
|
LOG_WARN("Unknown argument: %s", argv[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ PFNGLUNIFORM1FPROC Uniform1f = nullptr;
|
|||||||
PFNGLUNIFORM2FPROC Uniform2f = nullptr;
|
PFNGLUNIFORM2FPROC Uniform2f = nullptr;
|
||||||
PFNGLUNIFORM3FPROC Uniform3f = nullptr;
|
PFNGLUNIFORM3FPROC Uniform3f = nullptr;
|
||||||
PFNGLUNIFORM4FPROC Uniform4f = nullptr;
|
PFNGLUNIFORM4FPROC Uniform4f = nullptr;
|
||||||
|
PFNGLUNIFORM3FVPROC Uniform3fv = nullptr;
|
||||||
|
PFNGLUNIFORM4FVPROC Uniform4fv = nullptr;
|
||||||
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv = nullptr;
|
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv = nullptr;
|
||||||
|
|
||||||
PFNGLGENFRAMEBUFFERSPROC GenFramebuffers = nullptr;
|
PFNGLGENFRAMEBUFFERSPROC GenFramebuffers = nullptr;
|
||||||
@@ -110,6 +112,8 @@ bool init() {
|
|||||||
ok &= load_fn(Uniform2f, "glUniform2f");
|
ok &= load_fn(Uniform2f, "glUniform2f");
|
||||||
ok &= load_fn(Uniform3f, "glUniform3f");
|
ok &= load_fn(Uniform3f, "glUniform3f");
|
||||||
ok &= load_fn(Uniform4f, "glUniform4f");
|
ok &= load_fn(Uniform4f, "glUniform4f");
|
||||||
|
ok &= load_fn(Uniform3fv, "glUniform3fv");
|
||||||
|
ok &= load_fn(Uniform4fv, "glUniform4fv");
|
||||||
ok &= load_fn(UniformMatrix4fv, "glUniformMatrix4fv");
|
ok &= load_fn(UniformMatrix4fv, "glUniformMatrix4fv");
|
||||||
|
|
||||||
ok &= load_fn(GenFramebuffers, "glGenFramebuffers");
|
ok &= load_fn(GenFramebuffers, "glGenFramebuffers");
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ extern PFNGLUNIFORM1FPROC Uniform1f;
|
|||||||
extern PFNGLUNIFORM2FPROC Uniform2f;
|
extern PFNGLUNIFORM2FPROC Uniform2f;
|
||||||
extern PFNGLUNIFORM3FPROC Uniform3f;
|
extern PFNGLUNIFORM3FPROC Uniform3f;
|
||||||
extern PFNGLUNIFORM4FPROC Uniform4f;
|
extern PFNGLUNIFORM4FPROC Uniform4f;
|
||||||
|
extern PFNGLUNIFORM3FVPROC Uniform3fv;
|
||||||
|
extern PFNGLUNIFORM4FVPROC Uniform4fv;
|
||||||
extern PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
|
extern PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
|
||||||
|
|
||||||
extern PFNGLGENFRAMEBUFFERSPROC GenFramebuffers;
|
extern PFNGLGENFRAMEBUFFERSPROC GenFramebuffers;
|
||||||
|
|||||||
@@ -101,6 +101,18 @@ void ShaderProgram::set_vec4(const char* name, const Vec4& v) const {
|
|||||||
if (loc >= 0) gl::Uniform4f(loc, v.x, v.y, v.z, v.w);
|
if (loc >= 0) gl::Uniform4f(loc, v.x, v.y, v.z, v.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShaderProgram::set_vec3_array(const char* name, const Vec3* vals, int count) const {
|
||||||
|
if (!vals || count <= 0) return;
|
||||||
|
GLint loc = gl::GetUniformLocation(program_, name);
|
||||||
|
if (loc >= 0) gl::Uniform3fv(loc, count, &vals[0].x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderProgram::set_vec4_array(const char* name, const Vec4* vals, int count) const {
|
||||||
|
if (!vals || count <= 0) return;
|
||||||
|
GLint loc = gl::GetUniformLocation(program_, name);
|
||||||
|
if (loc >= 0) gl::Uniform4fv(loc, count, &vals[0].x);
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderProgram::set_mat4(const char* name, const Mat4& m) const {
|
void ShaderProgram::set_mat4(const char* name, const Mat4& m) const {
|
||||||
GLint loc = gl::GetUniformLocation(program_, name);
|
GLint loc = gl::GetUniformLocation(program_, name);
|
||||||
if (loc >= 0) gl::UniformMatrix4fv(loc, 1, GL_FALSE, m.m);
|
if (loc >= 0) gl::UniformMatrix4fv(loc, 1, GL_FALSE, m.m);
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public:
|
|||||||
void set_vec2(const char* name, float x, float y) const;
|
void set_vec2(const char* name, float x, float y) const;
|
||||||
void set_vec3(const char* name, const Vec3& v) const;
|
void set_vec3(const char* name, const Vec3& v) const;
|
||||||
void set_vec4(const char* name, const Vec4& v) const;
|
void set_vec4(const char* name, const Vec4& v) const;
|
||||||
|
void set_vec3_array(const char* name, const Vec3* vals, int count) const;
|
||||||
|
void set_vec4_array(const char* name, const Vec4* vals, int count) const;
|
||||||
void set_mat4(const char* name, const Mat4& m) const;
|
void set_mat4(const char* name, const Mat4& m) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -35,6 +35,61 @@ inline void dihedral_uvs(uint8_t mod, float out_u[4], float out_v[4]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_block_at(const assets::LevelData& level, int x, int z, int slot) {
|
||||||
|
if (x < 0 || x >= assets::kMapWidth || z < 0 || z >= assets::kMapHeight || slot < 0 || slot >= 8) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const assets::MapEntry& m = level.cell(x, z);
|
||||||
|
if (m.tex_or_col >= 0) return false;
|
||||||
|
int cidx = -m.tex_or_col;
|
||||||
|
if (cidx <= 0 || cidx >= assets::kMaxColumns) return false;
|
||||||
|
return (level.columns[cidx].shape_mask & (1u << slot)) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float terrain_vertex_ao(const assets::LevelData& level, int vx, int vz) {
|
||||||
|
int solid_base = 0;
|
||||||
|
bool overpass = false;
|
||||||
|
for (int dz = -1; dz <= 0; ++dz) {
|
||||||
|
for (int dx = -1; dx <= 0; ++dx) {
|
||||||
|
int cx = vx + dx;
|
||||||
|
int cz = vz + dz;
|
||||||
|
if (cx < 0 || cx >= assets::kMapWidth || cz < 0 || cz >= assets::kMapHeight) continue;
|
||||||
|
const assets::MapEntry& m = level.cell(cx, cz);
|
||||||
|
if (m.tex_or_col >= 0) continue;
|
||||||
|
int cidx = -m.tex_or_col;
|
||||||
|
if (cidx <= 0 || cidx >= assets::kMaxColumns) continue;
|
||||||
|
uint16_t mask = level.columns[cidx].shape_mask;
|
||||||
|
if ((mask & 0x03u) != 0) {
|
||||||
|
++solid_base;
|
||||||
|
} else if ((mask & 0x3Cu) != 0) {
|
||||||
|
overpass = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float ao = 1.0f;
|
||||||
|
if (solid_base == 1) ao = 0.88f;
|
||||||
|
else if (solid_base == 2) ao = 0.79f;
|
||||||
|
else if (solid_base >= 3) ao = 0.72f;
|
||||||
|
if (overpass) ao *= 0.88f;
|
||||||
|
return std::clamp(ao, 0.70f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
float top_corner_ao(const assets::LevelData& level, int vx, int vz, int cell_x, int cell_z, int slot) {
|
||||||
|
if (slot + 1 >= 8) return 1.0f;
|
||||||
|
int higher = 0;
|
||||||
|
for (int dz = -1; dz <= 0; ++dz) {
|
||||||
|
for (int dx = -1; dx <= 0; ++dx) {
|
||||||
|
int nx = vx + dx;
|
||||||
|
int nz = vz + dz;
|
||||||
|
if (nx == cell_x && nz == cell_z) continue;
|
||||||
|
if (has_block_at(level, nx, nz, slot + 1)) ++higher;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (higher >= 2) return 0.85f;
|
||||||
|
if (higher == 1) return 0.92f;
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
void build_cell_quad(const assets::LevelData& level, int x, int z, WorldVertex out[4]) {
|
void build_cell_quad(const assets::LevelData& level, int x, int z, WorldVertex out[4]) {
|
||||||
const assets::MapEntry& m = level.cell(x, z);
|
const assets::MapEntry& m = level.cell(x, z);
|
||||||
int floor_tile = 0;
|
int floor_tile = 0;
|
||||||
@@ -61,31 +116,22 @@ void build_cell_quad(const assets::LevelData& level, int x, int z, WorldVertex o
|
|||||||
out[k].v = v[k];
|
out[k].v = v[k];
|
||||||
out[k].tile = static_cast<float>(floor_tile);
|
out[k].tile = static_cast<float>(floor_tile);
|
||||||
out[k].light = norm_light(vm.illumination);
|
out[k].light = norm_light(vm.illumination);
|
||||||
|
out[k].ao = terrain_vertex_ao(level, cx[k], cz[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_block_at(const assets::LevelData& level, int x, int z, int slot) {
|
|
||||||
if (x < 0 || x >= assets::kMapWidth || z < 0 || z >= assets::kMapHeight || slot < 0 || slot >= 8) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const assets::MapEntry& m = level.cell(x, z);
|
|
||||||
if (m.tex_or_col >= 0) return false;
|
|
||||||
int cidx = -m.tex_or_col;
|
|
||||||
if (cidx <= 0 || cidx >= assets::kMaxColumns) return false;
|
|
||||||
return (level.columns[cidx].shape_mask & (1u << slot)) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void emit_quad(std::vector<WorldVertex>& verts, std::vector<uint32_t>& indices,
|
void emit_quad(std::vector<WorldVertex>& verts, std::vector<uint32_t>& indices,
|
||||||
const Vec3& p0, const Vec3& p1, const Vec3& p2, const Vec3& p3,
|
const Vec3& p0, const Vec3& p1, const Vec3& p2, const Vec3& p3,
|
||||||
const Vec3& normal, uint8_t tex_id, uint8_t uv_mod, float light) {
|
const Vec3& normal, uint8_t tex_id, uint8_t uv_mod, float light,
|
||||||
|
float ao0, float ao1, float ao2, float ao3) {
|
||||||
float u[4], v[4];
|
float u[4], v[4];
|
||||||
dihedral_uvs(uv_mod, u, v);
|
dihedral_uvs(uv_mod, u, v);
|
||||||
uint32_t base = static_cast<uint32_t>(verts.size());
|
uint32_t base = static_cast<uint32_t>(verts.size());
|
||||||
float tile = static_cast<float>(tex_id);
|
float tile = static_cast<float>(tex_id);
|
||||||
verts.push_back({p0, normal, u[0], v[0], tile, light});
|
verts.push_back({p0, normal, u[0], v[0], tile, light, ao0});
|
||||||
verts.push_back({p1, normal, u[1], v[1], tile, light});
|
verts.push_back({p1, normal, u[1], v[1], tile, light, ao1});
|
||||||
verts.push_back({p2, normal, u[2], v[2], tile, light});
|
verts.push_back({p2, normal, u[2], v[2], tile, light, ao2});
|
||||||
verts.push_back({p3, normal, u[3], v[3], tile, light});
|
verts.push_back({p3, normal, u[3], v[3], tile, light, ao3});
|
||||||
// Counter-clockwise outward-facing winding matching declared normal
|
// Counter-clockwise outward-facing winding matching declared normal
|
||||||
indices.push_back(base + 0);
|
indices.push_back(base + 0);
|
||||||
indices.push_back(base + 3);
|
indices.push_back(base + 3);
|
||||||
@@ -160,34 +206,40 @@ void rebuild_column_geometry(const assets::LevelData& level,
|
|||||||
float sf = static_cast<float>(slot);
|
float sf = static_cast<float>(slot);
|
||||||
float b00 = h00 + sf, b10 = h10 + sf, b01 = h01 + sf, b11 = h11 + sf;
|
float b00 = h00 + sf, b10 = h10 + sf, b01 = h01 + sf, b11 = h11 + sf;
|
||||||
float t00 = b00 + 1.0f, t10 = b10 + 1.0f, t01 = b01 + 1.0f, t11 = b11 + 1.0f;
|
float t00 = b00 + 1.0f, t10 = b10 + 1.0f, t01 = b01 + 1.0f, t11 = b11 + 1.0f;
|
||||||
|
float bot_ao = (slot == 0) ? 0.83f
|
||||||
|
: (has_block_at(level, x, z, slot - 1) ? 0.96f : 0.90f);
|
||||||
|
|
||||||
// 0: North (-Z)
|
// 0: North (-Z)
|
||||||
if (!has_block_at(level, x, z - 1, slot)) {
|
if (!has_block_at(level, x, z - 1, slot)) {
|
||||||
emit_quad(column_verts, column_indices,
|
emit_quad(column_verts, column_indices,
|
||||||
Vec3(fx + 1, t10, fz), Vec3(fx, t00, fz),
|
Vec3(fx + 1, t10, fz), Vec3(fx, t00, fz),
|
||||||
Vec3(fx, b00, fz), Vec3(fx + 1, b10, fz),
|
Vec3(fx, b00, fz), Vec3(fx + 1, b10, fz),
|
||||||
Vec3(0, 0, -1), blk.tex[0], blk.attrs[0] & 7u, lgt * 0.90f);
|
Vec3(0, 0, -1), blk.tex[0], blk.attrs[0] & 7u, lgt * 0.90f,
|
||||||
|
1.0f, 1.0f, bot_ao, bot_ao);
|
||||||
}
|
}
|
||||||
// 1: East (+X)
|
// 1: East (+X)
|
||||||
if (!has_block_at(level, x + 1, z, slot)) {
|
if (!has_block_at(level, x + 1, z, slot)) {
|
||||||
emit_quad(column_verts, column_indices,
|
emit_quad(column_verts, column_indices,
|
||||||
Vec3(fx + 1, t11, fz + 1), Vec3(fx + 1, t10, fz),
|
Vec3(fx + 1, t11, fz + 1), Vec3(fx + 1, t10, fz),
|
||||||
Vec3(fx + 1, b10, fz), Vec3(fx + 1, b11, fz + 1),
|
Vec3(fx + 1, b10, fz), Vec3(fx + 1, b11, fz + 1),
|
||||||
Vec3(1, 0, 0), blk.tex[1], blk.attrs[1] & 7u, lgt * 0.85f);
|
Vec3(1, 0, 0), blk.tex[1], blk.attrs[1] & 7u, lgt * 0.85f,
|
||||||
|
1.0f, 1.0f, bot_ao, bot_ao);
|
||||||
}
|
}
|
||||||
// 2: South (+Z)
|
// 2: South (+Z)
|
||||||
if (!has_block_at(level, x, z + 1, slot)) {
|
if (!has_block_at(level, x, z + 1, slot)) {
|
||||||
emit_quad(column_verts, column_indices,
|
emit_quad(column_verts, column_indices,
|
||||||
Vec3(fx, t01, fz + 1), Vec3(fx + 1, t11, fz + 1),
|
Vec3(fx, t01, fz + 1), Vec3(fx + 1, t11, fz + 1),
|
||||||
Vec3(fx + 1, b11, fz + 1), Vec3(fx, b01, fz + 1),
|
Vec3(fx + 1, b11, fz + 1), Vec3(fx, b01, fz + 1),
|
||||||
Vec3(0, 0, 1), blk.tex[2], blk.attrs[2] & 7u, lgt * 0.95f);
|
Vec3(0, 0, 1), blk.tex[2], blk.attrs[2] & 7u, lgt * 0.95f,
|
||||||
|
1.0f, 1.0f, bot_ao, bot_ao);
|
||||||
}
|
}
|
||||||
// 3: West (-X)
|
// 3: West (-X)
|
||||||
if (!has_block_at(level, x - 1, z, slot)) {
|
if (!has_block_at(level, x - 1, z, slot)) {
|
||||||
emit_quad(column_verts, column_indices,
|
emit_quad(column_verts, column_indices,
|
||||||
Vec3(fx, t00, fz), Vec3(fx, t01, fz + 1),
|
Vec3(fx, t00, fz), Vec3(fx, t01, fz + 1),
|
||||||
Vec3(fx, b01, fz + 1), Vec3(fx, b00, fz),
|
Vec3(fx, b01, fz + 1), Vec3(fx, b00, fz),
|
||||||
Vec3(-1, 0, 0), blk.tex[3], blk.attrs[3] & 7u, lgt * 0.80f);
|
Vec3(-1, 0, 0), blk.tex[3], blk.attrs[3] & 7u, lgt * 0.80f,
|
||||||
|
1.0f, 1.0f, bot_ao, bot_ao);
|
||||||
}
|
}
|
||||||
// 4: Top (+Y)
|
// 4: Top (+Y)
|
||||||
if (!has_block_at(level, x, z, slot + 1)) {
|
if (!has_block_at(level, x, z, slot + 1)) {
|
||||||
@@ -197,7 +249,11 @@ void rebuild_column_geometry(const assets::LevelData& level,
|
|||||||
top_n = (top_n.len_sq() > 1e-6f) ? top_n.normalized() : Vec3(0, 1, 0);
|
top_n = (top_n.len_sq() > 1e-6f) ? top_n.normalized() : Vec3(0, 1, 0);
|
||||||
emit_quad(column_verts, column_indices,
|
emit_quad(column_verts, column_indices,
|
||||||
p0, p1, p2, p3,
|
p0, p1, p2, p3,
|
||||||
top_n, blk.tex[4], blk.attrs[4] & 7u, lgt * 1.05f);
|
top_n, blk.tex[4], blk.attrs[4] & 7u, lgt * 1.05f,
|
||||||
|
top_corner_ao(level, x, z, x, z, slot),
|
||||||
|
top_corner_ao(level, x + 1, z, x, z, slot),
|
||||||
|
top_corner_ao(level, x + 1, z + 1, x, z, slot),
|
||||||
|
top_corner_ao(level, x, z + 1, x, z, slot));
|
||||||
}
|
}
|
||||||
// 5: Bottom (-Y) - needed for elevated overpass/gantry blocks
|
// 5: Bottom (-Y) - needed for elevated overpass/gantry blocks
|
||||||
if (slot > 0 && !has_block_at(level, x, z, slot - 1)) {
|
if (slot > 0 && !has_block_at(level, x, z, slot - 1)) {
|
||||||
@@ -207,7 +263,8 @@ void rebuild_column_geometry(const assets::LevelData& level,
|
|||||||
bot_n = (bot_n.len_sq() > 1e-6f) ? bot_n.normalized() : Vec3(0, -1, 0);
|
bot_n = (bot_n.len_sq() > 1e-6f) ? bot_n.normalized() : Vec3(0, -1, 0);
|
||||||
emit_quad(column_verts, column_indices,
|
emit_quad(column_verts, column_indices,
|
||||||
p0, p1, p2, p3,
|
p0, p1, p2, p3,
|
||||||
bot_n, blk.tex[5], blk.attrs[5] & 7u, lgt * 0.70f);
|
bot_n, blk.tex[5], blk.attrs[5] & 7u, lgt * 0.70f,
|
||||||
|
0.85f, 0.85f, 0.85f, 0.85f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ struct WorldVertex {
|
|||||||
float v = 0.0f;
|
float v = 0.0f;
|
||||||
float tile = 0.0f;
|
float tile = 0.0f;
|
||||||
float light = 1.0f;
|
float light = 1.0f;
|
||||||
|
float ao = 1.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModelGpuVertex {
|
struct ModelGpuVertex {
|
||||||
|
|||||||
+627
-30
@@ -16,6 +16,7 @@ layout(location = 1) in vec3 aNormal;
|
|||||||
layout(location = 2) in vec2 aUv;
|
layout(location = 2) in vec2 aUv;
|
||||||
layout(location = 3) in float aTile;
|
layout(location = 3) in float aTile;
|
||||||
layout(location = 4) in float aLight;
|
layout(location = 4) in float aLight;
|
||||||
|
layout(location = 5) in float aAo;
|
||||||
|
|
||||||
uniform mat4 uViewProj;
|
uniform mat4 uViewProj;
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ out vec3 vNormal;
|
|||||||
out vec2 vUv;
|
out vec2 vUv;
|
||||||
out float vTile;
|
out float vTile;
|
||||||
out float vLight;
|
out float vLight;
|
||||||
|
out float vAo;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vWorldPos = aPos;
|
vWorldPos = aPos;
|
||||||
@@ -31,6 +33,7 @@ void main() {
|
|||||||
vUv = aUv;
|
vUv = aUv;
|
||||||
vTile = aTile;
|
vTile = aTile;
|
||||||
vLight = aLight;
|
vLight = aLight;
|
||||||
|
vAo = aAo;
|
||||||
gl_Position = uViewProj * vec4(aPos, 1.0);
|
gl_Position = uViewProj * vec4(aPos, 1.0);
|
||||||
}
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
@@ -42,25 +45,160 @@ in vec3 vNormal;
|
|||||||
in vec2 vUv;
|
in vec2 vUv;
|
||||||
in float vTile;
|
in float vTile;
|
||||||
in float vLight;
|
in float vLight;
|
||||||
|
in float vAo;
|
||||||
|
|
||||||
uniform sampler2DArray uTexArray;
|
uniform sampler2DArray uTexArray;
|
||||||
|
uniform sampler2D uShadowMap;
|
||||||
|
uniform mat4 uLightSpace;
|
||||||
uniform vec3 uCamPos;
|
uniform vec3 uCamPos;
|
||||||
uniform vec3 uFogColor;
|
uniform vec3 uFogColor;
|
||||||
uniform float uDrawDist;
|
uniform float uDrawDist;
|
||||||
|
uniform float uModernLighting;
|
||||||
|
uniform vec3 uSunDir;
|
||||||
|
uniform vec3 uSunColor;
|
||||||
|
uniform vec3 uSkyColor;
|
||||||
|
uniform vec3 uGroundColor;
|
||||||
|
uniform int uLightCount;
|
||||||
|
uniform vec4 uLightPosRad[12];
|
||||||
|
uniform vec4 uLightColInt[12];
|
||||||
|
uniform int uCraftShadowCount;
|
||||||
|
uniform vec4 uCraftShadows[10];
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
float sampleShadow(vec3 worldPos, vec3 N, float ndl) {
|
||||||
|
vec3 offsetPos = worldPos + N * 0.045;
|
||||||
|
vec4 ls = uLightSpace * vec4(offsetPos, 1.0);
|
||||||
|
vec3 proj = ls.xyz / max(ls.w, 1e-5);
|
||||||
|
proj = proj * 0.5 + 0.5;
|
||||||
|
if (proj.z >= 1.0 || proj.z <= 0.0 ||
|
||||||
|
proj.x <= 0.0 || proj.x >= 1.0 ||
|
||||||
|
proj.y <= 0.0 || proj.y >= 1.0) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
float bias = max(0.0007, 0.0020 * (1.0 - ndl));
|
||||||
|
vec2 texelSize = 1.0 / vec2(textureSize(uShadowMap, 0));
|
||||||
|
float vis = 0.0;
|
||||||
|
for (int x = -1; x <= 1; ++x) {
|
||||||
|
for (int y = -1; y <= 1; ++y) {
|
||||||
|
float d = texture(uShadowMap, proj.xy + vec2(x, y) * texelSize).r;
|
||||||
|
vis += (proj.z - bias > d) ? 0.0 : 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vis /= 9.0;
|
||||||
|
vec2 edge = abs(proj.xy * 2.0 - 1.0);
|
||||||
|
float borderFade = smoothstep(0.84, 0.98, max(edge.x, edge.y));
|
||||||
|
return mix(vis, 1.0, borderFade);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 softTone(vec3 c) {
|
||||||
|
// Preserve linear shadow/midtone contrast for visibility, gently roll off bright peaks > 0.80
|
||||||
|
vec3 lo = min(c, vec3(0.80));
|
||||||
|
vec3 hi = max(c - vec3(0.80), vec3(0.0));
|
||||||
|
return clamp(lo + hi / (vec3(1.0) + hi * 5.0), 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 texel = texture(uTexArray, vec3(vUv, floor(vTile + 0.5)));
|
vec4 texel = texture(uTexArray, vec3(vUv, floor(vTile + 0.5)));
|
||||||
vec3 sunDir = normalize(vec3(0.45, 0.80, 0.38));
|
vec3 sunDir = normalize(uModernLighting > 0.5 ? uSunDir : vec3(0.45, 0.80, 0.38));
|
||||||
float ndl = clamp(dot(normalize(vNormal), sunDir), 0.0, 1.0);
|
vec3 N = normalize(vNormal);
|
||||||
float shade = vLight * (0.72 + 0.35 * ndl);
|
|
||||||
vec3 lit = texel.rgb * shade;
|
|
||||||
|
|
||||||
float dist = length(vWorldPos - uCamPos);
|
float dist = length(vWorldPos - uCamPos);
|
||||||
float fogStart = uDrawDist * 0.45;
|
float fogStart = uDrawDist * 0.45;
|
||||||
float fogFactor = clamp((dist - fogStart) / max(uDrawDist - fogStart, 1.0), 0.0, 1.0);
|
float fogFactor = clamp((dist - fogStart) / max(uDrawDist - fogStart, 1.0), 0.0, 1.0);
|
||||||
vec3 finalRgb = mix(lit, uFogColor, fogFactor * fogFactor);
|
float fog2 = fogFactor * fogFactor;
|
||||||
|
|
||||||
|
if (uModernLighting < 0.5) {
|
||||||
|
float ndl = clamp(dot(N, sunDir), 0.0, 1.0);
|
||||||
|
float shade = vLight * (0.72 + 0.35 * ndl);
|
||||||
|
vec3 lit = texel.rgb * shade;
|
||||||
|
vec3 finalRgb = mix(lit, uFogColor, fog2);
|
||||||
|
FragColor = vec4(clamp(finalRgb, 0.0, 1.0), 1.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subtle derivative micro-relief so track asphalt & girders catch grazing light cleanly
|
||||||
|
float luma = dot(texel.rgb, vec3(0.299, 0.587, 0.114));
|
||||||
|
vec3 dpdx = dFdx(vWorldPos);
|
||||||
|
vec3 dpdy = dFdy(vWorldPos);
|
||||||
|
float dhx = dFdx(luma);
|
||||||
|
float dhy = dFdy(luma);
|
||||||
|
vec3 surfGrad = cross(dpdy, N) * dhx + cross(N, dpdx) * dhy;
|
||||||
|
float det = dot(dpdx, cross(dpdy, N));
|
||||||
|
if (abs(det) > 1e-6) {
|
||||||
|
float bumpFade = 1.0 - smoothstep(10.0, 34.0, dist);
|
||||||
|
vec3 bumpN = normalize(N - surfGrad * (0.45 / max(abs(det), 0.02)) * bumpFade);
|
||||||
|
N = normalize(mix(N, bumpN, 0.32 * bumpFade));
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 V = normalize(uCamPos - vWorldPos);
|
||||||
|
float ndl = max(dot(N, sunDir), 0.0);
|
||||||
|
float shadow = sampleShadow(vWorldPos, normalize(vNormal), ndl);
|
||||||
|
float sunVis = mix(0.32, 1.0, shadow);
|
||||||
|
|
||||||
|
// Soft hovercraft contact shadow projected onto upward-facing road/deck surfaces
|
||||||
|
float craftShadow = 1.0;
|
||||||
|
if (N.y > 0.30 && uCraftShadowCount > 0) {
|
||||||
|
for (int i = 0; i < uCraftShadowCount; ++i) {
|
||||||
|
vec4 cs = uCraftShadows[i];
|
||||||
|
float dy = cs.y - vWorldPos.y;
|
||||||
|
if (dy >= -0.25 && dy <= 3.2) {
|
||||||
|
vec2 d = vWorldPos.xz - cs.xz;
|
||||||
|
float r2 = dot(d, d);
|
||||||
|
float rad = cs.w * (1.0 + max(dy, 0.0) * 0.25);
|
||||||
|
if (r2 < rad * rad) {
|
||||||
|
float dlen = sqrt(r2);
|
||||||
|
float radial = 1.0 - smoothstep(rad * 0.22, rad, dlen);
|
||||||
|
float hfade = 1.0 - clamp((max(dy, 0.0) - 0.30) / 2.6, 0.0, 1.0);
|
||||||
|
craftShadow = min(craftShadow, 1.0 - 0.38 * radial * hfade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float aoTerm = mix(0.70, 1.0, vAo);
|
||||||
|
vec3 hemi = mix(uGroundColor, uSkyColor, N.y * 0.5 + 0.5) * 0.52 * aoTerm * vLight;
|
||||||
|
vec3 direct = uSunColor * (0.72 * ndl * sunVis * mix(0.78, 1.0, vAo) * vLight);
|
||||||
|
|
||||||
|
// Specular sheen + grazing Fresnel reflection weighted by tile smoothness/brightness
|
||||||
|
vec3 H = normalize(sunDir + V);
|
||||||
|
float roughBias = mix(0.18, 0.55, smoothstep(0.15, 0.85, luma));
|
||||||
|
float spec = pow(max(dot(N, H), 0.0), 34.0) * (0.20 * roughBias) * sunVis;
|
||||||
|
float fres = pow(1.0 - max(dot(N, V), 0.0), 4.0) * 0.14 * roughBias * mix(0.55, 1.0, sunVis);
|
||||||
|
|
||||||
|
// Subtle emissive lift on vivid track signage, pitstop bays & city lights
|
||||||
|
float maxc = max(texel.r, max(texel.g, texel.b));
|
||||||
|
float minc = min(texel.r, min(texel.g, texel.b));
|
||||||
|
float glowMask = smoothstep(0.55, 0.92, maxc) * smoothstep(0.24, 0.58, maxc - minc);
|
||||||
|
vec3 emissive = texel.rgb * glowMask * 0.26;
|
||||||
|
|
||||||
|
// Dynamic point lights (explosions, missiles, booster thrusters, pitstop bays)
|
||||||
|
vec3 dynLight = vec3(0.0);
|
||||||
|
for (int i = 0; i < uLightCount; ++i) {
|
||||||
|
vec4 pr = uLightPosRad[i];
|
||||||
|
vec4 ci = uLightColInt[i];
|
||||||
|
vec3 Lvec = pr.xyz - vWorldPos;
|
||||||
|
float d2 = dot(Lvec, Lvec);
|
||||||
|
float r2 = pr.w * pr.w;
|
||||||
|
if (d2 < r2) {
|
||||||
|
float d = sqrt(max(d2, 1e-6));
|
||||||
|
vec3 L = Lvec / d;
|
||||||
|
float q = 1.0 - d2 / r2;
|
||||||
|
float atten = q * q * ci.w;
|
||||||
|
float wrapNdl = clamp(dot(N, L) * 0.65 + 0.35, 0.0, 1.0);
|
||||||
|
dynLight += ci.rgb * (atten * wrapNdl * 0.90);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 lit = texel.rgb * ((hemi + direct) * craftShadow + dynLight)
|
||||||
|
+ (uSunColor * spec + uSkyColor * fres) * craftShadow
|
||||||
|
+ emissive;
|
||||||
|
|
||||||
|
// Aerial perspective: subtle solar forward-scattering warmth in distance fog
|
||||||
|
vec3 viewDir = normalize(vWorldPos - uCamPos);
|
||||||
|
float sunAlign = pow(max(dot(viewDir, sunDir), 0.0), 4.0);
|
||||||
|
vec3 fogRgb = mix(uFogColor, mix(uFogColor, uSunColor * 0.85, 0.30), sunAlign);
|
||||||
|
vec3 finalRgb = mix(softTone(lit), fogRgb, fog2);
|
||||||
FragColor = vec4(clamp(finalRgb, 0.0, 1.0), 1.0);
|
FragColor = vec4(clamp(finalRgb, 0.0, 1.0), 1.0);
|
||||||
}
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
@@ -106,14 +244,56 @@ in float vTextured;
|
|||||||
in float vShade;
|
in float vShade;
|
||||||
|
|
||||||
uniform sampler2D uAtlas;
|
uniform sampler2D uAtlas;
|
||||||
|
uniform sampler2D uShadowMap;
|
||||||
|
uniform mat4 uLightSpace;
|
||||||
uniform vec4 uTint;
|
uniform vec4 uTint;
|
||||||
uniform vec3 uCamPos;
|
uniform vec3 uCamPos;
|
||||||
uniform vec3 uFogColor;
|
uniform vec3 uFogColor;
|
||||||
uniform float uDrawDist;
|
uniform float uDrawDist;
|
||||||
uniform float uEnableFog;
|
uniform float uEnableFog;
|
||||||
|
uniform float uModernLighting;
|
||||||
|
uniform float uUseShadowMap;
|
||||||
|
uniform vec3 uSunDir;
|
||||||
|
uniform vec3 uSunColor;
|
||||||
|
uniform vec3 uSkyColor;
|
||||||
|
uniform vec3 uGroundColor;
|
||||||
|
uniform int uLightCount;
|
||||||
|
uniform vec4 uLightPosRad[12];
|
||||||
|
uniform vec4 uLightColInt[12];
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
|
float sampleModelShadow(vec3 worldPos, vec3 N, float ndl) {
|
||||||
|
vec3 offsetPos = worldPos + N * 0.035;
|
||||||
|
vec4 ls = uLightSpace * vec4(offsetPos, 1.0);
|
||||||
|
vec3 proj = ls.xyz / max(ls.w, 1e-5);
|
||||||
|
proj = proj * 0.5 + 0.5;
|
||||||
|
if (proj.z >= 1.0 || proj.z <= 0.0 ||
|
||||||
|
proj.x <= 0.0 || proj.x >= 1.0 ||
|
||||||
|
proj.y <= 0.0 || proj.y >= 1.0) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
float bias = max(0.0008, 0.0022 * (1.0 - ndl));
|
||||||
|
vec2 texelSize = 1.0 / vec2(textureSize(uShadowMap, 0));
|
||||||
|
float vis = 0.0;
|
||||||
|
for (int x = -1; x <= 1; ++x) {
|
||||||
|
for (int y = -1; y <= 1; ++y) {
|
||||||
|
float d = texture(uShadowMap, proj.xy + vec2(x, y) * texelSize).r;
|
||||||
|
vis += (proj.z - bias > d) ? 0.0 : 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vis /= 9.0;
|
||||||
|
vec2 edge = abs(proj.xy * 2.0 - 1.0);
|
||||||
|
float borderFade = smoothstep(0.84, 0.98, max(edge.x, edge.y));
|
||||||
|
return mix(vis, 1.0, borderFade);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 softToneModel(vec3 c) {
|
||||||
|
vec3 lo = min(c, vec3(0.82));
|
||||||
|
vec3 hi = max(c - vec3(0.82), vec3(0.0));
|
||||||
|
return clamp(lo + hi / (vec3(1.0) + hi * 5.5556), 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 base = vColor;
|
vec4 base = vColor;
|
||||||
if (vTextured > 0.5) {
|
if (vTextured > 0.5) {
|
||||||
@@ -121,11 +301,14 @@ void main() {
|
|||||||
if (t.a < 0.1) discard;
|
if (t.a < 0.1) discard;
|
||||||
base = t;
|
base = t;
|
||||||
}
|
}
|
||||||
|
vec3 N = normalize(vNormal);
|
||||||
|
if (!gl_FrontFacing) N = -N;
|
||||||
|
|
||||||
|
if (uModernLighting < 0.5) {
|
||||||
vec3 sunDir = normalize(vec3(0.45, 0.80, 0.38));
|
vec3 sunDir = normalize(vec3(0.45, 0.80, 0.38));
|
||||||
float ndl = abs(dot(normalize(vNormal), sunDir));
|
float ndl = abs(dot(N, sunDir));
|
||||||
float shade = vShade * (0.68 + 0.42 * ndl);
|
float shade = vShade * (0.68 + 0.42 * ndl);
|
||||||
vec3 rgb = base.rgb * shade * uTint.rgb;
|
vec3 rgb = base.rgb * shade * uTint.rgb;
|
||||||
|
|
||||||
if (uEnableFog > 0.5) {
|
if (uEnableFog > 0.5) {
|
||||||
float dist = length(vWorldPos - uCamPos);
|
float dist = length(vWorldPos - uCamPos);
|
||||||
float fogStart = uDrawDist * 0.45;
|
float fogStart = uDrawDist * 0.45;
|
||||||
@@ -133,6 +316,61 @@ void main() {
|
|||||||
rgb = mix(rgb, uFogColor, fogFactor * fogFactor);
|
rgb = mix(rgb, uFogColor, fogFactor * fogFactor);
|
||||||
}
|
}
|
||||||
FragColor = vec4(clamp(rgb, 0.0, 1.0), base.a * uTint.a);
|
FragColor = vec4(clamp(rgb, 0.0, 1.0), base.a * uTint.a);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 sunDir = normalize(uSunDir);
|
||||||
|
vec3 V = normalize(uCamPos - vWorldPos);
|
||||||
|
float ndl = max(dot(N, sunDir), 0.0);
|
||||||
|
float shadow = (uUseShadowMap > 0.5) ? sampleModelShadow(vWorldPos, N, ndl) : 1.0;
|
||||||
|
float sunVis = mix(0.35, 1.0, shadow);
|
||||||
|
|
||||||
|
vec3 hemi = mix(uGroundColor, uSkyColor, N.y * 0.5 + 0.5) * 0.56 * vShade;
|
||||||
|
vec3 direct = uSunColor * (0.76 * ndl * sunVis * vShade);
|
||||||
|
|
||||||
|
// Metallic dual-lobe clear-coat specular + crisp sky Fresnel rim
|
||||||
|
vec3 H = normalize(sunDir + V);
|
||||||
|
float ndh = max(dot(N, H), 0.0);
|
||||||
|
float spec = (pow(ndh, 24.0) * 0.24 + pow(ndh, 96.0) * 0.28) * sunVis;
|
||||||
|
float rim = pow(1.0 - max(dot(N, V), 0.0), 3.0) * 0.30;
|
||||||
|
|
||||||
|
vec3 dynDiff = vec3(0.0);
|
||||||
|
vec3 dynSpec = vec3(0.0);
|
||||||
|
for (int i = 0; i < uLightCount; ++i) {
|
||||||
|
vec4 pr = uLightPosRad[i];
|
||||||
|
vec4 ci = uLightColInt[i];
|
||||||
|
vec3 Lvec = pr.xyz - vWorldPos;
|
||||||
|
float d2 = dot(Lvec, Lvec);
|
||||||
|
float r2 = pr.w * pr.w;
|
||||||
|
if (d2 < r2) {
|
||||||
|
float d = sqrt(max(d2, 1e-6));
|
||||||
|
vec3 L = Lvec / d;
|
||||||
|
float q = 1.0 - d2 / r2;
|
||||||
|
float atten = q * q * ci.w;
|
||||||
|
float wrapNdl = clamp(dot(N, L) * 0.65 + 0.35, 0.0, 1.0);
|
||||||
|
vec3 hL = normalize(L + V);
|
||||||
|
float sL = pow(max(dot(N, hL), 0.0), 32.0) * 0.35;
|
||||||
|
dynDiff += ci.rgb * (atten * wrapNdl * 0.90);
|
||||||
|
dynSpec += ci.rgb * (atten * sL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 rgb = base.rgb * uTint.rgb * (hemi + direct + dynDiff)
|
||||||
|
+ uSunColor * spec
|
||||||
|
+ mix(uSkyColor, vec3(1.0), 0.35) * rim
|
||||||
|
+ dynSpec;
|
||||||
|
rgb = softToneModel(rgb);
|
||||||
|
|
||||||
|
if (uEnableFog > 0.5) {
|
||||||
|
float dist = length(vWorldPos - uCamPos);
|
||||||
|
float fogStart = uDrawDist * 0.45;
|
||||||
|
float fogFactor = clamp((dist - fogStart) / max(uDrawDist - fogStart, 1.0), 0.0, 1.0);
|
||||||
|
vec3 viewDir = normalize(vWorldPos - uCamPos);
|
||||||
|
float sunAlign = pow(max(dot(viewDir, sunDir), 0.0), 4.0);
|
||||||
|
vec3 fogRgb = mix(uFogColor, mix(uFogColor, uSunColor * 0.85, 0.30), sunAlign);
|
||||||
|
rgb = mix(rgb, fogRgb, fogFactor * fogFactor);
|
||||||
|
}
|
||||||
|
FragColor = vec4(clamp(rgb, 0.0, 1.0), base.a * uTint.a);
|
||||||
}
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
|
|
||||||
@@ -143,9 +381,11 @@ layout(location = 1) in vec2 aUv;
|
|||||||
|
|
||||||
uniform mat4 uViewProjNoTrans;
|
uniform mat4 uViewProjNoTrans;
|
||||||
out vec2 vUv;
|
out vec2 vUv;
|
||||||
|
out vec3 vDir;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vUv = aUv;
|
vUv = aUv;
|
||||||
|
vDir = aPos;
|
||||||
vec4 p = uViewProjNoTrans * vec4(aPos, 1.0);
|
vec4 p = uViewProjNoTrans * vec4(aPos, 1.0);
|
||||||
gl_Position = p.xyww;
|
gl_Position = p.xyww;
|
||||||
}
|
}
|
||||||
@@ -154,31 +394,88 @@ void main() {
|
|||||||
constexpr const char* kSkyFS = R"glsl(
|
constexpr const char* kSkyFS = R"glsl(
|
||||||
#version 330 core
|
#version 330 core
|
||||||
in vec2 vUv;
|
in vec2 vUv;
|
||||||
|
in vec3 vDir;
|
||||||
uniform sampler2D uSkyTex;
|
uniform sampler2D uSkyTex;
|
||||||
uniform vec3 uFogColor;
|
uniform vec3 uFogColor;
|
||||||
|
uniform vec3 uSunDir;
|
||||||
|
uniform vec3 uSunColor;
|
||||||
|
uniform float uModernLighting;
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 sky = texture(uSkyTex, vUv).rgb;
|
vec3 sky = texture(uSkyTex, vUv).rgb;
|
||||||
|
if (uModernLighting > 0.5) {
|
||||||
|
vec3 d = normalize(vDir);
|
||||||
|
vec3 s = normalize(uSunDir);
|
||||||
|
float mu = max(dot(d, s), 0.0);
|
||||||
|
float halo = pow(mu, 20.0) * 0.14 + pow(mu, 160.0) * 0.30;
|
||||||
|
float horizGlow = exp(-abs(d.y) * 5.0) * 0.05 * (0.4 + 0.6 * pow(mu, 2.0));
|
||||||
|
sky = clamp(sky + uSunColor * (halo + horizGlow), 0.0, 1.0);
|
||||||
|
}
|
||||||
// Preserve clouds/mountains (v = 0.59..0.91) and blend smoothly into fog at the horizon
|
// Preserve clouds/mountains (v = 0.59..0.91) and blend smoothly into fog at the horizon
|
||||||
float hBlend = smoothstep(0.91, 0.968, vUv.y);
|
float hBlend = smoothstep(0.91, 0.968, vUv.y);
|
||||||
FragColor = vec4(mix(sky, uFogColor, hBlend), 1.0);
|
FragColor = vec4(mix(sky, uFogColor, hBlend), 1.0);
|
||||||
}
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
|
|
||||||
|
constexpr const char* kShadowWorldVS = R"glsl(
|
||||||
|
#version 330 core
|
||||||
|
layout(location = 0) in vec3 aPos;
|
||||||
|
uniform mat4 uLightSpace;
|
||||||
|
void main() {
|
||||||
|
gl_Position = uLightSpace * vec4(aPos, 1.0);
|
||||||
|
}
|
||||||
|
)glsl";
|
||||||
|
|
||||||
|
constexpr const char* kShadowWorldFS = R"glsl(
|
||||||
|
#version 330 core
|
||||||
|
void main() {}
|
||||||
|
)glsl";
|
||||||
|
|
||||||
|
constexpr const char* kShadowModelVS = R"glsl(
|
||||||
|
#version 330 core
|
||||||
|
layout(location = 0) in vec3 aPos;
|
||||||
|
layout(location = 2) in vec2 aUv;
|
||||||
|
layout(location = 4) in float aTextured;
|
||||||
|
uniform mat4 uModel;
|
||||||
|
uniform mat4 uLightSpace;
|
||||||
|
out vec2 vUv;
|
||||||
|
out float vTextured;
|
||||||
|
void main() {
|
||||||
|
vUv = aUv;
|
||||||
|
vTextured = aTextured;
|
||||||
|
gl_Position = uLightSpace * uModel * vec4(aPos, 1.0);
|
||||||
|
}
|
||||||
|
)glsl";
|
||||||
|
|
||||||
|
constexpr const char* kShadowModelFS = R"glsl(
|
||||||
|
#version 330 core
|
||||||
|
in vec2 vUv;
|
||||||
|
in float vTextured;
|
||||||
|
uniform sampler2D uAtlas;
|
||||||
|
void main() {
|
||||||
|
if (vTextured > 0.5 && texture(uAtlas, vUv).a < 0.1) discard;
|
||||||
|
}
|
||||||
|
)glsl";
|
||||||
|
|
||||||
constexpr const char* kParticleVS = R"glsl(
|
constexpr const char* kParticleVS = R"glsl(
|
||||||
#version 330 core
|
#version 330 core
|
||||||
layout(location = 0) in vec3 aPos;
|
layout(location = 0) in vec3 aPos;
|
||||||
layout(location = 1) in vec2 aUv;
|
layout(location = 1) in vec2 aUv;
|
||||||
layout(location = 2) in vec4 aColor;
|
layout(location = 2) in vec4 aColor;
|
||||||
|
layout(location = 3) in vec2 aParams;
|
||||||
|
|
||||||
uniform mat4 uViewProj;
|
uniform mat4 uViewProj;
|
||||||
out vec2 vUv;
|
out vec2 vUv;
|
||||||
out vec4 vColor;
|
out vec4 vColor;
|
||||||
|
out vec2 vParams;
|
||||||
|
out vec3 vWorldPos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vUv = aUv;
|
vUv = aUv;
|
||||||
vColor = aColor;
|
vColor = aColor;
|
||||||
|
vParams = aParams;
|
||||||
|
vWorldPos = aPos;
|
||||||
gl_Position = uViewProj * vec4(aPos, 1.0);
|
gl_Position = uViewProj * vec4(aPos, 1.0);
|
||||||
}
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
@@ -187,14 +484,67 @@ constexpr const char* kParticleFS = R"glsl(
|
|||||||
#version 330 core
|
#version 330 core
|
||||||
in vec2 vUv;
|
in vec2 vUv;
|
||||||
in vec4 vColor;
|
in vec4 vColor;
|
||||||
|
in vec2 vParams;
|
||||||
|
in vec3 vWorldPos;
|
||||||
|
|
||||||
|
uniform vec3 uCamPos;
|
||||||
|
uniform vec3 uFogColor;
|
||||||
|
uniform float uDrawDist;
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 d = vUv * 2.0 - 1.0;
|
vec2 d = vUv * 2.0 - 1.0;
|
||||||
float r = dot(d, d);
|
float r2 = dot(d, d);
|
||||||
if (r > 1.0) discard;
|
float style = vParams.x;
|
||||||
float alpha = (1.0 - r) * vColor.a;
|
float seed = vParams.y;
|
||||||
FragColor = vec4(vColor.rgb, alpha);
|
|
||||||
|
float dist = length(vWorldPos - uCamPos);
|
||||||
|
float fogStart = uDrawDist * 0.45;
|
||||||
|
float fogFactor = clamp((dist - fogStart) / max(uDrawDist - fogStart, 1.0), 0.0, 1.0);
|
||||||
|
float fog2 = fogFactor * fogFactor;
|
||||||
|
float nearFade = smoothstep(0.75, 2.35, dist);
|
||||||
|
|
||||||
|
if (style < 0.5) {
|
||||||
|
if (r2 > 1.0) discard;
|
||||||
|
float a = (1.0 - r2) * vColor.a * (1.0 - fog2) * nearFade;
|
||||||
|
FragColor = vec4(vColor.rgb, a);
|
||||||
|
} else if (style < 1.5) {
|
||||||
|
float ang = atan(d.y, d.x) + seed * 6.28318;
|
||||||
|
float warp = 0.16 * sin(ang * 5.0 + seed * 12.0) + 0.10 * cos(ang * 3.0 - seed * 9.0);
|
||||||
|
float lenD = length(d);
|
||||||
|
float rr = lenD * (1.0 + warp);
|
||||||
|
if (rr > 1.0) discard;
|
||||||
|
float core = pow(max(0.0, 1.0 - rr * rr), 1.45);
|
||||||
|
float hot = pow(max(0.0, 1.0 - rr), 2.6);
|
||||||
|
vec3 col = mix(vColor.rgb, vec3(1.0, 0.98, 0.86), hot * 0.65);
|
||||||
|
float a = core * vColor.a * (1.0 - fog2) * nearFade;
|
||||||
|
FragColor = vec4(col, a);
|
||||||
|
} else if (style < 2.5) {
|
||||||
|
float a0 = seed * 6.28318;
|
||||||
|
float dens = max(0.0, 1.0 - r2 / 0.52);
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
float fi = float(i);
|
||||||
|
float ang = a0 + fi * 1.570796 + 0.35 * sin(seed * 17.0 + fi * 2.1);
|
||||||
|
vec2 off = vec2(cos(ang), sin(ang)) * (0.28 + 0.10 * cos(seed * 11.0 + fi));
|
||||||
|
vec2 q = d - off;
|
||||||
|
float rad2 = 0.44 + 0.08 * sin(seed * 13.0 + fi * 3.0);
|
||||||
|
dens = max(dens, max(0.0, 1.0 - dot(q, q) / rad2));
|
||||||
|
}
|
||||||
|
if (dens < 0.04) discard;
|
||||||
|
float soft = smoothstep(0.04, 0.72, dens);
|
||||||
|
float topLight = 0.72 + 0.34 * clamp(d.y * 0.8 + 0.3, 0.0, 1.0);
|
||||||
|
vec3 smokeRgb = mix(vColor.rgb * topLight, uFogColor, fog2);
|
||||||
|
FragColor = vec4(smokeRgb, soft * vColor.a * nearFade);
|
||||||
|
} else {
|
||||||
|
float ang = seed * 6.28318;
|
||||||
|
float ca = cos(ang);
|
||||||
|
float sa = sin(ang);
|
||||||
|
vec2 rd = vec2(d.x * ca - d.y * sa, d.x * sa + d.y * ca);
|
||||||
|
if (abs(rd.x) > 0.65 || abs(rd.y) > 0.38) discard;
|
||||||
|
vec3 debRgb = mix(vColor.rgb * (0.75 + 0.35 * rd.y), uFogColor, fog2);
|
||||||
|
FragColor = vec4(debRgb, vColor.a * nearFade);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
|
|
||||||
@@ -240,6 +590,14 @@ void main() {
|
|||||||
}
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
|
|
||||||
|
Mat4 build_model_matrix(const ModelInstance& inst) {
|
||||||
|
return Mat4::translate(inst.pos) *
|
||||||
|
Mat4::rotate_y(inst.yaw) *
|
||||||
|
Mat4::rotate_x(inst.pitch) *
|
||||||
|
Mat4::rotate_z(inst.roll) *
|
||||||
|
Mat4::scale(Vec3(inst.scale, inst.scale, inst.scale));
|
||||||
|
}
|
||||||
|
|
||||||
void set_world_vertex_attribs() {
|
void set_world_vertex_attribs() {
|
||||||
gl::EnableVertexAttribArray(0);
|
gl::EnableVertexAttribArray(0);
|
||||||
gl::VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(WorldVertex),
|
gl::VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(WorldVertex),
|
||||||
@@ -256,6 +614,9 @@ void set_world_vertex_attribs() {
|
|||||||
gl::EnableVertexAttribArray(4);
|
gl::EnableVertexAttribArray(4);
|
||||||
gl::VertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, sizeof(WorldVertex),
|
gl::VertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, sizeof(WorldVertex),
|
||||||
reinterpret_cast<void*>(offsetof(WorldVertex, light)));
|
reinterpret_cast<void*>(offsetof(WorldVertex, light)));
|
||||||
|
gl::EnableVertexAttribArray(5);
|
||||||
|
gl::VertexAttribPointer(5, 1, GL_FLOAT, GL_FALSE, sizeof(WorldVertex),
|
||||||
|
reinterpret_cast<void*>(offsetof(WorldVertex, ao)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -264,6 +625,62 @@ WorldRenderer::~WorldRenderer() {
|
|||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WorldRenderer::WorldLightingTheme WorldRenderer::theme_for_world(int world_idx) {
|
||||||
|
switch (std::clamp(world_idx, 0, 5)) {
|
||||||
|
case 0: // Amazon Delta Turnpike
|
||||||
|
return {Vec3(0.46f, 0.78f, 0.42f).normalized(),
|
||||||
|
Vec3(1.06f, 0.99f, 0.87f), Vec3(0.72f, 0.88f, 1.04f), Vec3(0.42f, 0.46f, 0.36f)};
|
||||||
|
case 1: // Trans-Asia Interstate
|
||||||
|
return {Vec3(0.50f, 0.76f, 0.40f).normalized(),
|
||||||
|
Vec3(1.08f, 0.97f, 0.84f), Vec3(0.75f, 0.86f, 1.02f), Vec3(0.44f, 0.40f, 0.34f)};
|
||||||
|
case 2: // Shanghai Dragon
|
||||||
|
return {Vec3(0.42f, 0.80f, 0.42f).normalized(),
|
||||||
|
Vec3(1.02f, 0.98f, 0.94f), Vec3(0.70f, 0.82f, 1.04f), Vec3(0.38f, 0.40f, 0.46f)};
|
||||||
|
case 3: // New Chernobyl Central
|
||||||
|
return {Vec3(0.48f, 0.74f, 0.47f).normalized(),
|
||||||
|
Vec3(1.06f, 0.95f, 0.82f), Vec3(0.74f, 0.82f, 0.94f), Vec3(0.40f, 0.38f, 0.34f)};
|
||||||
|
case 4: // Slam Canyon
|
||||||
|
return {Vec3(0.52f, 0.76f, 0.39f).normalized(),
|
||||||
|
Vec3(1.10f, 0.98f, 0.84f), Vec3(0.72f, 0.86f, 1.02f), Vec3(0.50f, 0.40f, 0.32f)};
|
||||||
|
default: // Thrak City
|
||||||
|
return {Vec3(0.44f, 0.79f, 0.43f).normalized(),
|
||||||
|
Vec3(1.02f, 0.97f, 0.95f), Vec3(0.68f, 0.80f, 1.05f), Vec3(0.38f, 0.38f, 0.48f)};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WorldRenderer::init_shadow_map() {
|
||||||
|
if (shadow_fbo_) return true;
|
||||||
|
|
||||||
|
glGenTextures(1, &shadow_depth_tex_);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, shadow_depth_tex_);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, kShadowMapSize, kShadowMapSize, 0,
|
||||||
|
GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||||
|
static constexpr float kBorder[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
|
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, kBorder);
|
||||||
|
|
||||||
|
gl::GenFramebuffers(1, &shadow_fbo_);
|
||||||
|
gl::BindFramebuffer(GL_FRAMEBUFFER, shadow_fbo_);
|
||||||
|
gl::FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadow_depth_tex_, 0);
|
||||||
|
glDrawBuffer(GL_NONE);
|
||||||
|
glReadBuffer(GL_NONE);
|
||||||
|
GLenum status = gl::CheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||||
|
gl::BindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
|
LOG_WARN("Shadow map FBO incomplete (0x%x); continuing without real-time shadows", status);
|
||||||
|
gl::DeleteFramebuffers(1, &shadow_fbo_);
|
||||||
|
glDeleteTextures(1, &shadow_depth_tex_);
|
||||||
|
shadow_fbo_ = 0;
|
||||||
|
shadow_depth_tex_ = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool WorldRenderer::init(const Vfs& vfs, const assets::Palette& pal) {
|
bool WorldRenderer::init(const Vfs& vfs, const assets::Palette& pal) {
|
||||||
if (initialized_) return true;
|
if (initialized_) return true;
|
||||||
if (!gl::is_loaded()) {
|
if (!gl::is_loaded()) {
|
||||||
@@ -275,9 +692,12 @@ bool WorldRenderer::init(const Vfs& vfs, const assets::Palette& pal) {
|
|||||||
!model_shader_.build(kModelVS, kModelFS, "model") ||
|
!model_shader_.build(kModelVS, kModelFS, "model") ||
|
||||||
!sky_shader_.build(kSkyVS, kSkyFS, "sky") ||
|
!sky_shader_.build(kSkyVS, kSkyFS, "sky") ||
|
||||||
!particle_shader_.build(kParticleVS, kParticleFS, "particle") ||
|
!particle_shader_.build(kParticleVS, kParticleFS, "particle") ||
|
||||||
!classic_shader_.build(kClassicVS, kClassicFS, "classic")) {
|
!classic_shader_.build(kClassicVS, kClassicFS, "classic") ||
|
||||||
|
!shadow_world_shader_.build(kShadowWorldVS, kShadowWorldFS, "shadow_world") ||
|
||||||
|
!shadow_model_shader_.build(kShadowModelVS, kShadowModelFS, "shadow_model")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
init_shadow_map();
|
||||||
|
|
||||||
if (!obj_atlas_.load(vfs, pal)) {
|
if (!obj_atlas_.load(vfs, pal)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -385,20 +805,23 @@ bool WorldRenderer::init(const Vfs& vfs, const assets::Palette& pal) {
|
|||||||
gl::VertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
gl::VertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||||
reinterpret_cast<void*>(2 * sizeof(float)));
|
reinterpret_cast<void*>(2 * sizeof(float)));
|
||||||
|
|
||||||
// Dynamic particle stream VAO/VBO
|
// Dynamic particle stream VAO/VBO (pos3 + uv2 + color4 + params2 = 11 floats)
|
||||||
gl::GenVertexArrays(1, &part_vao_);
|
gl::GenVertexArrays(1, &part_vao_);
|
||||||
gl::GenBuffers(1, &part_vbo_);
|
gl::GenBuffers(1, &part_vbo_);
|
||||||
gl::BindVertexArray(part_vao_);
|
gl::BindVertexArray(part_vao_);
|
||||||
gl::BindBuffer(GL_ARRAY_BUFFER, part_vbo_);
|
gl::BindBuffer(GL_ARRAY_BUFFER, part_vbo_);
|
||||||
gl::BufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);
|
gl::BufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);
|
||||||
gl::EnableVertexAttribArray(0);
|
gl::EnableVertexAttribArray(0);
|
||||||
gl::VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), nullptr);
|
gl::VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 11 * sizeof(float), nullptr);
|
||||||
gl::EnableVertexAttribArray(1);
|
gl::EnableVertexAttribArray(1);
|
||||||
gl::VertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 9 * sizeof(float),
|
gl::VertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 11 * sizeof(float),
|
||||||
reinterpret_cast<void*>(3 * sizeof(float)));
|
reinterpret_cast<void*>(3 * sizeof(float)));
|
||||||
gl::EnableVertexAttribArray(2);
|
gl::EnableVertexAttribArray(2);
|
||||||
gl::VertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 9 * sizeof(float),
|
gl::VertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 11 * sizeof(float),
|
||||||
reinterpret_cast<void*>(5 * sizeof(float)));
|
reinterpret_cast<void*>(5 * sizeof(float)));
|
||||||
|
gl::EnableVertexAttribArray(3);
|
||||||
|
gl::VertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 11 * sizeof(float),
|
||||||
|
reinterpret_cast<void*>(9 * sizeof(float)));
|
||||||
|
|
||||||
gl::BindVertexArray(0);
|
gl::BindVertexArray(0);
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
@@ -423,15 +846,18 @@ void WorldRenderer::shutdown() {
|
|||||||
if (part_vbo_) gl::DeleteBuffers(1, &part_vbo_);
|
if (part_vbo_) gl::DeleteBuffers(1, &part_vbo_);
|
||||||
if (classic_fbo_) gl::DeleteFramebuffers(1, &classic_fbo_);
|
if (classic_fbo_) gl::DeleteFramebuffers(1, &classic_fbo_);
|
||||||
if (classic_depth_rbo_) gl::DeleteRenderbuffers(1, &classic_depth_rbo_);
|
if (classic_depth_rbo_) gl::DeleteRenderbuffers(1, &classic_depth_rbo_);
|
||||||
|
if (shadow_fbo_) gl::DeleteFramebuffers(1, &shadow_fbo_);
|
||||||
}
|
}
|
||||||
if (tex_terrain_array_) glDeleteTextures(1, &tex_terrain_array_);
|
if (tex_terrain_array_) glDeleteTextures(1, &tex_terrain_array_);
|
||||||
if (tex_sky_) glDeleteTextures(1, &tex_sky_);
|
if (tex_sky_) glDeleteTextures(1, &tex_sky_);
|
||||||
if (tex_obj_atlas_) glDeleteTextures(1, &tex_obj_atlas_);
|
if (tex_obj_atlas_) glDeleteTextures(1, &tex_obj_atlas_);
|
||||||
if (tex_palette_) glDeleteTextures(1, &tex_palette_);
|
if (tex_palette_) glDeleteTextures(1, &tex_palette_);
|
||||||
if (classic_color_tex_) glDeleteTextures(1, &classic_color_tex_);
|
if (classic_color_tex_) glDeleteTextures(1, &classic_color_tex_);
|
||||||
|
if (shadow_depth_tex_) glDeleteTextures(1, &shadow_depth_tex_);
|
||||||
|
|
||||||
sky_vao_ = sky_vbo_ = quad_vao_ = quad_vbo_ = part_vao_ = part_vbo_ = 0;
|
sky_vao_ = sky_vbo_ = quad_vao_ = quad_vbo_ = part_vao_ = part_vbo_ = 0;
|
||||||
classic_fbo_ = classic_depth_rbo_ = classic_color_tex_ = 0;
|
classic_fbo_ = classic_depth_rbo_ = classic_color_tex_ = 0;
|
||||||
|
shadow_fbo_ = shadow_depth_tex_ = 0;
|
||||||
tex_terrain_array_ = tex_sky_ = tex_obj_atlas_ = tex_palette_ = 0;
|
tex_terrain_array_ = tex_sky_ = tex_obj_atlas_ = tex_palette_ = 0;
|
||||||
classic_w_ = classic_h_ = 0;
|
classic_w_ = classic_h_ = 0;
|
||||||
|
|
||||||
@@ -440,6 +866,8 @@ void WorldRenderer::shutdown() {
|
|||||||
sky_shader_.destroy();
|
sky_shader_.destroy();
|
||||||
particle_shader_.destroy();
|
particle_shader_.destroy();
|
||||||
classic_shader_.destroy();
|
classic_shader_.destroy();
|
||||||
|
shadow_world_shader_.destroy();
|
||||||
|
shadow_model_shader_.destroy();
|
||||||
initialized_ = false;
|
initialized_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,6 +913,7 @@ bool WorldRenderer::load_level(const Vfs& vfs, const assets::LevelData& level,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fog_color_ = color_tables_.fog_color;
|
fog_color_ = color_tables_.fog_color;
|
||||||
|
current_world_index_ = std::clamp(level.world_index, 0, 5);
|
||||||
|
|
||||||
// Upload 256 x 64 x 64 terrain texture array
|
// Upload 256 x 64 x 64 terrain texture array
|
||||||
if (tex_terrain_array_) glDeleteTextures(1, &tex_terrain_array_);
|
if (tex_terrain_array_) glDeleteTextures(1, &tex_terrain_array_);
|
||||||
@@ -691,9 +1120,73 @@ void WorldRenderer::begin_frame(int backbuffer_w, int backbuffer_h, const GameCo
|
|||||||
|
|
||||||
void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector<ModelInstance>& models,
|
void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector<ModelInstance>& models,
|
||||||
const std::vector<ParticleQuad>& particles,
|
const std::vector<ParticleQuad>& particles,
|
||||||
int viewport_index, int split_count, const GameConfig& cfg) {
|
int viewport_index, int split_count, const GameConfig& cfg,
|
||||||
|
const std::vector<DynamicLight>& lights,
|
||||||
|
const std::vector<CraftShadow>& craft_shadows) {
|
||||||
int target_w = cfg.classic_mode ? classic_w_ : backbuffer_w_;
|
int target_w = cfg.classic_mode ? classic_w_ : backbuffer_w_;
|
||||||
int target_h = cfg.classic_mode ? classic_h_ : backbuffer_h_;
|
int target_h = cfg.classic_mode ? classic_h_ : backbuffer_h_;
|
||||||
|
const bool modern = !cfg.classic_mode;
|
||||||
|
const WorldLightingTheme theme = theme_for_world(current_world_index_);
|
||||||
|
|
||||||
|
// 0. Directional Shadow Map Pass (Modern Mode only)
|
||||||
|
Mat4 light_space = Mat4::identity();
|
||||||
|
const bool use_shadows = modern && shadow_fbo_ != 0 && shadow_depth_tex_ != 0;
|
||||||
|
if (use_shadows) {
|
||||||
|
constexpr float kOrthoRadius = 36.0f;
|
||||||
|
const float texel_w = (2.0f * kOrthoRadius) / static_cast<float>(kShadowMapSize);
|
||||||
|
Vec3 light_dir = theme.sun_dir.normalized();
|
||||||
|
Vec3 up = (std::abs(light_dir.y) > 0.98f) ? Vec3(0.0f, 0.0f, 1.0f) : Vec3(0.0f, 1.0f, 0.0f);
|
||||||
|
Vec3 f_dir = (-light_dir).normalized();
|
||||||
|
Vec3 s_dir = f_dir.cross(up).normalized();
|
||||||
|
Vec3 u_dir = s_dir.cross(f_dir);
|
||||||
|
float sx = std::floor(cam.target.dot(s_dir) / texel_w) * texel_w;
|
||||||
|
float sy = std::floor(cam.target.dot(u_dir) / texel_w) * texel_w;
|
||||||
|
float sz = cam.target.dot(f_dir);
|
||||||
|
Vec3 focus = s_dir * sx + u_dir * sy + f_dir * sz;
|
||||||
|
|
||||||
|
Mat4 light_view = Mat4::look_at(focus + light_dir * 52.0f, focus, up);
|
||||||
|
Mat4 light_proj = Mat4::ortho(-kOrthoRadius, kOrthoRadius, -kOrthoRadius, kOrthoRadius, 1.0f, 120.0f);
|
||||||
|
light_space = light_proj * light_view;
|
||||||
|
|
||||||
|
gl::BindFramebuffer(GL_FRAMEBUFFER, shadow_fbo_);
|
||||||
|
glViewport(0, 0, kShadowMapSize, kShadowMapSize);
|
||||||
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LESS);
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
glPolygonOffset(1.8f, 3.5f);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
|
shadow_world_shader_.use();
|
||||||
|
shadow_world_shader_.set_mat4("uLightSpace", light_space);
|
||||||
|
if (terrain_mesh_.vao && terrain_mesh_.index_count > 0) {
|
||||||
|
gl::BindVertexArray(terrain_mesh_.vao);
|
||||||
|
glDrawElements(GL_TRIANGLES, terrain_mesh_.index_count, GL_UNSIGNED_INT, nullptr);
|
||||||
|
}
|
||||||
|
if (column_mesh_.vao && column_mesh_.index_count > 0) {
|
||||||
|
gl::BindVertexArray(column_mesh_.vao);
|
||||||
|
glDrawElements(GL_TRIANGLES, column_mesh_.index_count, GL_UNSIGNED_INT, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
shadow_model_shader_.use();
|
||||||
|
shadow_model_shader_.set_mat4("uLightSpace", light_space);
|
||||||
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_obj_atlas_);
|
||||||
|
shadow_model_shader_.set_int("uAtlas", 0);
|
||||||
|
for (const auto& inst : models) {
|
||||||
|
if (inst.tint.w < 0.99f) continue;
|
||||||
|
auto it = model_cache_.find(inst.model_key);
|
||||||
|
if (it == model_cache_.end() || !it->second.vao) continue;
|
||||||
|
shadow_model_shader_.set_mat4("uModel", build_model_matrix(inst));
|
||||||
|
gl::BindVertexArray(it->second.vao);
|
||||||
|
glDrawElements(GL_TRIANGLES, it->second.index_count, GL_UNSIGNED_INT, nullptr);
|
||||||
|
}
|
||||||
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
}
|
||||||
|
|
||||||
if (cfg.classic_mode) {
|
if (cfg.classic_mode) {
|
||||||
gl::BindFramebuffer(GL_FRAMEBUFFER, classic_fbo_);
|
gl::BindFramebuffer(GL_FRAMEBUFFER, classic_fbo_);
|
||||||
} else {
|
} else {
|
||||||
@@ -720,6 +1213,25 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
|
|||||||
Mat4 view = Mat4::look_at(cam.eye, cam.target, cam.up);
|
Mat4 view = Mat4::look_at(cam.eye, cam.target, cam.up);
|
||||||
Mat4 view_proj = proj * view;
|
Mat4 view_proj = proj * view;
|
||||||
|
|
||||||
|
// Pack dynamic lights (up to 12) and craft contact shadows (up to 10)
|
||||||
|
constexpr int kMaxLights = 12;
|
||||||
|
constexpr int kMaxCraftShadows = 10;
|
||||||
|
int light_count = modern ? std::min(static_cast<int>(lights.size()), kMaxLights) : 0;
|
||||||
|
Vec4 light_pos_rad[kMaxLights]{};
|
||||||
|
Vec4 light_col_int[kMaxLights]{};
|
||||||
|
for (int i = 0; i < light_count; ++i) {
|
||||||
|
light_pos_rad[i] = Vec4(lights[i].pos.x, lights[i].pos.y, lights[i].pos.z,
|
||||||
|
std::max(lights[i].radius, 0.25f));
|
||||||
|
light_col_int[i] = Vec4(lights[i].color.x, lights[i].color.y, lights[i].color.z,
|
||||||
|
std::max(lights[i].intensity, 0.0f));
|
||||||
|
}
|
||||||
|
int cshadow_count = modern ? std::min(static_cast<int>(craft_shadows.size()), kMaxCraftShadows) : 0;
|
||||||
|
Vec4 cshadow_spheres[kMaxCraftShadows]{};
|
||||||
|
for (int i = 0; i < cshadow_count; ++i) {
|
||||||
|
cshadow_spheres[i] = Vec4(craft_shadows[i].pos.x, craft_shadows[i].pos.y,
|
||||||
|
craft_shadows[i].pos.z, std::max(craft_shadows[i].radius, 0.25f));
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Cylindrical Skybox (no translation, depth <= 1.0)
|
// 1. Cylindrical Skybox (no translation, depth <= 1.0)
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
@@ -731,6 +1243,9 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
|
|||||||
sky_shader_.use();
|
sky_shader_.use();
|
||||||
sky_shader_.set_mat4("uViewProjNoTrans", proj * view_no_trans);
|
sky_shader_.set_mat4("uViewProjNoTrans", proj * view_no_trans);
|
||||||
sky_shader_.set_vec3("uFogColor", fog_color_);
|
sky_shader_.set_vec3("uFogColor", fog_color_);
|
||||||
|
sky_shader_.set_vec3("uSunDir", theme.sun_dir);
|
||||||
|
sky_shader_.set_vec3("uSunColor", theme.sun_color);
|
||||||
|
sky_shader_.set_float("uModernLighting", modern ? 1.0f : 0.0f);
|
||||||
gl::ActiveTexture(GL_TEXTURE0);
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex_sky_);
|
glBindTexture(GL_TEXTURE_2D, tex_sky_);
|
||||||
sky_shader_.set_int("uSkyTex", 0);
|
sky_shader_.set_int("uSkyTex", 0);
|
||||||
@@ -746,12 +1261,33 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
|
|||||||
|
|
||||||
world_shader_.use();
|
world_shader_.use();
|
||||||
world_shader_.set_mat4("uViewProj", view_proj);
|
world_shader_.set_mat4("uViewProj", view_proj);
|
||||||
|
world_shader_.set_mat4("uLightSpace", light_space);
|
||||||
world_shader_.set_vec3("uCamPos", cam.eye);
|
world_shader_.set_vec3("uCamPos", cam.eye);
|
||||||
world_shader_.set_vec3("uFogColor", fog_color_);
|
world_shader_.set_vec3("uFogColor", fog_color_);
|
||||||
world_shader_.set_float("uDrawDist", draw_dist);
|
world_shader_.set_float("uDrawDist", draw_dist);
|
||||||
|
world_shader_.set_float("uModernLighting", modern ? 1.0f : 0.0f);
|
||||||
|
world_shader_.set_vec3("uSunDir", theme.sun_dir);
|
||||||
|
world_shader_.set_vec3("uSunColor", theme.sun_color);
|
||||||
|
world_shader_.set_vec3("uSkyColor", theme.sky_color);
|
||||||
|
world_shader_.set_vec3("uGroundColor", theme.ground_color);
|
||||||
|
world_shader_.set_int("uLightCount", light_count);
|
||||||
|
if (light_count > 0) {
|
||||||
|
world_shader_.set_vec4_array("uLightPosRad", light_pos_rad, light_count);
|
||||||
|
world_shader_.set_vec4_array("uLightColInt", light_col_int, light_count);
|
||||||
|
}
|
||||||
|
world_shader_.set_int("uCraftShadowCount", cshadow_count);
|
||||||
|
if (cshadow_count > 0) {
|
||||||
|
world_shader_.set_vec4_array("uCraftShadows", cshadow_spheres, cshadow_count);
|
||||||
|
}
|
||||||
gl::ActiveTexture(GL_TEXTURE0);
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, tex_terrain_array_);
|
glBindTexture(GL_TEXTURE_2D_ARRAY, tex_terrain_array_);
|
||||||
world_shader_.set_int("uTexArray", 0);
|
world_shader_.set_int("uTexArray", 0);
|
||||||
|
world_shader_.set_int("uShadowMap", 1);
|
||||||
|
if (shadow_depth_tex_) {
|
||||||
|
gl::ActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, shadow_depth_tex_);
|
||||||
|
}
|
||||||
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
if (terrain_mesh_.vao && terrain_mesh_.index_count > 0) {
|
if (terrain_mesh_.vao && terrain_mesh_.index_count > 0) {
|
||||||
gl::BindVertexArray(terrain_mesh_.vao);
|
gl::BindVertexArray(terrain_mesh_.vao);
|
||||||
@@ -766,23 +1302,36 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
|
|||||||
glDisable(GL_CULL_FACE); // Bullfrog models mix face windings on thin fins/wings
|
glDisable(GL_CULL_FACE); // Bullfrog models mix face windings on thin fins/wings
|
||||||
model_shader_.use();
|
model_shader_.use();
|
||||||
model_shader_.set_mat4("uViewProj", view_proj);
|
model_shader_.set_mat4("uViewProj", view_proj);
|
||||||
|
model_shader_.set_mat4("uLightSpace", light_space);
|
||||||
model_shader_.set_vec3("uCamPos", cam.eye);
|
model_shader_.set_vec3("uCamPos", cam.eye);
|
||||||
model_shader_.set_vec3("uFogColor", fog_color_);
|
model_shader_.set_vec3("uFogColor", fog_color_);
|
||||||
model_shader_.set_float("uDrawDist", draw_dist);
|
model_shader_.set_float("uDrawDist", draw_dist);
|
||||||
model_shader_.set_float("uEnableFog", 1.0f);
|
model_shader_.set_float("uEnableFog", 1.0f);
|
||||||
|
model_shader_.set_float("uModernLighting", modern ? 1.0f : 0.0f);
|
||||||
|
model_shader_.set_float("uUseShadowMap", use_shadows ? 1.0f : 0.0f);
|
||||||
|
model_shader_.set_vec3("uSunDir", theme.sun_dir);
|
||||||
|
model_shader_.set_vec3("uSunColor", theme.sun_color);
|
||||||
|
model_shader_.set_vec3("uSkyColor", theme.sky_color);
|
||||||
|
model_shader_.set_vec3("uGroundColor", theme.ground_color);
|
||||||
|
model_shader_.set_int("uLightCount", light_count);
|
||||||
|
if (light_count > 0) {
|
||||||
|
model_shader_.set_vec4_array("uLightPosRad", light_pos_rad, light_count);
|
||||||
|
model_shader_.set_vec4_array("uLightColInt", light_col_int, light_count);
|
||||||
|
}
|
||||||
gl::ActiveTexture(GL_TEXTURE0);
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex_obj_atlas_);
|
glBindTexture(GL_TEXTURE_2D, tex_obj_atlas_);
|
||||||
model_shader_.set_int("uAtlas", 0);
|
model_shader_.set_int("uAtlas", 0);
|
||||||
|
model_shader_.set_int("uShadowMap", 1);
|
||||||
|
if (shadow_depth_tex_) {
|
||||||
|
gl::ActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, shadow_depth_tex_);
|
||||||
|
}
|
||||||
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
auto draw_model = [&](const ModelInstance& inst) {
|
auto draw_model = [&](const ModelInstance& inst) {
|
||||||
auto it = model_cache_.find(inst.model_key);
|
auto it = model_cache_.find(inst.model_key);
|
||||||
if (it == model_cache_.end() || !it->second.vao) return;
|
if (it == model_cache_.end() || !it->second.vao) return;
|
||||||
Mat4 model = Mat4::translate(inst.pos) *
|
model_shader_.set_mat4("uModel", build_model_matrix(inst));
|
||||||
Mat4::rotate_y(inst.yaw) *
|
|
||||||
Mat4::rotate_x(inst.pitch) *
|
|
||||||
Mat4::rotate_z(inst.roll) *
|
|
||||||
Mat4::scale(Vec3(inst.scale, inst.scale, inst.scale));
|
|
||||||
model_shader_.set_mat4("uModel", model);
|
|
||||||
model_shader_.set_vec4("uTint", inst.tint);
|
model_shader_.set_vec4("uTint", inst.tint);
|
||||||
gl::BindVertexArray(it->second.vao);
|
gl::BindVertexArray(it->second.vao);
|
||||||
glDrawElements(GL_TRIANGLES, it->second.index_count, GL_UNSIGNED_INT, nullptr);
|
glDrawElements(GL_TRIANGLES, it->second.index_count, GL_UNSIGNED_INT, nullptr);
|
||||||
@@ -798,15 +1347,34 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
|
|||||||
if (inst.tint.w < 0.99f) draw_model(inst);
|
if (inst.tint.w < 0.99f) draw_model(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Particles / Explosions / Booster Flames / Minigun Tracers (additive)
|
// 4. Particles: volumetric alpha-blended smoke/debris (back-to-front), then additive fireballs/glows
|
||||||
if (!particles.empty() && part_vao_) {
|
if (!particles.empty() && part_vao_) {
|
||||||
// Extract camera right & up vectors from view matrix
|
// Extract camera right & up vectors from view matrix
|
||||||
Vec3 cam_right(view.m[0], view.m[4], view.m[8]);
|
Vec3 cam_right(view.m[0], view.m[4], view.m[8]);
|
||||||
Vec3 cam_up(view.m[1], view.m[5], view.m[9]);
|
Vec3 cam_up(view.m[1], view.m[5], view.m[9]);
|
||||||
|
Vec3 cam_fwd(-view.m[2], -view.m[6], -view.m[10]);
|
||||||
|
|
||||||
|
std::vector<size_t> alpha_idx;
|
||||||
|
std::vector<size_t> add_idx;
|
||||||
|
alpha_idx.reserve(particles.size());
|
||||||
|
add_idx.reserve(particles.size());
|
||||||
|
for (size_t i = 0; i < particles.size(); ++i) {
|
||||||
|
Vec3 rel = particles[i].pos - cam.eye;
|
||||||
|
if (rel.dot(cam_fwd) < 0.55f) continue; // avoid clipping particles right in front of cockpit lens
|
||||||
|
if (particles[i].additive) add_idx.push_back(i);
|
||||||
|
else alpha_idx.push_back(i);
|
||||||
|
}
|
||||||
|
std::sort(alpha_idx.begin(), alpha_idx.end(), [&](size_t ia, size_t ib) {
|
||||||
|
float da = (particles[ia].pos - cam.eye).len_sq();
|
||||||
|
float db = (particles[ib].pos - cam.eye).len_sq();
|
||||||
|
return da > db;
|
||||||
|
});
|
||||||
|
|
||||||
|
const size_t total_quads = alpha_idx.size() + add_idx.size();
|
||||||
std::vector<float> pverts;
|
std::vector<float> pverts;
|
||||||
pverts.reserve(particles.size() * 6 * 9);
|
pverts.reserve(total_quads * 6 * 11);
|
||||||
for (const auto& p : particles) {
|
auto push_quad_idx = [&](size_t idx) {
|
||||||
|
const auto& p = particles[idx];
|
||||||
Vec3 rx = cam_right * (p.size * 0.5f);
|
Vec3 rx = cam_right * (p.size * 0.5f);
|
||||||
Vec3 ry = cam_up * (p.size * 0.5f);
|
Vec3 ry = cam_up * (p.size * 0.5f);
|
||||||
Vec3 c0 = p.pos - rx - ry;
|
Vec3 c0 = p.pos - rx - ry;
|
||||||
@@ -819,20 +1387,33 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
|
|||||||
pverts.push_back(u); pverts.push_back(v);
|
pverts.push_back(u); pverts.push_back(v);
|
||||||
pverts.push_back(p.color.x); pverts.push_back(p.color.y);
|
pverts.push_back(p.color.x); pverts.push_back(p.color.y);
|
||||||
pverts.push_back(p.color.z); pverts.push_back(p.color.w);
|
pverts.push_back(p.color.z); pverts.push_back(p.color.w);
|
||||||
|
pverts.push_back(p.style); pverts.push_back(p.seed);
|
||||||
};
|
};
|
||||||
emit(c0, 0.0f, 0.0f); emit(c1, 1.0f, 0.0f); emit(c2, 1.0f, 1.0f);
|
emit(c0, 0.0f, 0.0f); emit(c1, 1.0f, 0.0f); emit(c2, 1.0f, 1.0f);
|
||||||
emit(c0, 0.0f, 0.0f); emit(c2, 1.0f, 1.0f); emit(c3, 0.0f, 1.0f);
|
emit(c0, 0.0f, 0.0f); emit(c2, 1.0f, 1.0f); emit(c3, 0.0f, 1.0f);
|
||||||
}
|
};
|
||||||
|
for (size_t idx : alpha_idx) push_quad_idx(idx);
|
||||||
|
for (size_t idx : add_idx) push_quad_idx(idx);
|
||||||
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
||||||
particle_shader_.use();
|
particle_shader_.use();
|
||||||
particle_shader_.set_mat4("uViewProj", view_proj);
|
particle_shader_.set_mat4("uViewProj", view_proj);
|
||||||
|
particle_shader_.set_vec3("uCamPos", cam.eye);
|
||||||
|
particle_shader_.set_vec3("uFogColor", fog_color_);
|
||||||
|
particle_shader_.set_float("uDrawDist", draw_dist);
|
||||||
gl::BindVertexArray(part_vao_);
|
gl::BindVertexArray(part_vao_);
|
||||||
gl::BindBuffer(GL_ARRAY_BUFFER, part_vbo_);
|
gl::BindBuffer(GL_ARRAY_BUFFER, part_vbo_);
|
||||||
gl::BufferData(GL_ARRAY_BUFFER,
|
gl::BufferData(GL_ARRAY_BUFFER,
|
||||||
static_cast<GLsizeiptr>(pverts.size() * sizeof(float)),
|
static_cast<GLsizeiptr>(pverts.size() * sizeof(float)),
|
||||||
pverts.data(), GL_DYNAMIC_DRAW);
|
pverts.data(), GL_DYNAMIC_DRAW);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(particles.size() * 6));
|
if (!alpha_idx.empty()) {
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(alpha_idx.size() * 6));
|
||||||
|
}
|
||||||
|
if (!add_idx.empty()) {
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
|
glDrawArrays(GL_TRIANGLES, static_cast<GLint>(alpha_idx.size() * 6),
|
||||||
|
static_cast<GLsizei>(add_idx.size() * 6));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
@@ -894,17 +1475,33 @@ void WorldRenderer::render_model_preview(const std::string& model_key, float yaw
|
|||||||
|
|
||||||
float aspect = static_cast<float>(vw) / static_cast<float>(vh);
|
float aspect = static_cast<float>(vw) / static_cast<float>(vh);
|
||||||
Mat4 proj = Mat4::perspective(deg_to_rad(42.0f), aspect, 0.1f, 20.0f);
|
Mat4 proj = Mat4::perspective(deg_to_rad(42.0f), aspect, 0.1f, 20.0f);
|
||||||
Mat4 view = Mat4::look_at(Vec3(0.0f, 1.1f, 2.7f), Vec3(0.0f, 0.05f, 0.0f), Vec3(0, 1, 0));
|
Vec3 eye(0.0f, 1.1f, 2.7f);
|
||||||
|
Mat4 view = Mat4::look_at(eye, Vec3(0.0f, 0.05f, 0.0f), Vec3(0, 1, 0));
|
||||||
Mat4 model = Mat4::rotate_y(yaw_rad) * Mat4::scale(Vec3(scale, scale, scale));
|
Mat4 model = Mat4::rotate_y(yaw_rad) * Mat4::scale(Vec3(scale, scale, scale));
|
||||||
|
|
||||||
model_shader_.use();
|
model_shader_.use();
|
||||||
model_shader_.set_mat4("uViewProj", proj * view);
|
model_shader_.set_mat4("uViewProj", proj * view);
|
||||||
model_shader_.set_mat4("uModel", model);
|
model_shader_.set_mat4("uModel", model);
|
||||||
|
model_shader_.set_mat4("uLightSpace", Mat4::identity());
|
||||||
model_shader_.set_vec4("uTint", Vec4(1, 1, 1, 1));
|
model_shader_.set_vec4("uTint", Vec4(1, 1, 1, 1));
|
||||||
|
model_shader_.set_vec3("uCamPos", eye);
|
||||||
model_shader_.set_float("uEnableFog", 0.0f);
|
model_shader_.set_float("uEnableFog", 0.0f);
|
||||||
|
model_shader_.set_float("uModernLighting", 1.0f);
|
||||||
|
model_shader_.set_float("uUseShadowMap", 0.0f);
|
||||||
|
model_shader_.set_vec3("uSunDir", Vec3(0.50f, 0.78f, 0.45f).normalized());
|
||||||
|
model_shader_.set_vec3("uSunColor", Vec3(1.06f, 0.99f, 0.92f));
|
||||||
|
model_shader_.set_vec3("uSkyColor", Vec3(0.72f, 0.85f, 1.04f));
|
||||||
|
model_shader_.set_vec3("uGroundColor", Vec3(0.35f, 0.36f, 0.44f));
|
||||||
|
model_shader_.set_int("uLightCount", 0);
|
||||||
gl::ActiveTexture(GL_TEXTURE0);
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex_obj_atlas_);
|
glBindTexture(GL_TEXTURE_2D, tex_obj_atlas_);
|
||||||
model_shader_.set_int("uAtlas", 0);
|
model_shader_.set_int("uAtlas", 0);
|
||||||
|
model_shader_.set_int("uShadowMap", 1);
|
||||||
|
if (shadow_depth_tex_) {
|
||||||
|
gl::ActiveTexture(GL_TEXTURE1);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, shadow_depth_tex_);
|
||||||
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
|
}
|
||||||
|
|
||||||
gl::BindVertexArray(it->second.vao);
|
gl::BindVertexArray(it->second.vao);
|
||||||
glDrawElements(GL_TRIANGLES, it->second.index_count, GL_UNSIGNED_INT, nullptr);
|
glDrawElements(GL_TRIANGLES, it->second.index_count, GL_UNSIGNED_INT, nullptr);
|
||||||
|
|||||||
@@ -41,6 +41,21 @@ struct ParticleQuad {
|
|||||||
Vec3 pos;
|
Vec3 pos;
|
||||||
float size = 0.4f;
|
float size = 0.4f;
|
||||||
Vec4 color{1.0f, 0.8f, 0.3f, 1.0f};
|
Vec4 color{1.0f, 0.8f, 0.3f, 1.0f};
|
||||||
|
float style = 0.0f; // 0=glow, 1=fireball, 2=smoke, 3=debris
|
||||||
|
float seed = 0.0f;
|
||||||
|
bool additive = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DynamicLight {
|
||||||
|
Vec3 pos;
|
||||||
|
float radius = 6.0f;
|
||||||
|
Vec3 color{1.0f, 0.8f, 0.4f};
|
||||||
|
float intensity = 1.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CraftShadow {
|
||||||
|
Vec3 pos;
|
||||||
|
float radius = 0.95f;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WorldRenderer {
|
class WorldRenderer {
|
||||||
@@ -66,7 +81,9 @@ public:
|
|||||||
// viewport_index: 0 = full screen (when split_count == 1), 0 = top / 1 = bottom (when split_count == 2)
|
// viewport_index: 0 = full screen (when split_count == 1), 0 = top / 1 = bottom (when split_count == 2)
|
||||||
void render_world_view(const RenderCamera& cam, const std::vector<ModelInstance>& models,
|
void render_world_view(const RenderCamera& cam, const std::vector<ModelInstance>& models,
|
||||||
const std::vector<ParticleQuad>& particles,
|
const std::vector<ParticleQuad>& particles,
|
||||||
int viewport_index, int split_count, const GameConfig& cfg);
|
int viewport_index, int split_count, const GameConfig& cfg,
|
||||||
|
const std::vector<DynamicLight>& lights = {},
|
||||||
|
const std::vector<CraftShadow>& craft_shadows = {});
|
||||||
|
|
||||||
// Finalizes Classic Mode FBO quantization blit if active; call before drawing crisp 2D UI or after
|
// Finalizes Classic Mode FBO quantization blit if active; call before drawing crisp 2D UI or after
|
||||||
void end_classic_world_pass(int backbuffer_w, int backbuffer_h, const GameConfig& cfg);
|
void end_classic_world_pass(int backbuffer_w, int backbuffer_h, const GameConfig& cfg);
|
||||||
@@ -86,11 +103,20 @@ private:
|
|||||||
GLsizei index_count = 0;
|
GLsizei index_count = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct WorldLightingTheme {
|
||||||
|
Vec3 sun_dir{0.45f, 0.80f, 0.38f};
|
||||||
|
Vec3 sun_color{1.0f, 0.96f, 0.88f};
|
||||||
|
Vec3 sky_color{0.55f, 0.68f, 0.88f};
|
||||||
|
Vec3 ground_color{0.34f, 0.30f, 0.26f};
|
||||||
|
};
|
||||||
|
|
||||||
void destroy_mesh(GpuMesh& m);
|
void destroy_mesh(GpuMesh& m);
|
||||||
void upload_world_mesh(GpuMesh& m, const std::vector<WorldVertex>& verts,
|
void upload_world_mesh(GpuMesh& m, const std::vector<WorldVertex>& verts,
|
||||||
const std::vector<uint32_t>& indices, bool dynamic);
|
const std::vector<uint32_t>& indices, bool dynamic);
|
||||||
void ensure_classic_fbo(int w, int h);
|
void ensure_classic_fbo(int w, int h);
|
||||||
|
bool init_shadow_map();
|
||||||
void apply_texture_filtering(TextureFilterMode mode);
|
void apply_texture_filtering(TextureFilterMode mode);
|
||||||
|
static WorldLightingTheme theme_for_world(int world_idx);
|
||||||
|
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
assets::ObjectTextureAtlas obj_atlas_;
|
assets::ObjectTextureAtlas obj_atlas_;
|
||||||
@@ -104,6 +130,8 @@ private:
|
|||||||
ShaderProgram sky_shader_;
|
ShaderProgram sky_shader_;
|
||||||
ShaderProgram particle_shader_;
|
ShaderProgram particle_shader_;
|
||||||
ShaderProgram classic_shader_;
|
ShaderProgram classic_shader_;
|
||||||
|
ShaderProgram shadow_world_shader_;
|
||||||
|
ShaderProgram shadow_model_shader_;
|
||||||
|
|
||||||
// Textures
|
// Textures
|
||||||
GLuint tex_terrain_array_ = 0;
|
GLuint tex_terrain_array_ = 0;
|
||||||
@@ -112,6 +140,11 @@ private:
|
|||||||
GLuint tex_palette_ = 0;
|
GLuint tex_palette_ = 0;
|
||||||
TextureFilterMode active_filter_ = TextureFilterMode::Linear;
|
TextureFilterMode active_filter_ = TextureFilterMode::Linear;
|
||||||
|
|
||||||
|
// Shadow map FBO (2048x2048 directional shadow depth map for Modern Mode)
|
||||||
|
static constexpr int kShadowMapSize = 2048;
|
||||||
|
GLuint shadow_fbo_ = 0;
|
||||||
|
GLuint shadow_depth_tex_ = 0;
|
||||||
|
|
||||||
// World meshes
|
// World meshes
|
||||||
GpuMesh terrain_mesh_;
|
GpuMesh terrain_mesh_;
|
||||||
GpuMesh column_mesh_;
|
GpuMesh column_mesh_;
|
||||||
@@ -130,6 +163,7 @@ private:
|
|||||||
// Cached 3D models
|
// Cached 3D models
|
||||||
std::unordered_map<std::string, GpuMesh> model_cache_;
|
std::unordered_map<std::string, GpuMesh> model_cache_;
|
||||||
Vec3 fog_color_{0.15f, 0.2f, 0.3f};
|
Vec3 fog_color_{0.15f, 0.2f, 0.3f};
|
||||||
|
int current_world_index_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace top_octane::render
|
} // namespace top_octane::render
|
||||||
+171
-18
@@ -3,20 +3,26 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
namespace top_octane::sim {
|
namespace top_octane::sim {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void spawn_explosion(std::vector<ParticleBurst>& particles, const Vec3& pos, float scale = 1.0f) {
|
uint32_t pos_seed_u32(const Vec3& p, uint32_t salt) {
|
||||||
for (int k = 0; k < 10; ++k) {
|
uint32_t hx = static_cast<uint32_t>(std::lround(p.x * 16.0f)) * 73856093u;
|
||||||
float ang = kTwoPi * (static_cast<float>(k) / 10.0f);
|
uint32_t hy = static_cast<uint32_t>(std::lround(p.y * 16.0f)) * 19349663u;
|
||||||
float spd = (1.5f + static_cast<float>((k * 37) % 10) * 0.28f) * scale;
|
uint32_t hz = static_cast<uint32_t>(std::lround(p.z * 16.0f)) * 83492791u;
|
||||||
Vec3 v(std::cos(ang) * spd, (1.2f + static_cast<float>(k % 3) * 0.9f) * scale,
|
return hx ^ hy ^ hz ^ (salt * 2654435761u);
|
||||||
std::sin(ang) * spd);
|
|
||||||
Vec4 col = (k % 2 == 0) ? Vec4(1.0f, 0.6f, 0.15f, 1.0f) : Vec4(1.0f, 0.25f, 0.05f, 1.0f);
|
|
||||||
particles.push_back({pos, v, 0.55f * scale, col, 0.45f, 0.45f});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float fx_hash(uint32_t x) {
|
||||||
|
x ^= x >> 16;
|
||||||
|
x *= 0x7feb352du;
|
||||||
|
x ^= x >> 15;
|
||||||
|
x *= 0x846ca68bu;
|
||||||
|
x ^= x >> 16;
|
||||||
|
return static_cast<float>(x & 0x00FFFFFFu) / 16777216.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply_damage(CraftState& victim, int attacker_id, const std::vector<CraftState>& crafts,
|
void apply_damage(CraftState& victim, int attacker_id, const std::vector<CraftState>& crafts,
|
||||||
@@ -42,7 +48,7 @@ void apply_damage(CraftState& victim, int attacker_id, const std::vector<CraftSt
|
|||||||
}
|
}
|
||||||
victim.killed_by = killer_name;
|
victim.killed_by = killer_name;
|
||||||
|
|
||||||
spawn_explosion(particles, victim.curr_pose.pos, 1.5f);
|
spawn_explosion_fx(particles, victim.curr_pose.pos, 1.55f);
|
||||||
events.push_back({SimSoundCue::Explosion, victim.curr_pose.pos,
|
events.push_back({SimSoundCue::Explosion, victim.curr_pose.pos,
|
||||||
victim.is_human ? victim.player_index : -1,
|
victim.is_human ? victim.player_index : -1,
|
||||||
victim.is_human ? ("KILLED BY " + killer_name) : "", 0.95f});
|
victim.is_human ? ("KILLED BY " + killer_name) : "", 0.95f});
|
||||||
@@ -118,6 +124,124 @@ void apply_pickup(CraftState& c, uint8_t subtype, std::vector<SimEvent>& events)
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void spawn_smoke_puff(std::vector<ParticleBurst>& particles, const Vec3& pos, const Vec3& vel,
|
||||||
|
float start_size, float end_size, const Vec4& color, float life,
|
||||||
|
float drag, float gravity, float seed) {
|
||||||
|
particles.push_back({pos, vel, start_size, color, life, life,
|
||||||
|
ParticleKind::Smoke, start_size, end_size,
|
||||||
|
drag, gravity, seed, color.w});
|
||||||
|
}
|
||||||
|
|
||||||
|
void spawn_explosion_fx(std::vector<ParticleBurst>& particles, const Vec3& pos, float scale) {
|
||||||
|
// 1. 2 blazing white-yellow core flash Fireball puffs
|
||||||
|
for (int k = 0; k < 2; ++k) {
|
||||||
|
float h0 = fx_hash(pos_seed_u32(pos, static_cast<uint32_t>(k + 1)));
|
||||||
|
float life = 0.22f + 0.06f * h0;
|
||||||
|
Vec3 jitter((h0 - 0.5f) * 0.25f * scale, 0.20f * scale,
|
||||||
|
(fx_hash(pos_seed_u32(pos, static_cast<uint32_t>(k + 20))) - 0.5f) * 0.25f * scale);
|
||||||
|
particles.push_back({pos + jitter, Vec3(0.0f, 0.9f * scale, 0.0f),
|
||||||
|
0.55f * scale, Vec4(1.0f, 0.96f, 0.78f, 1.0f), life, life,
|
||||||
|
ParticleKind::Fireball, 0.55f * scale, 2.25f * scale,
|
||||||
|
3.0f, 0.8f, h0, 1.0f});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 10 expanding turbulent Fireball puffs bursting spherically/upward
|
||||||
|
for (int k = 0; k < 10; ++k) {
|
||||||
|
uint32_t sbase = static_cast<uint32_t>(100 + k * 7);
|
||||||
|
float h_ang = fx_hash(pos_seed_u32(pos, sbase + 0u));
|
||||||
|
float h_spd = fx_hash(pos_seed_u32(pos, sbase + 1u));
|
||||||
|
float h_vy = fx_hash(pos_seed_u32(pos, sbase + 2u));
|
||||||
|
float h_life = fx_hash(pos_seed_u32(pos, sbase + 3u));
|
||||||
|
float ang = kTwoPi * (static_cast<float>(k) / 10.0f) + (h_ang - 0.5f) * 0.45f;
|
||||||
|
float spd = (2.0f + h_spd * 3.2f) * scale;
|
||||||
|
float vy = (1.2f + h_vy * 3.0f) * scale;
|
||||||
|
float life = 0.45f + h_life * 0.30f;
|
||||||
|
Vec3 off(std::cos(ang) * 0.28f * scale, 0.12f * scale, std::sin(ang) * 0.28f * scale);
|
||||||
|
Vec3 v(std::cos(ang) * spd, vy, std::sin(ang) * spd);
|
||||||
|
particles.push_back({pos + off, v,
|
||||||
|
0.45f * scale, Vec4(1.0f, 0.82f, 0.32f, 0.95f), life, life,
|
||||||
|
ParticleKind::Fireball, 0.45f * scale, 1.85f * scale,
|
||||||
|
2.8f, 1.6f, h_ang, 0.95f});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 12 thick dark charcoal/black Smoke puffs bursting outward & rising buoyantly
|
||||||
|
for (int k = 0; k < 12; ++k) {
|
||||||
|
uint32_t sbase = static_cast<uint32_t>(200 + k * 7);
|
||||||
|
float h_ang = fx_hash(pos_seed_u32(pos, sbase + 0u));
|
||||||
|
float h_spd = fx_hash(pos_seed_u32(pos, sbase + 1u));
|
||||||
|
float h_vy = fx_hash(pos_seed_u32(pos, sbase + 2u));
|
||||||
|
float h_life = fx_hash(pos_seed_u32(pos, sbase + 3u));
|
||||||
|
float h_col = fx_hash(pos_seed_u32(pos, sbase + 4u));
|
||||||
|
float ang = kTwoPi * (static_cast<float>(k) / 12.0f) + (h_ang - 0.5f) * 0.40f;
|
||||||
|
float spd = (1.4f + h_spd * 2.4f) * scale;
|
||||||
|
float vy = (1.4f + h_vy * 2.2f) * scale;
|
||||||
|
float life = 1.15f + h_life * 0.70f;
|
||||||
|
float g = 0.13f + h_col * 0.11f;
|
||||||
|
Vec3 off(std::cos(ang) * 0.35f * scale, 0.20f * scale, std::sin(ang) * 0.35f * scale);
|
||||||
|
Vec3 v(std::cos(ang) * spd, vy, std::sin(ang) * spd);
|
||||||
|
spawn_smoke_puff(particles, pos + off, v, 0.55f * scale, 2.80f * scale,
|
||||||
|
Vec4(g, g, g * 1.04f, 0.84f), life, 2.2f, 1.7f, h_ang);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 4 bright hot orange-yellow AdditiveGlow sparks
|
||||||
|
for (int k = 0; k < 4; ++k) {
|
||||||
|
uint32_t sbase = static_cast<uint32_t>(300 + k * 7);
|
||||||
|
float h_ang = fx_hash(pos_seed_u32(pos, sbase + 0u));
|
||||||
|
float h_spd = fx_hash(pos_seed_u32(pos, sbase + 1u));
|
||||||
|
float h_vy = fx_hash(pos_seed_u32(pos, sbase + 2u));
|
||||||
|
float h_life = fx_hash(pos_seed_u32(pos, sbase + 3u));
|
||||||
|
float ang = kTwoPi * (static_cast<float>(k) / 4.0f) + h_ang * 0.9f;
|
||||||
|
float spd = (5.5f + h_spd * 4.0f) * scale;
|
||||||
|
float vy = (3.5f + h_vy * 4.0f) * scale;
|
||||||
|
float life = 0.45f + h_life * 0.30f;
|
||||||
|
particles.push_back({pos, Vec3(std::cos(ang) * spd, vy, std::sin(ang) * spd),
|
||||||
|
0.18f * scale, Vec4(1.0f, 0.82f, 0.28f, 1.0f), life, life,
|
||||||
|
ParticleKind::AdditiveGlow, 0.18f * scale, 0.06f * scale,
|
||||||
|
0.8f, -12.0f, h_ang, 1.0f});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 4 charred rotating Debris chunks under strong downward gravity
|
||||||
|
for (int k = 0; k < 4; ++k) {
|
||||||
|
uint32_t sbase = static_cast<uint32_t>(400 + k * 7);
|
||||||
|
float h_ang = fx_hash(pos_seed_u32(pos, sbase + 0u));
|
||||||
|
float h_spd = fx_hash(pos_seed_u32(pos, sbase + 1u));
|
||||||
|
float h_vy = fx_hash(pos_seed_u32(pos, sbase + 2u));
|
||||||
|
float h_life = fx_hash(pos_seed_u32(pos, sbase + 3u));
|
||||||
|
float ang = kTwoPi * (static_cast<float>(k) / 4.0f + 0.125f) + (h_ang - 0.5f) * 0.6f;
|
||||||
|
float spd = (3.8f + h_spd * 3.7f) * scale;
|
||||||
|
float vy = (4.0f + h_vy * 4.2f) * scale;
|
||||||
|
float life = 0.65f + h_life * 0.40f;
|
||||||
|
particles.push_back({pos, Vec3(std::cos(ang) * spd, vy, std::sin(ang) * spd),
|
||||||
|
0.26f * scale, Vec4(0.15f, 0.14f, 0.13f, 0.95f), life, life,
|
||||||
|
ParticleKind::Debris, 0.26f * scale, 0.18f * scale,
|
||||||
|
0.4f, -13.5f, h_ang, 0.95f});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void spawn_impact_fx(std::vector<ParticleBurst>& particles, const Vec3& pos, bool hit_craft) {
|
||||||
|
const int n_sparks = hit_craft ? 4 : 3;
|
||||||
|
for (int k = 0; k < n_sparks; ++k) {
|
||||||
|
uint32_t sbase = static_cast<uint32_t>(500 + k * 5);
|
||||||
|
float h0 = fx_hash(pos_seed_u32(pos, sbase + 0u));
|
||||||
|
float h1 = fx_hash(pos_seed_u32(pos, sbase + 1u));
|
||||||
|
float ang = kTwoPi * (static_cast<float>(k) / static_cast<float>(n_sparks)) + h0;
|
||||||
|
float spd = 2.6f + h1 * 2.8f;
|
||||||
|
float life = 0.18f + 0.10f * h0;
|
||||||
|
Vec4 scol = hit_craft ? Vec4(1.0f, 0.65f, 0.20f, 1.0f) : Vec4(1.0f, 0.85f, 0.35f, 0.95f);
|
||||||
|
particles.push_back({pos, Vec3(std::cos(ang) * spd, 1.8f + h1 * 2.2f, std::sin(ang) * spd),
|
||||||
|
0.18f, scol, life, life,
|
||||||
|
ParticleKind::AdditiveGlow, 0.18f, 0.05f,
|
||||||
|
1.2f, -10.0f, h0, scol.w});
|
||||||
|
}
|
||||||
|
for (int k = 0; k < 2; ++k) {
|
||||||
|
float h0 = fx_hash(pos_seed_u32(pos, static_cast<uint32_t>(550 + k * 5)));
|
||||||
|
float ang = h0 * kTwoPi;
|
||||||
|
Vec3 v(std::cos(ang) * 0.9f, 1.2f + 0.6f * h0, std::sin(ang) * 0.9f);
|
||||||
|
spawn_smoke_puff(particles, pos, v, 0.18f, 0.62f,
|
||||||
|
Vec4(0.48f, 0.48f, 0.50f, 0.55f), 0.45f, 2.5f, 0.9f, h0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void step_combat_and_world(
|
void step_combat_and_world(
|
||||||
RaceSetup& setup,
|
RaceSetup& setup,
|
||||||
const assets::LevelData& level,
|
const assets::LevelData& level,
|
||||||
@@ -163,6 +287,23 @@ void step_combat_and_world(
|
|||||||
c.prev_pose = c.curr_pose;
|
c.prev_pose = c.curr_pose;
|
||||||
c.vel = Vec3(0, 0, 0);
|
c.vel = Vec3(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
} else if (c.shield <= 0.1f) {
|
||||||
|
int rec_ticks = static_cast<int>(std::lround(c.recovery_timer * 60.0f));
|
||||||
|
if (rec_ticks % 4 == 0) {
|
||||||
|
float h0 = fx_hash(pos_seed_u32(c.curr_pose.pos, static_cast<uint32_t>(rec_ticks)));
|
||||||
|
float ang = h0 * kTwoPi;
|
||||||
|
Vec3 p = c.curr_pose.pos + Vec3(std::cos(ang) * 0.22f, 0.25f, std::sin(ang) * 0.22f);
|
||||||
|
Vec3 v(std::cos(ang) * 0.45f, 2.4f + 0.6f * h0, std::sin(ang) * 0.45f);
|
||||||
|
spawn_smoke_puff(particles, p, v, 0.42f, 2.15f,
|
||||||
|
Vec4(0.14f, 0.14f, 0.16f, 0.78f), 1.25f, 1.6f, 1.8f, h0);
|
||||||
|
}
|
||||||
|
if (rec_ticks % 7 == 0) {
|
||||||
|
float h1 = fx_hash(pos_seed_u32(c.curr_pose.pos, static_cast<uint32_t>(rec_ticks + 91)));
|
||||||
|
particles.push_back({c.curr_pose.pos + Vec3(0.0f, 0.25f, 0.0f),
|
||||||
|
Vec3((h1 - 0.5f) * 0.6f, 1.8f, (h1 - 0.5f) * 0.6f),
|
||||||
|
0.32f, Vec4(1.0f, 0.78f, 0.30f, 0.95f), 0.34f, 0.34f,
|
||||||
|
ParticleKind::Fireball, 0.32f, 0.80f, 1.5f, 1.4f, h1, 0.95f});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -280,9 +421,21 @@ void step_combat_and_world(
|
|||||||
pr.vel = steered * std::max(spd, 28.0f);
|
pr.vel = steered * std::max(spd, 28.0f);
|
||||||
pr.yaw = std::atan2(steered.x, steered.z);
|
pr.yaw = std::atan2(steered.x, steered.z);
|
||||||
}
|
}
|
||||||
particles.push_back({pr.pos, Vec3(0, 0.3f, 0), 0.24f, Vec4(0.95f, 0.8f, 0.45f, 0.8f), 0.18f, 0.18f});
|
}
|
||||||
} else if (!pr.is_missile) {
|
if (pr.is_missile) {
|
||||||
particles.push_back({pr.pos, Vec3(0, 0, 0), 0.14f, Vec4(1.0f, 0.95f, 0.4f, 0.9f), 0.06f, 0.06f});
|
Vec3 mdir = pr.vel.normalized();
|
||||||
|
float seed = fx_hash(pos_seed_u32(pr.pos, static_cast<uint32_t>(pr.owner_id + 17)));
|
||||||
|
spawn_smoke_puff(particles, pr.pos - mdir * 0.22f,
|
||||||
|
-mdir * 1.4f + Vec3((seed - 0.5f) * 0.4f, 0.45f, (seed - 0.5f) * 0.4f),
|
||||||
|
0.20f, 0.90f, Vec4(0.76f, 0.77f, 0.79f, 0.64f), 0.62f,
|
||||||
|
3.5f, 0.75f, seed);
|
||||||
|
particles.push_back({pr.pos - mdir * 0.14f, Vec3(0, 0.1f, 0),
|
||||||
|
0.24f, Vec4(1.0f, 0.78f, 0.30f, 0.95f), 0.08f, 0.08f,
|
||||||
|
ParticleKind::AdditiveGlow, 0.24f, 0.07f, 0.0f, 0.0f, seed, 0.95f});
|
||||||
|
} else {
|
||||||
|
particles.push_back({pr.pos, Vec3(0, 0, 0), 0.14f, Vec4(1.0f, 0.95f, 0.4f, 0.9f),
|
||||||
|
0.06f, 0.06f, ParticleKind::AdditiveGlow, 0.14f, 0.06f,
|
||||||
|
0.0f, 0.0f, 0.0f, 0.9f});
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3 prev_pos = pr.pos;
|
Vec3 prev_pos = pr.pos;
|
||||||
@@ -304,10 +457,10 @@ void step_combat_and_world(
|
|||||||
level.is_cell_solid_at_point(ix, iz, pr.pos.x, pr.pos.z, pr.pos.y, 0.10f)) {
|
level.is_cell_solid_at_point(ix, iz, pr.pos.x, pr.pos.z, pr.pos.y, 0.10f)) {
|
||||||
pr.active = false;
|
pr.active = false;
|
||||||
if (pr.is_missile) {
|
if (pr.is_missile) {
|
||||||
spawn_explosion(particles, pr.pos, 0.9f);
|
spawn_explosion_fx(particles, pr.pos, 0.95f);
|
||||||
events.push_back({SimSoundCue::Explosion, pr.pos, -1, "", 0.0f});
|
events.push_back({SimSoundCue::Explosion, pr.pos, -1, "", 0.0f});
|
||||||
} else {
|
} else {
|
||||||
particles.push_back({pr.pos, Vec3(0, 1.0f, 0), 0.22f, Vec4(1.0f, 0.8f, 0.3f, 0.9f), 0.16f, 0.16f});
|
spawn_impact_fx(particles, pr.pos, false);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -325,11 +478,11 @@ void step_combat_and_world(
|
|||||||
crafts[pr.owner_id].shots_hit += 1;
|
crafts[pr.owner_id].shots_hit += 1;
|
||||||
}
|
}
|
||||||
if (pr.is_missile) {
|
if (pr.is_missile) {
|
||||||
spawn_explosion(particles, pr.pos, 1.15f);
|
spawn_explosion_fx(particles, pr.pos, 1.15f);
|
||||||
events.push_back({SimSoundCue::Explosion, pr.pos,
|
events.push_back({SimSoundCue::Explosion, pr.pos,
|
||||||
victim.is_human ? victim.player_index : -1, "", 0.65f});
|
victim.is_human ? victim.player_index : -1, "", 0.65f});
|
||||||
} else {
|
} else {
|
||||||
particles.push_back({pr.pos, Vec3(0, 1.2f, 0), 0.28f, Vec4(1.0f, 0.6f, 0.2f, 1.0f), 0.20f, 0.20f});
|
spawn_impact_fx(particles, pr.pos, true);
|
||||||
events.push_back({SimSoundCue::Impact, pr.pos,
|
events.push_back({SimSoundCue::Impact, pr.pos,
|
||||||
victim.is_human ? victim.player_index : -1, "", 0.20f});
|
victim.is_human ? victim.player_index : -1, "", 0.20f});
|
||||||
}
|
}
|
||||||
@@ -364,7 +517,7 @@ void step_combat_and_world(
|
|||||||
if (prop.hp <= 0.0f) {
|
if (prop.hp <= 0.0f) {
|
||||||
prop.alive = false;
|
prop.alive = false;
|
||||||
prop.respawn_timer = 25.0f;
|
prop.respawn_timer = 25.0f;
|
||||||
spawn_explosion(particles, prop.pos, 0.85f);
|
spawn_explosion_fx(particles, prop.pos, 0.95f);
|
||||||
events.push_back({SimSoundCue::Explosion, prop.pos, -1, "", 0.25f});
|
events.push_back({SimSoundCue::Explosion, prop.pos, -1, "", 0.25f});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -422,7 +575,7 @@ void step_combat_and_world(
|
|||||||
if (setup.damage_enabled) {
|
if (setup.damage_enabled) {
|
||||||
c.shield = std::max(5.0f, c.shield - 12.0f);
|
c.shield = std::max(5.0f, c.shield - 12.0f);
|
||||||
}
|
}
|
||||||
spawn_explosion(particles, prop.pos, 0.9f);
|
spawn_explosion_fx(particles, prop.pos, 1.0f);
|
||||||
events.push_back({SimSoundCue::Explosion, prop.pos,
|
events.push_back({SimSoundCue::Explosion, prop.pos,
|
||||||
c.is_human ? c.player_index : -1, "", 0.45f});
|
c.is_human ? c.player_index : -1, "", 0.45f});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ struct RecoveryVisual {
|
|||||||
float yaw = 0.0f;
|
float yaw = 0.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Shared deterministic explosion, billowing smoke & spark VFX helpers
|
||||||
|
void spawn_explosion_fx(std::vector<ParticleBurst>& particles, const Vec3& pos, float scale = 1.0f);
|
||||||
|
void spawn_smoke_puff(std::vector<ParticleBurst>& particles, const Vec3& pos, const Vec3& vel,
|
||||||
|
float start_size, float end_size, const Vec4& color, float life,
|
||||||
|
float drag = 2.0f, float gravity = 1.2f, float seed = 0.25f);
|
||||||
|
void spawn_impact_fx(std::vector<ParticleBurst>& particles, const Vec3& pos, bool hit_craft);
|
||||||
|
|
||||||
// Updates forward-cone missile lock, weapon firing, projectile movement, collisions, pickups, props & recovery
|
// Updates forward-cone missile lock, weapon firing, projectile movement, collisions, pickups, props & recovery
|
||||||
void step_combat_and_world(
|
void step_combat_and_world(
|
||||||
RaceSetup& setup,
|
RaceSetup& setup,
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ struct CraftState {
|
|||||||
float scrape_intensity = 0.0f;
|
float scrape_intensity = 0.0f;
|
||||||
float refuel_sound_cd = 0.0f;
|
float refuel_sound_cd = 0.0f;
|
||||||
uint8_t active_recharge_mask = 0; // bit0=Shield, bit1=Fuel, bit2=Ammo
|
uint8_t active_recharge_mask = 0; // bit0=Shield, bit1=Fuel, bit2=Ammo
|
||||||
|
uint8_t on_pit_mask = 0; // bit0=Shield, bit1=Fuel, bit2=Ammo (present on bay even if full)
|
||||||
|
float pit_fill_ratio = 1.0f; // [0..1] fill ratio of active charging resource(s)
|
||||||
bool autopilot = false;
|
bool autopilot = false;
|
||||||
|
|
||||||
// Recovery / repair
|
// Recovery / repair
|
||||||
|
|||||||
+180
-40
@@ -140,6 +140,8 @@ bool RaceSim::start_race(const assets::LevelData& level, const RaceSetup& setup,
|
|||||||
dirty_rects_.clear();
|
dirty_rects_.clear();
|
||||||
columns_dirty_ = false;
|
columns_dirty_ = false;
|
||||||
morph_banner_cd_ = 0.0f;
|
morph_banner_cd_ = 0.0f;
|
||||||
|
steam_vent_timers_.assign(level_.effects.size(), 0.0f);
|
||||||
|
fx_tick_ = 0;
|
||||||
|
|
||||||
int total_racers = 1;
|
int total_racers = 1;
|
||||||
if (setup_.mode == GameMode::SplitScreen) {
|
if (setup_.mode == GameMode::SplitScreen) {
|
||||||
@@ -325,8 +327,10 @@ void RaceSim::step(const CraftInput& p1_input, const CraftInput& p2_input, float
|
|||||||
}
|
}
|
||||||
|
|
||||||
elapsed_time_ += dt;
|
elapsed_time_ += dt;
|
||||||
|
++fx_tick_;
|
||||||
update_timed_triggers(dt);
|
update_timed_triggers(dt);
|
||||||
update_active_morphs(dt);
|
update_active_morphs(dt);
|
||||||
|
update_steam_vents(dt);
|
||||||
|
|
||||||
std::vector<CraftInput> inputs(crafts_.size());
|
std::vector<CraftInput> inputs(crafts_.size());
|
||||||
for (size_t i = 0; i < crafts_.size(); ++i) {
|
for (size_t i = 0; i < crafts_.size(); ++i) {
|
||||||
@@ -360,10 +364,63 @@ void RaceSim::step(const CraftInput& p1_input, const CraftInput& p2_input, float
|
|||||||
if (prev_boost_timer <= 0.01f && c.boost_timer > 0.0f && fb.boosting) {
|
if (prev_boost_timer <= 0.01f && c.boost_timer > 0.0f && fb.boosting) {
|
||||||
events_.push_back({SimSoundCue::Boost, c.curr_pose.pos, c.player_index, "", 0.35f});
|
events_.push_back({SimSoundCue::Boost, c.curr_pose.pos, c.player_index, "", 0.35f});
|
||||||
}
|
}
|
||||||
if (fb.boosting && (static_cast<int>(elapsed_time_ * 12.0f) % 4 == 0)) {
|
if (c.recovery_state == RecoveryState::Active) {
|
||||||
Vec3 back = c.curr_pose.pos - c.forward_dir() * 0.65f;
|
const Vec3 fwd = c.forward_dir();
|
||||||
particles_.push_back({back, -c.forward_dir() * 2.5f + Vec3(0, 0.4f, 0),
|
const Vec3 tail = c.curr_pose.pos - fwd * 0.58f + Vec3(0.0f, 0.18f, 0.0f);
|
||||||
0.38f, Vec4(0.35f, 0.75f, 1.0f, 0.95f), 0.18f, 0.18f});
|
const uint32_t c_phase = fx_tick_ + static_cast<uint32_t>(c.id) * 5u;
|
||||||
|
|
||||||
|
// Damaged craft trailing smoke & critical fire
|
||||||
|
float sh_ratio = c.shield / std::max(c.max_shield, 1.0f);
|
||||||
|
if (sh_ratio < 0.25f) {
|
||||||
|
if (c_phase % 3u == 0u) {
|
||||||
|
float off_s = ((c_phase % 2u == 0u) ? 0.15f : 0.75f);
|
||||||
|
spawn_smoke_puff(particles_, tail,
|
||||||
|
c.vel * 0.18f + Vec3(0.0f, 1.35f, 0.0f),
|
||||||
|
0.34f, 1.55f, Vec4(0.18f, 0.18f, 0.20f, 0.78f),
|
||||||
|
1.05f, 1.8f, 1.4f, off_s);
|
||||||
|
}
|
||||||
|
if ((fx_tick_ + static_cast<uint32_t>(c.id) * 7u) % 9u == 0u) {
|
||||||
|
particles_.push_back({tail, c.vel * 0.20f + Vec3(0.0f, 1.15f, 0.0f),
|
||||||
|
0.26f, Vec4(1.0f, 0.78f, 0.30f, 0.95f), 0.26f, 0.26f,
|
||||||
|
ParticleKind::Fireball, 0.26f, 0.62f,
|
||||||
|
2.2f, 1.2f, 0.35f, 0.95f});
|
||||||
|
}
|
||||||
|
} else if (sh_ratio < 0.50f && (c_phase % 5u == 0u)) {
|
||||||
|
float off_s = ((c_phase % 2u == 0u) ? 0.25f : 0.65f);
|
||||||
|
spawn_smoke_puff(particles_, tail,
|
||||||
|
c.vel * 0.22f + Vec3(0.0f, 1.10f, 0.0f),
|
||||||
|
0.26f, 1.15f, Vec4(0.44f, 0.45f, 0.48f, 0.56f),
|
||||||
|
0.82f, 2.0f, 1.1f, off_s);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Booster exhaust flare & faint exhaust smoke wisp
|
||||||
|
if (fb.boosting && ((fx_tick_ + static_cast<uint32_t>(c.id)) % 2u == 0u)) {
|
||||||
|
Vec3 back = c.curr_pose.pos - fwd * 0.65f;
|
||||||
|
particles_.push_back({back, -fwd * 2.5f + Vec3(0.0f, 0.35f, 0.0f),
|
||||||
|
0.38f, Vec4(0.35f, 0.78f, 1.0f, 0.95f), 0.16f, 0.16f,
|
||||||
|
ParticleKind::AdditiveGlow, 0.38f, 0.12f,
|
||||||
|
1.2f, 0.2f, 0.2f, 0.95f});
|
||||||
|
if ((fx_tick_ + static_cast<uint32_t>(c.id)) % 4u == 0u) {
|
||||||
|
spawn_smoke_puff(particles_, back - fwd * 0.15f,
|
||||||
|
-fwd * 1.4f + Vec3(0.0f, 0.5f, 0.0f),
|
||||||
|
0.22f, 0.75f, Vec4(0.62f, 0.70f, 0.80f, 0.35f),
|
||||||
|
0.42f, 2.5f, 0.7f, 0.45f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wall-scrape sparks
|
||||||
|
if (fb.scraping && c.scrape_intensity > 0.25f &&
|
||||||
|
((fx_tick_ + static_cast<uint32_t>(c.id)) % 3u == 0u)) {
|
||||||
|
Vec3 right(-fwd.z, 0.0f, fwd.x);
|
||||||
|
for (int k = 0; k < 2; ++k) {
|
||||||
|
float side = (k == 0) ? -1.0f : 1.0f;
|
||||||
|
Vec3 sv = -fwd * 2.2f + right * (side * 2.4f) + Vec3(0.0f, 2.2f + k * 0.8f, 0.0f);
|
||||||
|
particles_.push_back({c.curr_pose.pos + right * (side * 0.35f), sv,
|
||||||
|
0.15f, Vec4(1.0f, 0.85f, 0.45f, 1.0f), 0.22f, 0.22f,
|
||||||
|
ParticleKind::AdditiveGlow, 0.15f, 0.05f,
|
||||||
|
0.8f, -11.0f, 0.1f + 0.4f * k, 1.0f});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (fb.stunt_degrees > 0) {
|
if (fb.stunt_degrees > 0) {
|
||||||
SimSoundCue sc = (fb.stunt_degrees >= 720) ? SimSoundCue::Stunt720 :
|
SimSoundCue sc = (fb.stunt_degrees >= 720) ? SimSoundCue::Stunt720 :
|
||||||
@@ -488,7 +545,10 @@ void RaceSim::update_checkpoints_and_laps(CraftState& c, float dt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RaceSim::update_recharge_pads(CraftState& c, float dt) {
|
void RaceSim::update_recharge_pads(CraftState& c, float dt) {
|
||||||
|
const uint8_t prev_charging = c.active_recharge_mask;
|
||||||
c.active_recharge_mask = 0;
|
c.active_recharge_mask = 0;
|
||||||
|
c.on_pit_mask = 0;
|
||||||
|
c.pit_fill_ratio = 1.0f;
|
||||||
if (c.recovery_state != RecoveryState::Active) return;
|
if (c.recovery_state != RecoveryState::Active) return;
|
||||||
|
|
||||||
const float px = c.curr_pose.pos.x;
|
const float px = c.curr_pose.pos.x;
|
||||||
@@ -502,29 +562,44 @@ void RaceSim::update_recharge_pads(CraftState& c, float dt) {
|
|||||||
for (const auto& pad : level_.pads) {
|
for (const auto& pad : level_.pads) {
|
||||||
if (std::abs(px - pad.cx) <= pad.half_x && std::abs(pz - pad.cz) <= pad.half_z) {
|
if (std::abs(px - pad.cx) <= pad.half_x && std::abs(pz - pad.cz) <= pad.half_z) {
|
||||||
switch (pad.type) {
|
switch (pad.type) {
|
||||||
case assets::ChargerType::Shield: in_shield = true; break;
|
case assets::ChargerType::Shield:
|
||||||
case assets::ChargerType::Fuel: in_fuel = true; break;
|
in_shield = true;
|
||||||
case assets::ChargerType::Ammo: in_ammo = true; break;
|
c.on_pit_mask |= 1u;
|
||||||
|
break;
|
||||||
|
case assets::ChargerType::Fuel:
|
||||||
|
in_fuel = true;
|
||||||
|
c.on_pit_mask |= 2u;
|
||||||
|
break;
|
||||||
|
case assets::ChargerType::Ammo:
|
||||||
|
in_ammo = true;
|
||||||
|
c.on_pit_mask |= 4u;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_shield && c.shield < c.max_shield) {
|
float min_fill = 1.0f;
|
||||||
c.shield = std::min(c.max_shield, c.shield + c.max_shield * 0.50f * dt);
|
auto charge_resource = [&](bool in_bay, float& val, float maxv, float rate_frac, uint8_t bit) {
|
||||||
c.active_recharge_mask |= 1u;
|
if (!in_bay) return;
|
||||||
|
const float prev_val = val;
|
||||||
|
if (val < maxv) {
|
||||||
|
val = std::min(maxv, val + maxv * rate_frac * dt);
|
||||||
}
|
}
|
||||||
if (in_fuel && c.fuel < c.max_fuel) {
|
const bool was_charging = (prev_charging & bit) != 0;
|
||||||
c.fuel = std::min(c.max_fuel, c.fuel + c.max_fuel * 0.55f * dt);
|
if ((was_charging || prev_val < maxv - 0.5f) && val < maxv - 1e-4f) {
|
||||||
c.active_recharge_mask |= 2u;
|
c.active_recharge_mask |= bit;
|
||||||
}
|
min_fill = std::min(min_fill, val / std::max(maxv, 1.0f));
|
||||||
if (in_ammo && c.ammo < c.max_ammo) {
|
|
||||||
c.ammo = std::min(c.max_ammo, c.ammo + c.max_ammo * 0.55f * dt);
|
|
||||||
c.active_recharge_mask |= 4u;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
charge_resource(in_shield, c.shield, c.max_shield, 0.50f, 1u);
|
||||||
|
charge_resource(in_fuel, c.fuel, c.max_fuel, 0.55f, 2u);
|
||||||
|
charge_resource(in_ammo, c.ammo, c.max_ammo, 0.55f, 4u);
|
||||||
|
|
||||||
if (c.active_recharge_mask != 0 && c.is_human && c.refuel_sound_cd <= 0.0f) {
|
if (c.active_recharge_mask != 0) {
|
||||||
c.refuel_sound_cd = 0.38f;
|
c.pit_fill_ratio = std::clamp(min_fill, 0.0f, 1.0f);
|
||||||
events_.push_back({SimSoundCue::Refuel, c.curr_pose.pos, c.player_index, "", 0.0f});
|
}
|
||||||
|
if (c.is_human && prev_charging != 0 && c.active_recharge_mask == 0 && c.on_pit_mask != 0) {
|
||||||
|
events_.push_back({SimSoundCue::PitComplete, Vec3(0.0f, 0.0f, 0.0f), c.player_index, "", 0.0f});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,20 +668,13 @@ void RaceSim::activate_group(uint16_t group, int actor_player, bool allow_banner
|
|||||||
|
|
||||||
// 2. Spawn group environmental effects (explosions, steam jets, blast hazards)
|
// 2. Spawn group environmental effects (explosions, steam jets, blast hazards)
|
||||||
bool emitted_explosion_sfx = false;
|
bool emitted_explosion_sfx = false;
|
||||||
for (const auto& ef : level_.effects) {
|
for (size_t ei = 0; ei < level_.effects.size(); ++ei) {
|
||||||
|
const auto& ef = level_.effects[ei];
|
||||||
if (ef.group != group) continue;
|
if (ef.group != group) continue;
|
||||||
float gy = level_.sample_height_world(ef.x, ef.z);
|
float gy = level_.sample_height_world(ef.x, ef.z);
|
||||||
Vec3 epos(ef.x, gy + 0.45f, ef.z);
|
Vec3 epos(ef.x, gy + 0.45f, ef.z);
|
||||||
if (ef.subtype == 1 || ef.subtype == 3) {
|
if (ef.subtype == 1 || ef.subtype == 3) {
|
||||||
for (int k = 0; k < 10; ++k) {
|
spawn_explosion_fx(particles_, epos, 1.25f);
|
||||||
float ang = kTwoPi * (static_cast<float>(k) / 10.0f);
|
|
||||||
float spd = 1.6f + static_cast<float>((k * 37) % 10) * 0.28f;
|
|
||||||
Vec3 v(std::cos(ang) * spd, 1.4f + static_cast<float>(k % 3) * 0.9f,
|
|
||||||
std::sin(ang) * spd);
|
|
||||||
Vec4 col = (k % 2 == 0) ? Vec4(1.0f, 0.65f, 0.15f, 1.0f)
|
|
||||||
: Vec4(1.0f, 0.25f, 0.05f, 1.0f);
|
|
||||||
particles_.push_back({epos, v, 0.65f, col, 0.50f, 0.50f});
|
|
||||||
}
|
|
||||||
if (!emitted_explosion_sfx) {
|
if (!emitted_explosion_sfx) {
|
||||||
events_.push_back({SimSoundCue::Explosion, epos, actor_player, "", 0.40f});
|
events_.push_back({SimSoundCue::Explosion, epos, actor_player, "", 0.40f});
|
||||||
emitted_explosion_sfx = true;
|
emitted_explosion_sfx = true;
|
||||||
@@ -615,17 +683,17 @@ void RaceSim::activate_group(uint16_t group, int actor_player, bool allow_banner
|
|||||||
int count = (ef.subtype == 5) ? 6 : 3;
|
int count = (ef.subtype == 5) ? 6 : 3;
|
||||||
for (int k = 0; k < count; ++k) {
|
for (int k = 0; k < count; ++k) {
|
||||||
float ang = kTwoPi * (static_cast<float>(k) / static_cast<float>(count));
|
float ang = kTwoPi * (static_cast<float>(k) / static_cast<float>(count));
|
||||||
Vec3 v(std::cos(ang) * 0.5f, 2.2f + static_cast<float>(k % 2) * 0.8f,
|
Vec3 v(std::cos(ang) * 0.65f, 2.6f + static_cast<float>(k % 2) * 0.9f,
|
||||||
std::sin(ang) * 0.5f);
|
std::sin(ang) * 0.65f);
|
||||||
particles_.push_back({Vec3(ef.x, gy + 0.35f, ef.z), v,
|
spawn_smoke_puff(particles_, Vec3(ef.x, gy + 0.35f, ef.z), v,
|
||||||
0.48f, Vec4(0.85f, 0.92f, 1.0f, 0.72f), 0.45f, 0.45f});
|
0.42f, 1.85f, Vec4(0.84f, 0.88f, 0.92f, 0.66f),
|
||||||
|
1.15f, 1.6f, 0.9f, static_cast<float>(k) / static_cast<float>(count));
|
||||||
|
}
|
||||||
|
if (ei < steam_vent_timers_.size()) {
|
||||||
|
steam_vent_timers_[ei] = (ef.subtype == 5) ? 4.0f : 3.0f;
|
||||||
}
|
}
|
||||||
} else if (ef.subtype == 2) {
|
} else if (ef.subtype == 2) {
|
||||||
for (int k = 0; k < 6; ++k) {
|
spawn_explosion_fx(particles_, epos, 0.75f);
|
||||||
float ang = kTwoPi * (static_cast<float>(k) / 6.0f);
|
|
||||||
particles_.push_back({epos, Vec3(std::cos(ang) * 1.4f, 1.5f, std::sin(ang) * 1.4f),
|
|
||||||
0.45f, Vec4(1.0f, 0.45f, 0.15f, 0.9f), 0.35f, 0.35f});
|
|
||||||
}
|
|
||||||
if (setup_.damage_enabled) {
|
if (setup_.damage_enabled) {
|
||||||
for (auto& c : crafts_) {
|
for (auto& c : crafts_) {
|
||||||
if (c.recovery_state != RecoveryState::Active) continue;
|
if (c.recovery_state != RecoveryState::Active) continue;
|
||||||
@@ -1046,16 +1114,88 @@ void RaceSim::finalize_unfinished_times(const std::vector<size_t>& order) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RaceSim::update_steam_vents(float dt) {
|
||||||
|
const size_t n = std::min(level_.effects.size(), steam_vent_timers_.size());
|
||||||
|
for (size_t ei = 0; ei < n; ++ei) {
|
||||||
|
if (steam_vent_timers_[ei] <= 0.0f) continue;
|
||||||
|
steam_vent_timers_[ei] = std::max(0.0f, steam_vent_timers_[ei] - dt);
|
||||||
|
const auto& ef = level_.effects[ei];
|
||||||
|
uint32_t period = (ef.subtype == 5) ? 4u : 6u;
|
||||||
|
if (((fx_tick_ + static_cast<uint32_t>(ei)) % period) != 0u) continue;
|
||||||
|
float gy = level_.sample_height_world(ef.x, ef.z);
|
||||||
|
float phase = static_cast<float>((fx_tick_ * 17u + ei * 31u) % 100u) / 100.0f;
|
||||||
|
float ang = phase * kTwoPi;
|
||||||
|
float vy = 2.8f + phase * 1.2f;
|
||||||
|
Vec3 p(ef.x + std::cos(ang) * 0.15f, gy + 0.35f, ef.z + std::sin(ang) * 0.15f);
|
||||||
|
Vec3 v(std::cos(ang) * 0.45f, vy, std::sin(ang) * 0.45f);
|
||||||
|
spawn_smoke_puff(particles_, p, v, 0.38f, 1.80f,
|
||||||
|
Vec4(0.84f, 0.88f, 0.92f, 0.62f), 1.15f, 1.6f, 0.8f, phase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RaceSim::update_particles(float dt) {
|
void RaceSim::update_particles(float dt) {
|
||||||
for (auto& p : particles_) {
|
for (auto& p : particles_) {
|
||||||
|
if (p.base_alpha < 0.0f) {
|
||||||
|
p.base_alpha = p.color.w;
|
||||||
|
}
|
||||||
|
if (p.start_size <= 0.0f) {
|
||||||
|
p.start_size = p.size;
|
||||||
|
}
|
||||||
|
if (p.drag > 0.0f) {
|
||||||
|
p.vel *= std::max(0.0f, 1.0f - p.drag * dt);
|
||||||
|
}
|
||||||
|
if (p.gravity != 0.0f) {
|
||||||
|
p.vel.y += p.gravity * dt;
|
||||||
|
}
|
||||||
p.pos += p.vel * dt;
|
p.pos += p.vel * dt;
|
||||||
p.life -= dt;
|
p.life -= dt;
|
||||||
p.color.w = std::clamp(p.life / std::max(p.max_life, 0.01f), 0.0f, 1.0f);
|
|
||||||
|
float u = std::clamp(1.0f - p.life / std::max(p.max_life, 0.01f), 0.0f, 1.0f);
|
||||||
|
if (p.end_size > 0.0f) {
|
||||||
|
p.size = lerp(p.start_size, p.end_size, u);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (p.kind) {
|
||||||
|
case ParticleKind::Fireball: {
|
||||||
|
Vec3 c_white(1.0f, 0.97f, 0.78f);
|
||||||
|
Vec3 c_yellow(1.0f, 0.78f, 0.22f);
|
||||||
|
Vec3 c_orange(1.0f, 0.34f, 0.06f);
|
||||||
|
Vec3 c_crimson(0.55f, 0.08f, 0.02f);
|
||||||
|
Vec3 rgb;
|
||||||
|
if (u < 0.22f) {
|
||||||
|
rgb = lerp(c_white, c_yellow, u / 0.22f);
|
||||||
|
} else if (u < 0.58f) {
|
||||||
|
rgb = lerp(c_yellow, c_orange, (u - 0.22f) / 0.36f);
|
||||||
|
} else {
|
||||||
|
rgb = lerp(c_orange, c_crimson, (u - 0.58f) / 0.42f);
|
||||||
|
}
|
||||||
|
p.color.x = rgb.x;
|
||||||
|
p.color.y = rgb.y;
|
||||||
|
p.color.z = rgb.z;
|
||||||
|
p.color.w = p.base_alpha * std::max(0.0f, 1.0f - u * u);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ParticleKind::Smoke: {
|
||||||
|
float smooth_in = std::min(1.0f, u / 0.12f);
|
||||||
|
float smooth_out = (u > 0.48f) ? std::max(0.0f, 1.0f - (u - 0.48f) / 0.52f) : 1.0f;
|
||||||
|
p.color.w = p.base_alpha * smooth_in * smooth_out;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ParticleKind::Debris:
|
||||||
|
case ParticleKind::AdditiveGlow:
|
||||||
|
default:
|
||||||
|
p.color.w = p.base_alpha * std::max(0.0f, 1.0f - u);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
particles_.erase(
|
particles_.erase(
|
||||||
std::remove_if(particles_.begin(), particles_.end(),
|
std::remove_if(particles_.begin(), particles_.end(),
|
||||||
[](const ParticleBurst& p) { return p.life <= 0.0f; }),
|
[](const ParticleBurst& p) { return p.life <= 0.0f; }),
|
||||||
particles_.end());
|
particles_.end());
|
||||||
|
if (particles_.size() > kMaxParticles) {
|
||||||
|
size_t excess = particles_.size() - kMaxParticles;
|
||||||
|
particles_.erase(particles_.begin(), particles_.begin() + static_cast<ptrdiff_t>(excess));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CraftPose RaceSim::interpolated_clone_pose(float alpha) const {
|
CraftPose RaceSim::interpolated_clone_pose(float alpha) const {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ enum class SimSoundCue {
|
|||||||
Stunt360,
|
Stunt360,
|
||||||
Stunt720,
|
Stunt720,
|
||||||
SwitchTrigger,
|
SwitchTrigger,
|
||||||
|
PitComplete,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SimEvent {
|
struct SimEvent {
|
||||||
@@ -81,6 +82,13 @@ struct PropObject {
|
|||||||
float respawn_timer = 0.0f;
|
float respawn_timer = 0.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ParticleKind : uint8_t {
|
||||||
|
AdditiveGlow = 0, // Booster flare, minigun tracers, sparks
|
||||||
|
Fireball = 1, // Expanding turbulent fireball (white-yellow -> orange -> crimson)
|
||||||
|
Smoke = 2, // Alpha-blended billowing volumetric smoke cloud
|
||||||
|
Debris = 3, // Alpha-blended rotating charred shrapnel affected by gravity
|
||||||
|
};
|
||||||
|
|
||||||
struct ParticleBurst {
|
struct ParticleBurst {
|
||||||
Vec3 pos{0, 0, 0};
|
Vec3 pos{0, 0, 0};
|
||||||
Vec3 vel{0, 0, 0};
|
Vec3 vel{0, 0, 0};
|
||||||
@@ -88,6 +96,13 @@ struct ParticleBurst {
|
|||||||
Vec4 color{1.0f, 0.7f, 0.2f, 1.0f};
|
Vec4 color{1.0f, 0.7f, 0.2f, 1.0f};
|
||||||
float life = 0.5f;
|
float life = 0.5f;
|
||||||
float max_life = 0.5f;
|
float max_life = 0.5f;
|
||||||
|
ParticleKind kind = ParticleKind::AdditiveGlow;
|
||||||
|
float start_size = 0.0f; // 0 => use initial size
|
||||||
|
float end_size = 0.0f; // 0 => keep constant size
|
||||||
|
float drag = 0.0f; // velocity damping (1/sec)
|
||||||
|
float gravity = 0.0f; // vertical acceleration (+ rises, - falls)
|
||||||
|
float seed = 0.0f; // procedural puff variation [0..1]
|
||||||
|
float base_alpha = -1.0f; // <0 => initialized from color.w on first update
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CloneRecording {
|
struct CloneRecording {
|
||||||
@@ -131,6 +146,8 @@ struct RaceSetup {
|
|||||||
|
|
||||||
class RaceSim {
|
class RaceSim {
|
||||||
public:
|
public:
|
||||||
|
static constexpr size_t kMaxParticles = 900;
|
||||||
|
|
||||||
bool start_race(const assets::LevelData& level, const RaceSetup& setup,
|
bool start_race(const assets::LevelData& level, const RaceSetup& setup,
|
||||||
const CloneRecording* existing_clone = nullptr);
|
const CloneRecording* existing_clone = nullptr);
|
||||||
|
|
||||||
@@ -192,6 +209,7 @@ private:
|
|||||||
void activate_group(uint16_t group, int actor_player, bool allow_banner, bool fast_morph = false);
|
void activate_group(uint16_t group, int actor_player, bool allow_banner, bool fast_morph = false);
|
||||||
void update_standings();
|
void update_standings();
|
||||||
void finalize_unfinished_times(const std::vector<size_t>& order);
|
void finalize_unfinished_times(const std::vector<size_t>& order);
|
||||||
|
void update_steam_vents(float dt);
|
||||||
void update_particles(float dt);
|
void update_particles(float dt);
|
||||||
|
|
||||||
RaceSetup setup_{};
|
RaceSetup setup_{};
|
||||||
@@ -218,6 +236,8 @@ private:
|
|||||||
std::vector<DirtyRect> dirty_rects_;
|
std::vector<DirtyRect> dirty_rects_;
|
||||||
bool columns_dirty_ = false;
|
bool columns_dirty_ = false;
|
||||||
float morph_banner_cd_ = 0.0f;
|
float morph_banner_cd_ = 0.0f;
|
||||||
|
std::vector<float> steam_vent_timers_;
|
||||||
|
uint32_t fx_tick_ = 0;
|
||||||
|
|
||||||
// Clone race recording & playback
|
// Clone race recording & playback
|
||||||
CloneRecording recording_;
|
CloneRecording recording_;
|
||||||
|
|||||||
@@ -275,6 +275,30 @@ int main() {
|
|||||||
eng.stop_music();
|
eng.stop_music();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 7. Continuous pitstop REFUEL.WAV loop (charging, high-pitched standby, clean fade-out)
|
||||||
|
{
|
||||||
|
eng.stop_music();
|
||||||
|
eng.set_engine_state(false, 0.0f, false, 0.0f);
|
||||||
|
std::vector<float> pit_buf(12000 * 2, 0.0f);
|
||||||
|
|
||||||
|
eng.set_pitstop_state(true, true, 0.25f);
|
||||||
|
eng.mix_offline(pit_buf.data(), 12000);
|
||||||
|
BufferStats chg_st = measure_buffer(pit_buf, "Pitstop charging");
|
||||||
|
CHECK(chg_st.finite_ok && chg_st.rms > 0.01f);
|
||||||
|
|
||||||
|
eng.set_pitstop_state(true, false, 1.0f);
|
||||||
|
eng.mix_offline(pit_buf.data(), 12000);
|
||||||
|
BufferStats stdby_st = measure_buffer(pit_buf, "Pitstop standby");
|
||||||
|
CHECK(stdby_st.finite_ok && stdby_st.rms > 0.004f && stdby_st.rms < chg_st.rms);
|
||||||
|
|
||||||
|
eng.set_pitstop_state(false, false, 1.0f);
|
||||||
|
std::vector<float> fade_buf(4800 * 2, 0.0f);
|
||||||
|
eng.mix_offline(fade_buf.data(), 4800);
|
||||||
|
eng.mix_offline(pit_buf.data(), 12000);
|
||||||
|
BufferStats off_st = measure_buffer(pit_buf, "Pitstop off");
|
||||||
|
CHECK(off_st.finite_ok && off_st.rms < 0.001f);
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "[PASS] AudioEngine, OPL3 FM, SoundFont SBK, Normalization & Limiter validated\n";
|
std::cout << "[PASS] AudioEngine, OPL3 FM, SoundFont SBK, Normalization & Limiter validated\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+175
-5
@@ -671,25 +671,47 @@ int main() {
|
|||||||
p1.vel = Vec3(0, 0, 0);
|
p1.vel = Vec3(0, 0, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fuel bay (49.0, 79.0): recharges only fuel + emits Refuel sound
|
// Fuel bay (49.0, 79.0): recharges only fuel, updates on_pit_mask/pit_fill_ratio & emits PitComplete on 100%
|
||||||
p1.fuel = 20.0f;
|
p1.fuel = 20.0f;
|
||||||
p1.shield = 20.0f;
|
p1.shield = 20.0f;
|
||||||
p1.ammo = 20.0f;
|
p1.ammo = 20.0f;
|
||||||
p1.refuel_sound_cd = 0.0f;
|
|
||||||
place_p1(49.0f, 79.0f);
|
place_p1(49.0f, 79.0f);
|
||||||
psim.clear_events();
|
psim.clear_events();
|
||||||
bool saw_refuel_sfx = false;
|
float first_fill = 1.0f;
|
||||||
|
float mid_fill = 0.0f;
|
||||||
|
bool saw_pit_complete = false;
|
||||||
for (int t = 0; t < 60; ++t) {
|
for (int t = 0; t < 60; ++t) {
|
||||||
psim.step(CraftInput{}, CraftInput{}, dt);
|
psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
if (t == 0) {
|
||||||
|
CHECK(p1.on_pit_mask == 2u);
|
||||||
|
CHECK(p1.active_recharge_mask == 2u);
|
||||||
|
first_fill = p1.pit_fill_ratio;
|
||||||
|
}
|
||||||
|
if (t == 59) {
|
||||||
|
mid_fill = p1.pit_fill_ratio;
|
||||||
|
}
|
||||||
for (const auto& ev : psim.events()) {
|
for (const auto& ev : psim.events()) {
|
||||||
if (ev.sound == sim::SimSoundCue::Refuel) saw_refuel_sfx = true;
|
if (ev.sound == sim::SimSoundCue::PitComplete) saw_pit_complete = true;
|
||||||
}
|
}
|
||||||
psim.clear_events();
|
psim.clear_events();
|
||||||
}
|
}
|
||||||
CHECK(p1.fuel > 70.0f);
|
CHECK(p1.fuel > 70.0f);
|
||||||
CHECK(p1.shield == 20.0f);
|
CHECK(p1.shield == 20.0f);
|
||||||
CHECK(p1.ammo == 20.0f);
|
CHECK(p1.ammo == 20.0f);
|
||||||
CHECK(saw_refuel_sfx);
|
CHECK(mid_fill > first_fill && mid_fill < 1.0f);
|
||||||
|
|
||||||
|
// Continue on Fuel bay until full -> PitComplete emitted & active_recharge_mask clears while on_pit_mask stays 2
|
||||||
|
for (int t = 0; t < 70; ++t) {
|
||||||
|
psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
for (const auto& ev : psim.events()) {
|
||||||
|
if (ev.sound == sim::SimSoundCue::PitComplete) saw_pit_complete = true;
|
||||||
|
}
|
||||||
|
psim.clear_events();
|
||||||
|
}
|
||||||
|
CHECK(p1.fuel >= p1.max_fuel - 0.5f);
|
||||||
|
CHECK(p1.on_pit_mask == 2u);
|
||||||
|
CHECK(p1.active_recharge_mask == 0u);
|
||||||
|
CHECK(saw_pit_complete);
|
||||||
|
|
||||||
// Ammo bay (49.0, 85.0): recharges only ammo
|
// Ammo bay (49.0, 85.0): recharges only ammo
|
||||||
p1.fuel = 20.0f;
|
p1.fuel = 20.0f;
|
||||||
@@ -760,5 +782,153 @@ int main() {
|
|||||||
}
|
}
|
||||||
std::cout << "[PASS] Authentic pitstop Fuel/Shield/Ammo chargers verified across all 6 tracks\n";
|
std::cout << "[PASS] Authentic pitstop Fuel/Shield/Ammo chargers verified across all 6 tracks\n";
|
||||||
|
|
||||||
|
// 9. Original Explosions, Volumetric Smoke Trails, Wreck Plumes & Steam Vents
|
||||||
|
{
|
||||||
|
// 9a. Unguided missile smoke contrail + exhaust glow
|
||||||
|
{
|
||||||
|
sim::RaceSetup ms;
|
||||||
|
ms.mode = sim::GameMode::SingleRace;
|
||||||
|
ms.track_number = 1;
|
||||||
|
ms.num_ai = 0;
|
||||||
|
ms.fuel_enabled = false;
|
||||||
|
sim::RaceSim msim;
|
||||||
|
CHECK(msim.start_race(lvl1, ms));
|
||||||
|
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
|
||||||
|
auto& p1 = msim.crafts_mut()[0];
|
||||||
|
p1.lock_progress = 0.0f;
|
||||||
|
p1.lock_target_id = -1;
|
||||||
|
CraftInput fire;
|
||||||
|
fire.fire_missile = true;
|
||||||
|
msim.step(fire, CraftInput{}, dt);
|
||||||
|
for (int t = 0; t < 10; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
|
||||||
|
bool saw_smoke = false, saw_glow = false;
|
||||||
|
for (const auto& pb : msim.particles()) {
|
||||||
|
if (pb.kind == sim::ParticleKind::Smoke) saw_smoke = true;
|
||||||
|
if (pb.kind == sim::ParticleKind::AdditiveGlow) saw_glow = true;
|
||||||
|
}
|
||||||
|
CHECK(saw_smoke && saw_glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9b. Multi-layer explosion FX evolution (expanding smoke, falling debris) + kMaxParticles cap
|
||||||
|
{
|
||||||
|
sim::RaceSetup es;
|
||||||
|
es.mode = sim::GameMode::DeathMatch;
|
||||||
|
es.track_number = 1;
|
||||||
|
es.num_ai = 1;
|
||||||
|
es.fuel_enabled = false;
|
||||||
|
sim::RaceSim esim;
|
||||||
|
CHECK(esim.start_race(lvl1, es));
|
||||||
|
for (int t = 0; t < 200; ++t) esim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
|
||||||
|
auto& p1 = esim.crafts_mut()[0];
|
||||||
|
auto& tgt = esim.crafts_mut()[1];
|
||||||
|
tgt.curr_pose.pos = p1.curr_pose.pos + p1.forward_dir() * 4.0f;
|
||||||
|
tgt.prev_pose = tgt.curr_pose;
|
||||||
|
tgt.shield = 1.0f;
|
||||||
|
p1.lock_progress = 1.0f;
|
||||||
|
p1.lock_target_id = tgt.id;
|
||||||
|
|
||||||
|
CraftInput fire;
|
||||||
|
fire.fire_missile = true;
|
||||||
|
for (int t = 0; t < 20 && tgt.recovery_state == sim::RecoveryState::Active; ++t) {
|
||||||
|
esim.step(fire, CraftInput{}, dt);
|
||||||
|
fire.fire_missile = false;
|
||||||
|
}
|
||||||
|
CHECK(tgt.recovery_state == sim::RecoveryState::CallingRepair);
|
||||||
|
|
||||||
|
float max_smoke0 = 0.0f;
|
||||||
|
float min_debris_vy0 = 1e9f;
|
||||||
|
bool has_fireball = false, has_smoke = false, has_debris = false;
|
||||||
|
for (const auto& pb : esim.particles()) {
|
||||||
|
if (pb.kind == sim::ParticleKind::Fireball) has_fireball = true;
|
||||||
|
if (pb.kind == sim::ParticleKind::Smoke) {
|
||||||
|
has_smoke = true;
|
||||||
|
max_smoke0 = std::max(max_smoke0, pb.size);
|
||||||
|
}
|
||||||
|
if (pb.kind == sim::ParticleKind::Debris) {
|
||||||
|
has_debris = true;
|
||||||
|
min_debris_vy0 = std::min(min_debris_vy0, pb.vel.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CHECK(has_fireball && has_smoke && has_debris);
|
||||||
|
|
||||||
|
for (int t = 0; t < 6; ++t) esim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
float max_smoke1 = 0.0f;
|
||||||
|
float min_debris_vy1 = 1e9f;
|
||||||
|
for (const auto& pb : esim.particles()) {
|
||||||
|
if (pb.kind == sim::ParticleKind::Smoke) max_smoke1 = std::max(max_smoke1, pb.size);
|
||||||
|
if (pb.kind == sim::ParticleKind::Debris) min_debris_vy1 = std::min(min_debris_vy1, pb.vel.y);
|
||||||
|
}
|
||||||
|
CHECK(max_smoke1 > max_smoke0);
|
||||||
|
CHECK(min_debris_vy1 < min_debris_vy0);
|
||||||
|
|
||||||
|
// Wreck plume continues emitting Fireball & Smoke long after initial explosion fades
|
||||||
|
for (int t = 0; t < 55; ++t) esim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
CHECK(tgt.recovery_state != sim::RecoveryState::Active);
|
||||||
|
bool wreck_fire = false, wreck_smoke = false;
|
||||||
|
for (int t = 0; t < 25; ++t) {
|
||||||
|
esim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
for (const auto& pb : esim.particles()) {
|
||||||
|
if (pb.kind == sim::ParticleKind::Fireball) wreck_fire = true;
|
||||||
|
if (pb.kind == sim::ParticleKind::Smoke) wreck_smoke = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CHECK(wreck_fire && wreck_smoke);
|
||||||
|
|
||||||
|
// Rapid wall-missile spam stays within kMaxParticles
|
||||||
|
for (int t = 0; t < 35; ++t) {
|
||||||
|
p1.missile_cd = 0.0f;
|
||||||
|
p1.ammo = p1.max_ammo;
|
||||||
|
CraftInput spam;
|
||||||
|
spam.fire_missile = true;
|
||||||
|
esim.step(spam, CraftInput{}, dt);
|
||||||
|
}
|
||||||
|
CHECK(esim.particles().size() <= sim::RaceSim::kMaxParticles);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9c. Damaged craft smoke trail & Level 4 continuous steam vent
|
||||||
|
{
|
||||||
|
assets::LevelData lvl4;
|
||||||
|
CHECK(lvl4.load(vfs, 4));
|
||||||
|
sim::RaceSetup ss;
|
||||||
|
ss.mode = sim::GameMode::SingleRace;
|
||||||
|
ss.track_number = 4;
|
||||||
|
ss.num_ai = 0;
|
||||||
|
ss.fuel_enabled = false;
|
||||||
|
sim::RaceSim ssim;
|
||||||
|
CHECK(ssim.start_race(lvl4, ss));
|
||||||
|
for (int t = 0; t < 200; ++t) ssim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
|
||||||
|
auto& p1 = ssim.crafts_mut()[0];
|
||||||
|
p1.shield = p1.max_shield * 0.15f;
|
||||||
|
for (int t = 0; t < 15; ++t) ssim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
bool damaged_smoke = false;
|
||||||
|
for (const auto& pb : ssim.particles()) {
|
||||||
|
if (pb.kind == sim::ParticleKind::Smoke) damaged_smoke = true;
|
||||||
|
}
|
||||||
|
CHECK(damaged_smoke);
|
||||||
|
|
||||||
|
// Restore full shield, trigger Level 4 group 6 steam vents via (11.5, 77.5)
|
||||||
|
p1.shield = p1.max_shield;
|
||||||
|
for (int t = 0; t < 80; ++t) ssim.step(CraftInput{}, CraftInput{}, dt); // let old smoke expire
|
||||||
|
p1.curr_pose.pos = Vec3(11.5f, ssim.level().sample_height_world(11.5f, 77.5f) + 0.30f, 77.5f);
|
||||||
|
p1.prev_pose = p1.curr_pose;
|
||||||
|
p1.vel = Vec3(0, 0, 0);
|
||||||
|
ssim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
CHECK(!ssim.particles().empty());
|
||||||
|
|
||||||
|
// After 1.5s (> 1.15s initial puff lifetime), continuous steam vent still emits Smoke
|
||||||
|
for (int t = 0; t < 90; ++t) ssim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
bool continuous_steam = false;
|
||||||
|
for (const auto& pb : ssim.particles()) {
|
||||||
|
if (pb.kind == sim::ParticleKind::Smoke) continuous_steam = true;
|
||||||
|
}
|
||||||
|
CHECK(continuous_steam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "[PASS] Original explosions, smoke trails, wreck plumes & steam vents validated\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -37,16 +37,23 @@ int main() {
|
|||||||
CHECK(!geo.column_indices.empty());
|
CHECK(!geo.column_indices.empty());
|
||||||
CHECK(geo.column_indices.size() % 6 == 0);
|
CHECK(geo.column_indices.size() % 6 == 0);
|
||||||
|
|
||||||
|
bool has_open_ao = false;
|
||||||
|
bool has_crevice_ao = false;
|
||||||
for (const auto& v : geo.terrain_verts) {
|
for (const auto& v : geo.terrain_verts) {
|
||||||
CHECK(std::isfinite(v.pos.x) && std::isfinite(v.pos.y) && std::isfinite(v.pos.z));
|
CHECK(std::isfinite(v.pos.x) && std::isfinite(v.pos.y) && std::isfinite(v.pos.z));
|
||||||
CHECK(v.tile >= 0.0f && v.tile < 256.0f);
|
CHECK(v.tile >= 0.0f && v.tile < 256.0f);
|
||||||
CHECK(v.light >= 0.25f && v.light <= 1.5f);
|
CHECK(v.light >= 0.25f && v.light <= 1.5f);
|
||||||
|
CHECK(std::isfinite(v.ao) && v.ao >= 0.65f && v.ao <= 1.01f);
|
||||||
CHECK(v.u >= -1e-4f && v.u <= 1.0001f);
|
CHECK(v.u >= -1e-4f && v.u <= 1.0001f);
|
||||||
CHECK(v.v >= -1e-4f && v.v <= 1.0001f);
|
CHECK(v.v >= -1e-4f && v.v <= 1.0001f);
|
||||||
|
if (v.ao > 0.99f) has_open_ao = true;
|
||||||
|
if (v.ao < 0.95f) has_crevice_ao = true;
|
||||||
}
|
}
|
||||||
|
CHECK(has_open_ao && has_crevice_ao);
|
||||||
for (const auto& v : geo.column_verts) {
|
for (const auto& v : geo.column_verts) {
|
||||||
CHECK(std::isfinite(v.pos.x) && std::isfinite(v.pos.y) && std::isfinite(v.pos.z));
|
CHECK(std::isfinite(v.pos.x) && std::isfinite(v.pos.y) && std::isfinite(v.pos.z));
|
||||||
CHECK(v.tile >= 0.0f && v.tile < 256.0f);
|
CHECK(v.tile >= 0.0f && v.tile < 256.0f);
|
||||||
|
CHECK(std::isfinite(v.ao) && v.ao >= 0.65f && v.ao <= 1.01f);
|
||||||
CHECK(v.u >= -1e-4f && v.u <= 1.0001f);
|
CHECK(v.u >= -1e-4f && v.u <= 1.0001f);
|
||||||
CHECK(v.v >= -1e-4f && v.v <= 1.0001f);
|
CHECK(v.v >= -1e-4f && v.v <= 1.0001f);
|
||||||
}
|
}
|
||||||
@@ -135,6 +142,28 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify PANEL0-1 authentic HUD sprites referenced in GameApp::render_hud_viewport
|
||||||
|
{
|
||||||
|
assets::SpriteBank panel_bank;
|
||||||
|
CHECK(panel_bank.load(vfs, "DATA/PANEL0-1.DAT", "DATA/PANEL0-1.TAB", pal));
|
||||||
|
auto check_range = [&](int a, int b) -> bool {
|
||||||
|
for (int idx = a; idx <= b; ++idx) {
|
||||||
|
if (idx < 0 || static_cast<size_t>(idx) >= panel_bank.sprites.size()) return false;
|
||||||
|
const auto& sp = panel_bank.sprites[idx];
|
||||||
|
if (sp.width <= 2 || sp.height <= 2 || sp.rgba.empty()) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
CHECK(check_range(1, 77));
|
||||||
|
CHECK(check_range(86, 162));
|
||||||
|
CHECK(check_range(198, 199));
|
||||||
|
CHECK(check_range(227, 228));
|
||||||
|
CHECK(check_range(258, 268));
|
||||||
|
CHECK(check_range(270, 271));
|
||||||
|
CHECK(check_range(273, 276));
|
||||||
|
CHECK(check_range(281, 286));
|
||||||
|
}
|
||||||
|
|
||||||
// Verify 3D model GPU geometry conversion
|
// Verify 3D model GPU geometry conversion
|
||||||
assets::ObjectTextureAtlas atlas;
|
assets::ObjectTextureAtlas atlas;
|
||||||
CHECK(atlas.load(vfs, pal));
|
CHECK(atlas.load(vfs, pal));
|
||||||
|
|||||||
Reference in new issue
Block a user