FBC: NIGHT SHIFT - layered hit flinch and textured concrete room tinting
This commit is contained in:
parent
04fbc3d4ba
commit
cca6034319
6 changed files with 160 additions and 22 deletions
|
|
@ -19,6 +19,13 @@ uniform vec3 uCameraPos;
|
||||||
uniform float uScale = 0.42;
|
uniform float uScale = 0.42;
|
||||||
uniform float uCorruption = 0.0;
|
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()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 n = normalize(vNormal);
|
vec3 n = normalize(vNormal);
|
||||||
|
|
@ -61,6 +68,22 @@ void main()
|
||||||
// Hiss bleeding into the unlit side of the room as containment fails.
|
// 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;
|
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.
|
// Volumetric haze: distant concrete settles into the Oldest House gloom.
|
||||||
float dist = length(uCameraPos - vWorld);
|
float dist = length(uCameraPos - vWorld);
|
||||||
float fog = (1.0 - exp(-dist * 0.014)) * 0.50;
|
float fog = (1.0 - exp(-dist * 0.014)) * 0.50;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
@ -46,6 +47,20 @@ Texture2D load_map(const char* name) {
|
||||||
return tex;
|
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<float>& v, std::vector<float>& n,
|
void write_box(std::vector<float>& v, std::vector<float>& n,
|
||||||
std::vector<float>& uv, std::vector<unsigned char>& c,
|
std::vector<float>& uv, std::vector<unsigned char>& c,
|
||||||
std::vector<unsigned short>& idx,
|
std::vector<unsigned short>& 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);
|
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) {
|
void ConcreteMaterial::init(float arena, const Floor* floor) {
|
||||||
const std::string vs = resolve("assets/shaders/concrete.vs");
|
const std::string vs = resolve("assets/shaders/concrete.vs");
|
||||||
const std::string fs = resolve("assets/shaders/concrete.fs");
|
const std::string fs = resolve("assets/shaders/concrete.fs");
|
||||||
|
|
@ -122,6 +158,10 @@ void ConcreteMaterial::init(float arena, const Floor* floor) {
|
||||||
shader_ok_ = true;
|
shader_ok_ = true;
|
||||||
loc_corruption_ = GetShaderLocation(shader_, "uCorruption");
|
loc_corruption_ = GetShaderLocation(shader_, "uCorruption");
|
||||||
loc_camera_ = GetShaderLocation(shader_, "uCameraPos");
|
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
|
// The floor is sealed and glossier than the raw walls/pillars; vertex alpha
|
||||||
// carries that difference so everything still shares one material + mesh.
|
// 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};
|
const float cam[3] = {camera_pos.x, camera_pos.y, camera_pos.z};
|
||||||
SetShaderValue(shader_, loc_camera_, cam, SHADER_UNIFORM_VEC3);
|
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();
|
PROF_DRAW_CALL();
|
||||||
DrawMesh(mesh_, material_, MatrixIdentity());
|
DrawMesh(mesh_, material_, MatrixIdentity());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ public:
|
||||||
void apply_texture_filter();
|
void apply_texture_filter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr int kMaxRoomTints = 10; // keep in sync with concrete.fs
|
||||||
void add_box(Vector3 center, Vector3 size, float rough_mult);
|
void add_box(Vector3 center, Vector3 size, float rough_mult);
|
||||||
|
void load_room_tints(const Floor& floor);
|
||||||
|
|
||||||
std::vector<float> vertices_;
|
std::vector<float> vertices_;
|
||||||
std::vector<float> normals_;
|
std::vector<float> normals_;
|
||||||
|
|
@ -35,8 +37,14 @@ private:
|
||||||
Texture2D normal_{};
|
Texture2D normal_{};
|
||||||
Texture2D roughness_{};
|
Texture2D roughness_{};
|
||||||
Mesh mesh_{};
|
Mesh mesh_{};
|
||||||
|
float room_rect_[kMaxRoomTints * 4]{};
|
||||||
|
float room_tint_[kMaxRoomTints * 3]{};
|
||||||
|
int room_count_ = 0;
|
||||||
int loc_corruption_ = -1;
|
int loc_corruption_ = -1;
|
||||||
int loc_camera_ = -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 shader_ok_ = false;
|
||||||
bool mesh_ok_ = false;
|
bool mesh_ok_ = false;
|
||||||
bool ready_ = false;
|
bool ready_ = false;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "render/models.hpp"
|
#include "render/models.hpp"
|
||||||
|
|
||||||
#include "render/profiler.hpp"
|
#include "render/profiler.hpp"
|
||||||
|
#include "raymath.h"
|
||||||
#include "rlgl.h"
|
#include "rlgl.h"
|
||||||
|
|
||||||
#define DrawModelEx(...) do { PROF_DRAW_CALL(); DrawModelEx(__VA_ARGS__); } while(0)
|
#define DrawModelEx(...) do { PROF_DRAW_CALL(); DrawModelEx(__VA_ARGS__); } while(0)
|
||||||
|
|
@ -11,6 +12,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
@ -131,6 +133,29 @@ void ModelBank::init() {
|
||||||
TraceLog(LOG_INFO,
|
TraceLog(LOG_INFO,
|
||||||
"ACTOR: skinned agent — %d bones, %d animations (%d valid)",
|
"ACTOR: skinned agent — %d bones, %d animations (%d valid)",
|
||||||
model.skeleton.boneCount, e.animation_count, 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<Transform**>(
|
||||||
|
std::calloc(1, sizeof(Transform*)));
|
||||||
|
if (f.anim.keyframePoses != nullptr) {
|
||||||
|
f.anim.keyframePoses[0] = static_cast<Transform*>(
|
||||||
|
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<int>(b);
|
||||||
|
else if (std::strcmp(name, "head") == 0) f.head = static_cast<int>(b);
|
||||||
|
else if (std::strcmp(name, "upperarm.L") == 0) f.arm_l = static_cast<int>(b);
|
||||||
|
else if (std::strcmp(name, "upperarm.R") == 0) f.arm_r = static_cast<int>(b);
|
||||||
|
}
|
||||||
|
f.ready = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TraceLog(LOG_INFO, "ACTOR: %s (%d meshes, %d materials)", file_name(id),
|
TraceLog(LOG_INFO, "ACTOR: %s (%d meshes, %d materials)", file_name(id),
|
||||||
model.meshCount, model.materialCount);
|
model.meshCount, model.materialCount);
|
||||||
|
|
@ -150,6 +175,11 @@ void ModelBank::shutdown() {
|
||||||
e.blend_from_clock = 0.0f;
|
e.blend_from_clock = 0.0f;
|
||||||
e.blend_time = 0.0f;
|
e.blend_time = 0.0f;
|
||||||
e.blend_duration = 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);
|
if (e.loaded) UnloadModel(e.model);
|
||||||
e.loaded = false;
|
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<int>(id);
|
||||||
|
if (index < 0 || index >= static_cast<int>(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) {
|
float ModelBank::height(ActorModel id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case ActorModel::Guard: return 1.9f;
|
case ActorModel::Guard: return 1.9f;
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,26 @@ public:
|
||||||
void update_animation(ActorModel id, const char* name, float dt,
|
void update_animation(ActorModel id, const char* name, float dt,
|
||||||
float blend_seconds = 0.0f);
|
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.
|
// Per-model visual height, used for health bars / floating labels.
|
||||||
static float height(ActorModel id);
|
static float height(ActorModel id);
|
||||||
|
|
||||||
private:
|
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 {
|
struct Entry {
|
||||||
Model model{};
|
Model model{};
|
||||||
ModelAnimation* animations = nullptr;
|
ModelAnimation* animations = nullptr;
|
||||||
|
|
@ -49,6 +65,7 @@ private:
|
||||||
float blend_from_clock = 0.0f;
|
float blend_from_clock = 0.0f;
|
||||||
float blend_time = 0.0f;
|
float blend_time = 0.0f;
|
||||||
float blend_duration = 0.0f; // 0 => no cross-fade in progress
|
float blend_duration = 0.0f; // 0 => no cross-fade in progress
|
||||||
|
FlinchOverlay flinch{};
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -316,27 +316,8 @@ void Presenter::init(float arena_half, const Floor& floor) {
|
||||||
{
|
{
|
||||||
StaticMeshBuilder b;
|
StaticMeshBuilder b;
|
||||||
if (floor_mode_) {
|
if (floor_mode_) {
|
||||||
for (const FloorRect& c : floor.corridors()) {
|
// Room identity is now a low-strength tint in concrete.fs instead of
|
||||||
b.add_box({(c.x0 + c.x1) * 0.5f, 0.03f, (c.z0 + c.z1) * 0.5f},
|
// opaque plates: the PBR concrete stays visible under every room.
|
||||||
{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));
|
|
||||||
}
|
|
||||||
for (float x = -80.0f; x <= 80.0f; x += 10.0f) {
|
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},
|
b.add_box({x, 0.037f, 0.0f}, {0.06f, 0.007f, 120.0f},
|
||||||
Color{34, 34, 39, 255});
|
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.
|
// double up on top of the skeletal Run/Idle clips.
|
||||||
const char* agent_clip = "Idle";
|
const char* agent_clip = "Idle";
|
||||||
if (dash_pose_ > 0.0f) agent_clip = "Dash";
|
if (dash_pose_ > 0.0f) agent_clip = "Dash";
|
||||||
else if (player_flash > 0.05f) agent_clip = "Stagger";
|
|
||||||
else if (player_running_) agent_clip = "Run";
|
else if (player_running_) agent_clip = "Run";
|
||||||
models_.update_animation(ActorModel::Guard, agent_clip, frame_dt, 0.16f);
|
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,
|
models_.draw(ActorModel::Guard, {p.x, 0.0f, p.y}, player_yaw_, 1.0f,
|
||||||
WHITE, player_flash, true, player_walk_, player_flash,
|
WHITE, player_flash, true, player_walk_, player_flash,
|
||||||
anim_time_);
|
anim_time_);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue