diff --git a/assets/shaders/concrete.fs b/assets/shaders/concrete.fs index f65b422..7467b70 100644 --- a/assets/shaders/concrete.fs +++ b/assets/shaders/concrete.fs @@ -19,6 +19,13 @@ uniform vec3 uCameraPos; uniform float uScale = 0.42; uniform float uCorruption = 0.0; +// Floor 01 wayfinding: a low-strength tint per room, applied to up-facing +// concrete only. The PBR detail stays; this replaces the old opaque flat plates. +#define MAX_ROOM_TINTS 10 +uniform vec4 uRoomRect[MAX_ROOM_TINTS]; // x0, z0, x1, z1 in world metres +uniform vec3 uRoomTint[MAX_ROOM_TINTS]; // multiplicative tint, max channel 1 +uniform int uRoomCount = 0; + void main() { vec3 n = normalize(vNormal); @@ -61,6 +68,22 @@ void main() // Hiss bleeding into the unlit side of the room as containment fails. lit += vec3(0.12, 0.008, 0.012) * (1.0 - ndl) * uCorruption * 0.22; + // Room identity: pick the nearest containing rect, softened at its edges. + // Only the horizontal floor gets tinted, never walls or pillars. + if (uRoomCount > 0 && normalize(vNormal).y > 0.5) { + vec3 tint = vec3(1.0); + float best = 0.0; + for (int i = 0; i < MAX_ROOM_TINTS; ++i) { + if (i >= uRoomCount) break; + vec4 r = uRoomRect[i]; + float inside = min(min(vWorld.x - r.x, r.z - vWorld.x), + min(vWorld.z - r.y, r.w - vWorld.z)); + float w = smoothstep(-0.5, 1.5, inside); + if (w > best) { best = w; tint = uRoomTint[i]; } + } + lit *= mix(vec3(1.0), tint, best); + } + // Volumetric haze: distant concrete settles into the Oldest House gloom. float dist = length(uCameraPos - vWorld); float fog = (1.0 - exp(-dist * 0.014)) * 0.50; diff --git a/src/render/concrete.cpp b/src/render/concrete.cpp index b5bc7b5..ca22ba3 100644 --- a/src/render/concrete.cpp +++ b/src/render/concrete.cpp @@ -6,6 +6,7 @@ #include "raymath.h" +#include #include #include #include @@ -46,6 +47,20 @@ Texture2D load_map(const char* name) { return tex; } +// The old blockout used these as opaque floor plates. They now only supply a +// hue for a low-strength tint in concrete.fs, so the PBR detail stays visible. +Color room_hue(RoomKind kind) { + switch (kind) { + case RoomKind::Gate: return {94, 143, 190, 255}; + case RoomKind::Plaza: return {58, 58, 64, 255}; + case RoomKind::Projector: return {198, 157, 36, 255}; + case RoomKind::OfficeSuite: return {70, 84, 92, 255}; + case RoomKind::Silos: return {24, 142, 172, 255}; + case RoomKind::Stairwell: return {150, 30, 40, 255}; + default: return {68, 126, 116, 255}; + } +} + void write_box(std::vector& v, std::vector& n, std::vector& uv, std::vector& c, std::vector& idx, @@ -102,6 +117,27 @@ void ConcreteMaterial::add_box(Vector3 center, Vector3 size, float rough_mult) { write_box(vertices_, normals_, uvs_, colors_, indices_, center, size, rough_mult); } +void ConcreteMaterial::load_room_tints(const Floor& floor) { + room_count_ = 0; + for (const FloorRoom& r : floor.rooms()) { + if (room_count_ >= kMaxRoomTints) break; + const int i = room_count_++; + const FloorRect& q = r.rect; + room_rect_[i * 4 + 0] = q.x0; + room_rect_[i * 4 + 1] = q.z0; + room_rect_[i * 4 + 2] = q.x1; + room_rect_[i * 4 + 3] = q.z1; + + const Color c = room_hue(r.kind); + const float rgb[3] = {c.r / 255.0f, c.g / 255.0f, c.b / 255.0f}; + const float peak = std::max(rgb[0], std::max(rgb[1], rgb[2])); + const float strength = r.kind == RoomKind::Side ? 0.14f : 0.22f; + for (int k = 0; k < 3; ++k) { + room_tint_[i * 3 + k] = 1.0f + (rgb[k] / peak - 1.0f) * strength; + } + } +} + void ConcreteMaterial::init(float arena, const Floor* floor) { const std::string vs = resolve("assets/shaders/concrete.vs"); const std::string fs = resolve("assets/shaders/concrete.fs"); @@ -122,6 +158,10 @@ void ConcreteMaterial::init(float arena, const Floor* floor) { shader_ok_ = true; loc_corruption_ = GetShaderLocation(shader_, "uCorruption"); loc_camera_ = GetShaderLocation(shader_, "uCameraPos"); + loc_room_rect_ = GetShaderLocation(shader_, "uRoomRect[0]"); + loc_room_tint_ = GetShaderLocation(shader_, "uRoomTint[0]"); + loc_room_count_ = GetShaderLocation(shader_, "uRoomCount"); + if (floor != nullptr) load_room_tints(*floor); // The floor is sealed and glossier than the raw walls/pillars; vertex alpha // carries that difference so everything still shares one material + mesh. @@ -218,6 +258,16 @@ void ConcreteMaterial::draw(float corruption, Vector3 camera_pos) { const float cam[3] = {camera_pos.x, camera_pos.y, camera_pos.z}; SetShaderValue(shader_, loc_camera_, cam, SHADER_UNIFORM_VEC3); } + if (room_count_ > 0) { + if (loc_room_rect_ >= 0) + SetShaderValueV(shader_, loc_room_rect_, room_rect_, SHADER_UNIFORM_VEC4, + room_count_); + if (loc_room_tint_ >= 0) + SetShaderValueV(shader_, loc_room_tint_, room_tint_, SHADER_UNIFORM_VEC3, + room_count_); + if (loc_room_count_ >= 0) + SetShaderValue(shader_, loc_room_count_, &room_count_, SHADER_UNIFORM_INT); + } PROF_DRAW_CALL(); DrawMesh(mesh_, material_, MatrixIdentity()); } diff --git a/src/render/concrete.hpp b/src/render/concrete.hpp index c913d5d..1cf4332 100644 --- a/src/render/concrete.hpp +++ b/src/render/concrete.hpp @@ -21,7 +21,9 @@ public: void apply_texture_filter(); private: + static constexpr int kMaxRoomTints = 10; // keep in sync with concrete.fs void add_box(Vector3 center, Vector3 size, float rough_mult); + void load_room_tints(const Floor& floor); std::vector vertices_; std::vector normals_; @@ -35,8 +37,14 @@ private: Texture2D normal_{}; Texture2D roughness_{}; Mesh mesh_{}; + float room_rect_[kMaxRoomTints * 4]{}; + float room_tint_[kMaxRoomTints * 3]{}; + int room_count_ = 0; int loc_corruption_ = -1; int loc_camera_ = -1; + int loc_room_rect_ = -1; + int loc_room_tint_ = -1; + int loc_room_count_ = -1; bool shader_ok_ = false; bool mesh_ok_ = false; bool ready_ = false; diff --git a/src/render/models.cpp b/src/render/models.cpp index a81f65c..fc96a4c 100644 --- a/src/render/models.cpp +++ b/src/render/models.cpp @@ -1,6 +1,7 @@ #include "render/models.hpp" #include "render/profiler.hpp" +#include "raymath.h" #include "rlgl.h" #define DrawModelEx(...) do { PROF_DRAW_CALL(); DrawModelEx(__VA_ARGS__); } while(0) @@ -11,6 +12,7 @@ #include #include #include +#include #include #include @@ -131,6 +133,29 @@ void ModelBank::init() { TraceLog(LOG_INFO, "ACTOR: skinned agent — %d bones, %d animations (%d valid)", model.skeleton.boneCount, e.animation_count, valid); + + // One-frame overlay clip: the current locomotion pose plus a hit + // lean on the upper body only. Built once, reused every flinch. + const unsigned bones = model.skeleton.boneCount; + FlinchOverlay& f = e.flinch; + f.anim.boneCount = bones; + f.anim.keyframeCount = 1; + f.anim.keyframePoses = static_cast( + std::calloc(1, sizeof(Transform*))); + if (f.anim.keyframePoses != nullptr) { + f.anim.keyframePoses[0] = static_cast( + std::calloc(bones, sizeof(Transform))); + if (f.anim.keyframePoses[0] != nullptr) { + for (unsigned b = 0; b < bones; ++b) { + const char* name = model.skeleton.bones[b].name; + if (std::strcmp(name, "chest") == 0) f.chest = static_cast(b); + else if (std::strcmp(name, "head") == 0) f.head = static_cast(b); + else if (std::strcmp(name, "upperarm.L") == 0) f.arm_l = static_cast(b); + else if (std::strcmp(name, "upperarm.R") == 0) f.arm_r = static_cast(b); + } + f.ready = true; + } + } } TraceLog(LOG_INFO, "ACTOR: %s (%d meshes, %d materials)", file_name(id), model.meshCount, model.materialCount); @@ -150,6 +175,11 @@ void ModelBank::shutdown() { e.blend_from_clock = 0.0f; e.blend_time = 0.0f; e.blend_duration = 0.0f; + if (e.flinch.anim.keyframePoses != nullptr) { + std::free(e.flinch.anim.keyframePoses[0]); + std::free(e.flinch.anim.keyframePoses); + } + e.flinch = FlinchOverlay{}; if (e.loaded) UnloadModel(e.model); e.loaded = false; } @@ -283,6 +313,33 @@ void ModelBank::update_animation(ActorModel id, const char* name, float dt, } } +void ModelBank::flinch(ActorModel id, float amount) { + if (amount <= 0.0f) return; + const int index = static_cast(id); + if (index < 0 || index >= static_cast(ActorModel::Count)) return; + Entry& e = entries_[index]; + if (!e.loaded || !e.flinch.ready || e.model.currentPose == nullptr) return; + + Transform* pose = e.flinch.anim.keyframePoses[0]; + std::memcpy(pose, e.model.currentPose, + sizeof(Transform) * e.model.skeleton.boneCount); + + const float a = amount < 1.0f ? amount : 1.0f; + const Vector3 axis{1.0f, 0.0f, 0.0f}; + auto lean = [pose, a, axis](int bone, float angle) { + if (bone < 0) return; + pose[bone].rotation = QuaternionMultiply( + pose[bone].rotation, QuaternionFromAxisAngle(axis, angle * a)); + }; + lean(e.flinch.chest, -0.30f); + lean(e.flinch.head, -0.35f); + lean(e.flinch.arm_l, -0.35f); + lean(e.flinch.arm_r, 0.30f); + + // Single keyframe: re-applying it reproduces the base pose plus the lean. + UpdateModelAnimation(e.model, e.flinch.anim, 0.0f); +} + float ModelBank::height(ActorModel id) { switch (id) { case ActorModel::Guard: return 1.9f; diff --git a/src/render/models.hpp b/src/render/models.hpp index 71ef095..6ffb7b7 100644 --- a/src/render/models.hpp +++ b/src/render/models.hpp @@ -35,10 +35,26 @@ public: void update_animation(ActorModel id, const char* name, float dt, float blend_seconds = 0.0f); + // Layers a short upper-body flinch over the pose left by update_animation(). + // Legs/root keep their locomotion pose, so a hit never freezes the walk. + // Call after update_animation() with amount in 0..1. + void flinch(ActorModel id, float amount); + // Per-model visual height, used for health bars / floating labels. static float height(ActorModel id); private: + // Single-frame clip holding the current locomotion pose plus a hit lean. + // Only chest/head/arms are changed, so re-applying it leaves the legs alone. + struct FlinchOverlay { + ModelAnimation anim{}; + int chest = -1; + int head = -1; + int arm_l = -1; + int arm_r = -1; + bool ready = false; + }; + struct Entry { Model model{}; ModelAnimation* animations = nullptr; @@ -49,6 +65,7 @@ private: float blend_from_clock = 0.0f; float blend_time = 0.0f; float blend_duration = 0.0f; // 0 => no cross-fade in progress + FlinchOverlay flinch{}; bool loaded = false; }; diff --git a/src/render/presenter.cpp b/src/render/presenter.cpp index 7b270b4..af80343 100644 --- a/src/render/presenter.cpp +++ b/src/render/presenter.cpp @@ -316,27 +316,8 @@ void Presenter::init(float arena_half, const Floor& floor) { { StaticMeshBuilder b; if (floor_mode_) { - for (const FloorRect& c : floor.corridors()) { - b.add_box({(c.x0 + c.x1) * 0.5f, 0.03f, (c.z0 + c.z1) * 0.5f}, - {c.x1 - c.x0, 0.06f, c.z1 - c.z0}, - Color{52, 52, 58, 255}); - } - auto room_color = [](RoomKind kind) { - switch (kind) { - case RoomKind::Gate: return Color{94, 143, 190, 255}; - case RoomKind::Plaza: return Color{58, 58, 64, 255}; - case RoomKind::Projector: return Color{198, 157, 36, 255}; - case RoomKind::OfficeSuite: return Color{70, 84, 92, 255}; - case RoomKind::Silos: return Color{24, 142, 172, 255}; - case RoomKind::Stairwell: return Color{150, 30, 40, 255}; - default: return Color{68, 126, 116, 255}; - } - }; - for (const FloorRoom& r : floor.rooms()) { - const FloorRect& q = r.rect; - b.add_box({(q.x0 + q.x1) * 0.5f, 0.025f, (q.z0 + q.z1) * 0.5f}, - {q.x1 - q.x0, 0.05f, q.z1 - q.z0}, room_color(r.kind)); - } + // Room identity is now a low-strength tint in concrete.fs instead of + // opaque plates: the PBR concrete stays visible under every room. for (float x = -80.0f; x <= 80.0f; x += 10.0f) { b.add_box({x, 0.037f, 0.0f}, {0.06f, 0.007f, 120.0f}, Color{34, 34, 39, 255}); @@ -1278,9 +1259,11 @@ void Presenter::draw_scene(Game& game) { // double up on top of the skeletal Run/Idle clips. const char* agent_clip = "Idle"; if (dash_pose_ > 0.0f) agent_clip = "Dash"; - else if (player_flash > 0.05f) agent_clip = "Stagger"; else if (player_running_) agent_clip = "Run"; models_.update_animation(ActorModel::Guard, agent_clip, frame_dt, 0.16f); + // A hit used to swap in the Stagger clip, whose legs are locked at rest — + // the walk stopped dead. Keep locomotion and flinch the upper body only. + models_.flinch(ActorModel::Guard, player_flash * 0.9f); models_.draw(ActorModel::Guard, {p.x, 0.0f, p.y}, player_yaw_, 1.0f, WHITE, player_flash, true, player_walk_, player_flash, anim_time_);