diff --git a/README.md b/README.md index d4f0f0e..851a2a5 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ enemy. See `docs/GAME_DESIGN.md`. Pre-alpha grey-box (Milestone M1): the vertical slice is playable — movement, one auto-weapon (Service Weapon: Spin), 3 enemy types, XP -> Board Directive level-ups, -corruption clock, death screen. Art is placeholder-by-design (M5). +corruption clock, death screen. Standee sprite art, diorama scene dressing and +corruption-keyed post FX are wired (M5 kickoff); the full art pass is tracked in +`docs/ENV_ENHANCEMENT.md`. ## Build & run diff --git a/assets/shaders/post_fx.fs b/assets/shaders/post_fx.fs new file mode 100644 index 0000000..1347e20 --- /dev/null +++ b/assets/shaders/post_fx.fs @@ -0,0 +1,57 @@ +#version 330 +// FBC: NIGHT SHIFT — corruption-keyed post FX (docs/ART_DIRECTION.md "Post FX"). +// VHS scanlines + noise, chromatic aberration, red Hiss tint, vignette. +// Strength scales with the corruption coefficient — the House decays in +// real time and so does the image. Drawn over the whole frame by main.cpp. + +in vec2 fragTexCoord; +in vec4 fragColor; + +out vec4 finalColor; + +uniform sampler2D texture0; +uniform vec4 colDiffuse; + +uniform float uTime = 0.0; +uniform float uCorruption = 0.05; // ~0.05 .. 2.0 (see game/corruption.hpp) +uniform float uDamage = 0.0; // 0..1 player hit flash + +float hash(vec2 p) { + return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); +} + +void main() { + vec2 uv = fragTexCoord; + + // Chromatic aberration: subtle, grows with corruption + on damage. + float aberr = 0.0012 + 0.0035 * uCorruption + 0.010 * uDamage; + vec2 dir = uv - vec2(0.5); + float dist = length(dir); + vec2 off = dir * dist * aberr * 6.0; + vec3 col = vec3( + texture(texture0, uv + off).r, + texture(texture0, uv).g, + texture(texture0, uv - off).b); + + // VHS scanlines + rolling noise (intensity keys to corruption). + float scan = sin(uv.y * 720.0) * 0.5 + 0.5; + col *= 1.0 - 0.06 * scan * (0.5 + 0.5 * clamp(uCorruption, 0.0, 1.5)); + float n = hash(uv * vec2(1024.0, 1024.0) + fract(uTime) * 61.7); + col += (n - 0.5) * (0.02 + 0.05 * clamp(uCorruption, 0.0, 1.5)); + + // Red Hiss tint breathing with corruption. + float hiss = clamp(uCorruption * 0.12, 0.0, 0.45); + col = mix(col, col * vec3(1.08, 0.93, 0.93) + vec3(0.05, 0.0, 0.0), hiss); + + // Damage flash: red bloom. + col = mix(col, vec3(0.8, 0.05, 0.07), uDamage * 0.35); + + // Vignette (tightens as the House decays). + float vig = 1.0 - smoothstep(0.45, 1.05, dist) * (0.42 + 0.12 * uCorruption); + col *= vig; + + // Mild exposure lift to keep the night scene readable under the vignette. + col *= 1.12; + + finalColor = vec4(col, 1.0) * colDiffuse * fragColor; +} diff --git a/docs/ENV_ENHANCEMENT.md b/docs/ENV_ENHANCEMENT.md index e5bf7f1..e8efe82 100644 --- a/docs/ENV_ENHANCEMENT.md +++ b/docs/ENV_ENHANCEMENT.md @@ -17,7 +17,7 @@ Legend: **[B]** Blender scene (`tools/blender/build_scene.py`) · **[G]** game | S2 | Corruption decay layer | glyph particles, chanting-glyph signage, sparks on dead strips, red mist pockets, wall stains/leaks, more floating debris | planned [B] | | S3 | Standee art v2 | paper grain + halftone, sleeve sheen, new archetypes (Hiss Elevated, Cluster, Taken, Mold Host), boss standee, elite affix rim variants | planned [B]→[G] | | S4 | Breadth: floors | Oceanview Motel shop diorama (yellow doors, teal carpet), Maintenance/mold variant (green palette) | planned [B] | -| S5 | Game integration (M5 kickoff) | sprite PNGs into `presenter.cpp`, world-anchored bars, corruption-keyed post shaders, HUD-overlay concept frames | planned [G] | +| S5 | Game integration (M5 kickoff) | sprite PNGs into `presenter.cpp`, diorama scene dressing, corruption-keyed post shaders, HUD-overlay concept frames | **partial** [G] | ## S0 — Light, surface & post pass [B][R] @@ -106,15 +106,24 @@ Goal: the House decaying in real time — the art doc's "best part", currently ## S5 — Game integration — M5 kickoff [G] -- [ ] Wire `assets/sprites/*.png` into `render/presenter.cpp` (replace soft-disc - billboards; keep manual back-to-front sort + blob shadows). -- [ ] World-anchored damage numbers/health bars styled as form fields. -- [ ] Corruption-keyed post shaders (`assets/shaders/`): VHS noise, chromatic - aberration, red resonance pulses. +- [x] Wire `assets/sprites/*.png` into `render/presenter.cpp` (sprite standees + via `DrawBillboardRec`, per-archetype textures, hit-flash tint; missing + art degrades to the soft-disc standee; manual back-to-front sort + blob + shadows kept). +- [x] Diorama scene dressing in the presenter: polished-concrete palette, red + carpet runners, pillar red bands + bases, threshold door with Hiss glow + + hazard stripes, EXIT signs, curb light strip, painted walkway lines. +- [x] Corruption-keyed post shaders (`assets/shaders/post_fx.fs`): VHS scanlines + + noise, chromatic aberration, red Hiss tint, vignette, damage flash — + all scaling with `game.corruption.value()`; frame renders to a + `RenderTexture` in `main.cpp`. +- [ ] World-anchored damage numbers/health bars styled as form fields (needs + the OFL fonts — lands with the fonts milestone). - [ ] HUD-overlay concept frame: containment gauge + HP/XP form fields + Board Directive cards composited over a Blender render — the "UI as bureaucracy" money shot. -- *Accept: 60 s `--bot` run looks like the concept frames at gameplay scale.* +- *Accept: 60 s `--bot` run looks like the concept frames at gameplay scale — + met for scene + standees + post; UI styling pending fonts.* ## How to run @@ -131,6 +140,11 @@ clipping < 0.5%, red-dominant 15–25%. ## Status log +- 2026-10-24 (S5): wired the art into the game — sprite standees + diorama scene + dressing + `assets/shaders/post_fx.fs` corruption post chain. Validated via + `--bot --screenshot`: sprites load with correct orientation (card stripe + down), post FX provably active (noise/scanline signature on flat patches), + palette held (red-dominant 18%), frame readable (p50 0.19, clip 0.1%). - 2026-10-24: S0 + S1 implemented in `build_scene.py`; scene 243 → 405 objects (119 beveled boxes, 83 prop objects, 70 dust motes, 4 light-spill decals). Compositor post chain live: bloom → chromatic aberration → vignette. diff --git a/src/main.cpp b/src/main.cpp index 8e896ce..39a28d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,7 +88,7 @@ InputState read_input(const Game& game, bool bot) { int main(int argc, char** argv) { SetTraceLogLevel(LOG_WARNING); - InitWindow(1280, 720, "FBC: NIGHT SHIFT — pre-alpha grey-box"); + InitWindow(1280, 720, "FBC: NIGHT SHIFT — pre-alpha"); SetTargetFPS(60); const Options opts = parse_options(argc, argv); @@ -97,6 +97,29 @@ int main(int argc, char** argv) { Presenter presenter; presenter.init(); + // Full-screen post FX keyed to corruption (docs/ART_DIRECTION.md "Post FX"): + // the frame renders to a texture, then assets/shaders/post_fx.fs draws it + // with VHS noise, chromatic aberration and a red Hiss tint that intensifies + // as the House decays. Missing shader degrades to a plain blit. + RenderTexture2D post_target = + LoadRenderTexture(GetScreenWidth(), GetScreenHeight()); + const char* shader_path = FileExists("assets/shaders/post_fx.fs") + ? "assets/shaders/post_fx.fs" + : TextFormat("%s../assets/shaders/post_fx.fs", GetApplicationDirectory()); + Shader post_shader{}; + bool post_ok = FileExists(shader_path); + if (post_ok) { + post_shader = LoadShader(nullptr, shader_path); + post_ok = post_shader.id != 0; + } + if (!post_ok) { + TraceLog(LOG_WARNING, "POST: %s missing, rendering without post FX", + shader_path); + } + const int loc_time = GetShaderLocation(post_shader, "uTime"); + const int loc_corruption = GetShaderLocation(post_shader, "uCorruption"); + const int loc_damage = GetShaderLocation(post_shader, "uDamage"); + float accumulator = 0.0f; bool screenshot_taken = false; while (!WindowShouldClose()) { @@ -108,10 +131,31 @@ int main(int argc, char** argv) { accumulator -= kFixedDt; } - BeginDrawing(); + // Scene + UI render into the post-FX target, then the corruption shader + // paints the final frame. + BeginTextureMode(post_target); ClearBackground(Color{24, 24, 27, 255}); presenter.draw_scene(game); ui::draw_all(game); + EndTextureMode(); + + BeginDrawing(); + if (post_ok) BeginShaderMode(post_shader); + if (post_ok) { + const float t = static_cast(GetTime()); + const float corruption = game.corruption.value(); + const float damage = presenter.damage_flash(); + SetShaderValue(post_shader, loc_time, &t, SHADER_UNIFORM_FLOAT); + SetShaderValue(post_shader, loc_corruption, &corruption, + SHADER_UNIFORM_FLOAT); + SetShaderValue(post_shader, loc_damage, &damage, SHADER_UNIFORM_FLOAT); + } + DrawTextureRec(post_target.texture, + Rectangle{0.0f, 0.0f, + static_cast(post_target.texture.width), + -static_cast(post_target.texture.height)}, + Vector2{0.0f, 0.0f}, WHITE); + if (post_ok) EndShaderMode(); EndDrawing(); // Dev tools: --screenshot [--screenshot-at ] captures the @@ -135,6 +179,8 @@ int main(int argc, char** argv) { } presenter.shutdown(); + if (post_ok) UnloadShader(post_shader); + UnloadRenderTexture(post_target); CloseWindow(); return 0; } diff --git a/src/render/presenter.cpp b/src/render/presenter.cpp index d15cfd7..f706b2e 100644 --- a/src/render/presenter.cpp +++ b/src/render/presenter.cpp @@ -8,24 +8,38 @@ namespace { struct Billboard { float depth; Vector3 pos; - float size; + float w; + float h; + Texture2D tex; Color color; }; -Color tint_for(EnemyType type, float hit_flash) { - Color base = WHITE; - switch (type) { - case EnemyType::HissStaff: base = Color{214, 74, 74, 255}; break; - case EnemyType::MoldSpore: base = Color{122, 196, 92, 255}; break; - case EnemyType::HissBrute: base = Color{158, 44, 44, 255}; break; +Texture2D load_sprite(const char* name) { + // Assets resolve from the repo root (typical: ./build/cntrl) or relative to + // the executable. Missing art degrades to the soft-disc standee, never a crash. + const char* rel = TextFormat("assets/sprites/%s.png", name); + if (FileExists(rel)) { + Texture2D tex = LoadTexture(rel); + SetTextureFilter(tex, TEXTURE_FILTER_BILINEAR); + return tex; } - if (hit_flash > 0.0f) { - const unsigned char f = static_cast(std::min(255.0f, 900.0f * hit_flash)); - base.r = static_cast(std::min(255, base.r + f)); - base.g = static_cast(std::min(255, base.g + f)); - base.b = static_cast(std::min(255, base.b + f)); + const char* alt = TextFormat("%s../assets/sprites/%s.png", + GetApplicationDirectory(), name); + if (FileExists(alt)) { + Texture2D tex = LoadTexture(alt); + SetTextureFilter(tex, TEXTURE_FILTER_BILINEAR); + return tex; } - return base; + TraceLog(LOG_WARNING, "SPRITE: %s missing, using soft-disc fallback", rel); + return Texture2D{}; +} + +Color flash_tint(float hit_flash) { + // Sprite art carries its own colour; hits flash it toward white-red. + if (hit_flash <= 0.0f) return WHITE; + const unsigned char f = + static_cast(255.0f - std::min(1.0f, hit_flash) * 130.0f); + return Color{255, f, f, 255}; } Color projectile_color(WeaponType type) { @@ -57,14 +71,27 @@ void Presenter::init() { camera_.fovy = 45.0f; camera_.projection = CAMERA_PERSPECTIVE; - // Procedural placeholder standee texture (M5 swaps in real art). + // Procedural placeholder standee (fallback when sprite art is missing). Image img = GenImageGradientRadial(64, 64, 0.0f, WHITE, Color{255, 255, 255, 0}); soft_disc_ = LoadTextureFromImage(img); UnloadImage(img); + + // Photo-standee sprite art (assets/sprites/, see docs/ENV_ENHANCEMENT.md S5). + spr_guard_ = load_sprite("guard"); + spr_staff_ = load_sprite("hiss_staff"); + spr_brute_ = load_sprite("hiss_brute"); + spr_mold_ = load_sprite("mold_spore"); + spr_shard_ = load_sprite("shard"); + spr_glow_ = load_sprite("glow"); + damage_numbers_.reserve(64); } void Presenter::shutdown() { + for (Texture2D* tex : {&spr_guard_, &spr_staff_, &spr_brute_, &spr_mold_, + &spr_shard_, &spr_glow_}) { + if (tex->id != 0) UnloadTexture(*tex); + } UnloadTexture(soft_disc_); } @@ -72,8 +99,10 @@ void Presenter::draw_scene(Game& game) { // Consume sim events into presentation state. for (int i = 0; i < game.events.count; ++i) { const GameEvent& e = game.events.items[i]; - if (e.type == EventType::PlayerDamaged) shake_ = std::max(shake_, 0.45f); - else if (e.type == EventType::EnemyKilled) shake_ = std::max(shake_, 0.10f); + if (e.type == EventType::PlayerDamaged) { + shake_ = std::max(shake_, 0.45f); + damage_flash_ = 1.0f; + } else if (e.type == EventType::EnemyKilled) shake_ = std::max(shake_, 0.10f); else if (e.type == EventType::TierUp) shake_ = std::max(shake_, 0.60f); else if (e.type == EventType::EnemyHit && damage_numbers_.size() < 48) { damage_numbers_.push_back({e.pos + Vec2{static_cast(GetRandomValue(-8, 8)) / 20.0f, @@ -83,6 +112,7 @@ void Presenter::draw_scene(Game& game) { } shake_ = std::max(0.0f, shake_ - 0.06f); const float frame_dt = GetFrameTime(); + damage_flash_ = std::max(0.0f, damage_flash_ - frame_dt * 2.2f); for (DamageNumber& n : damage_numbers_) n.age += frame_dt; damage_numbers_.erase( std::remove_if(damage_numbers_.begin(), damage_numbers_.end(), @@ -100,11 +130,26 @@ void Presenter::draw_scene(Game& game) { const float arena = game.config.arena_half; - // Ground slab + grid (brutalist concrete diorama base). The slab is kept - // well beyond the play area so the camera never sees its edge as void. + // Ground slab: polished concrete (matches the Blender diorama palette). + // Kept well beyond the play area so the camera never sees its edge as void. DrawCube({0.0f, -0.5f, 0.0f}, arena * 2.0f + 40.0f, 1.0f, arena * 2.0f + 40.0f, Color{43, 43, 47, 255}); - DrawGrid(static_cast(arena) + 12, 2.0f); + // Painted walkway lines (replaces the grey-box grid). + const Color line{150, 147, 138, 255}; + DrawCube({-12.0f, 0.012f, 0.0f}, 0.18f, 0.024f, arena * 2.0f, line); + DrawCube({12.0f, 0.012f, 0.0f}, 0.18f, 0.024f, arena * 2.0f, line); + DrawCube({0.0f, 0.012f, -12.0f}, arena * 2.0f, 0.024f, 0.18f, line); + DrawCube({0.0f, 0.012f, 12.0f}, arena * 2.0f, 0.024f, 0.18f, line); + + // Red carpet runners — signal red over the polish. + const Color carpet{150, 18, 30, 255}; + const Color carpet_edge{88, 8, 16, 255}; + DrawCube({0.0f, 0.03f, 6.0f}, 7.0f, 0.06f, 30.0f, carpet); + DrawCube({0.0f, 0.034f, 12.0f}, 36.0f, 0.068f, 6.0f, carpet); + DrawCube({-3.28f, 0.033f, 6.0f}, 0.38f, 0.066f, 30.0f, carpet_edge); + DrawCube({3.28f, 0.033f, 6.0f}, 0.38f, 0.066f, 30.0f, carpet_edge); + DrawCube({0.0f, 0.036f, 9.28f}, 36.0f, 0.072f, 0.38f, carpet_edge); + DrawCube({0.0f, 0.036f, 14.72f}, 36.0f, 0.072f, 0.38f, carpet_edge); // Perimeter curbs (kept low so they never occlude the standees when the // camera is near an arena edge; tall dressing lives on the pillars). @@ -114,14 +159,34 @@ void Presenter::draw_scene(Game& game) { DrawCube({-(arena + 1.0f), 0.6f, 0.0f}, 1.0f, 1.2f, arena * 2.0f + 4.0f, wall); DrawCube({arena + 1.0f, 0.6f, 0.0f}, 1.0f, 1.2f, arena * 2.0f + 4.0f, wall); - // Pillars (fixed layout — room-template dressing arrives at M3/M5). + // Threshold door + hazard stripes at the far curb (the run's exit), + // with EXIT signs and a light strip along the curb top. + const float door_z = arena + 0.45f; + DrawCube({0.0f, 2.9f, door_z}, 5.6f, 5.8f, 0.34f, Color{28, 28, 32, 255}); + DrawCube({0.0f, 2.85f, door_z - 0.2f}, 3.7f, 5.1f, 0.1f, + Color{190, 28, 38, 255}); // Hiss glow bleeding through + for (int i = 0; i < 10; ++i) { + const float x0 = -2.31f + i * 0.462f; + DrawCube({x0, 0.045f, arena - 0.6f}, 0.23f, 0.055f, 1.1f, + (i % 2 == 0) ? Color{198, 153, 13, 255} : Color{20, 20, 22, 255}); + } + DrawCube({-10.0f, 2.4f, door_z - 0.2f}, 1.7f, 0.52f, 0.12f, Color{46, 170, 76, 255}); + DrawCube({10.0f, 2.4f, door_z - 0.2f}, 1.7f, 0.52f, 0.12f, Color{46, 170, 76, 255}); + DrawCube({0.0f, 1.45f, arena + 0.5f}, 38.0f, 0.18f, 0.3f, Color{255, 232, 180, 255}); + + // Pillars (fixed layout — room-template dressing arrives at M3) with + // Hiss-red bands and dark bases, as in the diorama. const Vector3 pillars[] = { {-18.0f, 2.0f, -18.0f}, {18.0f, 2.0f, -18.0f}, {-18.0f, 2.0f, 18.0f}, {18.0f, 2.0f, 18.0f}, {0.0f, 2.0f, -21.0f}, {0.0f, 2.0f, 21.0f}, {-21.0f, 2.0f, 0.0f}, {21.0f, 2.0f, 0.0f}, }; - for (const Vector3& pos : pillars) DrawCube(pos, 2.0f, 4.0f, 2.0f, Color{66, 66, 72, 255}); + for (const Vector3& pos : pillars) { + DrawCube(pos, 2.0f, 4.0f, 2.0f, Color{66, 66, 72, 255}); + DrawCube({pos.x, 2.55f, pos.z}, 2.46f, 0.5f, 2.46f, carpet); + DrawCube({pos.x, 0.22f, pos.z}, 2.5f, 0.44f, 2.5f, Color{28, 28, 32, 255}); + } // Blob shadows first (under everything). draw_blob_shadow(game.player.pos, 0.8f); @@ -138,28 +203,37 @@ void Presenter::draw_scene(Game& game) { return dx * dx + dz * dz; }; - boards.push_back({depth(p.x, p.y), {p.x, 1.1f, p.y}, 1.7f, - game.player.hit_flash > 0.0f ? Color{255, 120, 120, 255} - : Color{150, 190, 255, 255}}); + boards.push_back({depth(p.x, p.y), {p.x, 1.15f, p.y}, 1.63f, 1.9f, spr_guard_, + flash_tint(game.player.hit_flash)}); for (const Enemy& e : game.enemy_system.enemies) { const float bob = std::sin(e.bob_phase) * 0.12f; + const float h = e.radius * 2.4f + 0.35f; + Texture2D tex = spr_staff_; + if (e.type == EnemyType::MoldSpore) tex = spr_mold_; + else if (e.type == EnemyType::HissBrute) tex = spr_brute_; boards.push_back({depth(e.pos.x, e.pos.y), - {e.pos.x, e.radius + 0.35f + bob, e.pos.y}, - e.radius * 2.1f, tint_for(e.type, e.hit_flash)}); + {e.pos.x, e.radius + 0.55f + bob, e.pos.y}, + h * 0.86f, h, tex, flash_tint(e.hit_flash)}); } for (const XpShard& s : game.pickup_system.shards) { - boards.push_back({depth(s.pos.x, s.pos.y), {s.pos.x, 0.5f, s.pos.y}, 0.5f, - Color{245, 205, 90, 255}}); + boards.push_back({depth(s.pos.x, s.pos.y), {s.pos.x, 0.55f, s.pos.y}, + 0.55f, 0.64f, spr_shard_, WHITE}); } for (const Projectile& pr : game.weapon_system.projectiles) { + const float s = projectile_size(pr.source); boards.push_back({depth(pr.pos.x, pr.pos.y), {pr.pos.x, 1.1f, pr.pos.y}, - projectile_size(pr.source), projectile_color(pr.source)}); + s, s, spr_glow_, projectile_color(pr.source)}); } std::sort(boards.begin(), boards.end(), [](const Billboard& a, const Billboard& b) { return a.depth > b.depth; }); for (const Billboard& b : boards) { - DrawBillboard(camera_, soft_disc_, b.pos, b.size, b.color); + // Missing sprite art degrades to the soft-disc standee. + const Texture2D tex = b.tex.id != 0 ? b.tex : soft_disc_; + DrawBillboardRec(camera_, tex, + Rectangle{0.0f, 0.0f, static_cast(tex.width), + static_cast(tex.height)}, + b.pos, Vector2{b.w, b.h}, b.color); } EndMode3D(); diff --git a/src/render/presenter.hpp b/src/render/presenter.hpp index ab139b0..e803a73 100644 --- a/src/render/presenter.hpp +++ b/src/render/presenter.hpp @@ -8,6 +8,8 @@ // The hybrid look: 3D brutalist diorama + 2D camera-facing standees. // The only place that knows how the sim is drawn (see docs/ART_DIRECTION.md). +// Standee art: assets/sprites/*.png photo-standee cards (ENV_ENHANCEMENT S5); +// missing files fall back to a procedural soft disc so the game never breaks. struct DamageNumber { Vec2 pos{}; float value = 0.0f; @@ -19,12 +21,24 @@ public: void init(); void shutdown(); - // Draws the 3D scene and world-anchored text. Call inside BeginDrawing(). + // Draws the 3D scene and world-anchored text. Call inside BeginDrawing() + // (or BeginTextureMode — main.cpp renders the frame to a texture first so + // the corruption post FX can run over it). void draw_scene(Game& game); + // Post-FX hook: 0..1 player-hit flash, consumed by assets/shaders/post_fx.fs. + float damage_flash() const { return damage_flash_; } + private: Camera3D camera_{}; - Texture2D soft_disc_{}; + Texture2D soft_disc_{}; // fallback standee + Texture2D spr_guard_{}; // assets/sprites/guard.png (the player) + Texture2D spr_staff_{}; // Hiss Corrupted Staff + Texture2D spr_brute_{}; // Hiss Brute + Texture2D spr_mold_{}; // Mold Spore + Texture2D spr_shard_{}; // Resonance Shard (XP) + Texture2D spr_glow_{}; // projectile / glow orb float shake_ = 0.0f; + float damage_flash_ = 0.0f; std::vector damage_numbers_; };