mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-24 13:45:57 +00:00
Merge upstream dev 25a53e5 into fsr4
Conflicts: runtime/cfg.c keeps dev's FREECAM_* names next to the FSR_* ones; runtime/vk_dlaa.c keeps dev's two FXAA_FS hashes for translator patch 0017 (#1299) and this branch's FXAA_COPY_FS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
c71222fecb
22 files changed
+779
-44
No files matched your search
+4
-2
@@ -43,7 +43,7 @@ static const char *const known[] = {
|
||||
"COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT",
|
||||
"DESC_TEMPLATE", "DESWIZZLE", "DEVICE_PROFILE", "DIALOGUE_CLICK", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_BACKEND", "DLAA_CAM_JITTER", "DLAA_EFFECTS_AFTER", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_FIXED_EXPOSURE", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR",
|
||||
"DUMP_LOG", "DYNAMIC_RES", "DYN_DELTA", "EXEFS", "FEEDBACK", "FIXED_RES_PATCH", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
|
||||
"FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE",
|
||||
"FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE", "FREECAM_KEY", "FREECAM_PAD", "FREECAM_PATCH",
|
||||
"FREEZE_IDLE", "FREE_CORES", "FSR_DEBUG", "FSR_JITTER_SIGN", "FSR_SHARPNESS",
|
||||
"FULLSCREEN", "FXAA",
|
||||
"GAMEPLAY_DISTANCE_SENSITIVITY", "GAMEPLAY_ITEM_AD", "GAMEPLAY_ITEM_SENSITIVITY", "GAMEPLAY_ITEM_WHEEL",
|
||||
@@ -99,7 +99,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"GYRO_BIAS_X", "input"}, {"GYRO_BIAS_Y", "input"}, {"GYRO_BIAS_Z", "input"}, {"GYRO_BIAS_PAD", "input"},
|
||||
{"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"},
|
||||
{"STICK_SENS", "input"},
|
||||
{"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"POINTER_IMAGE", "input"}, {"QUICKSAVE", "input"}, {"QUICKSAVE_KEY", "input"}, {"QUICKLOAD_KEY", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"INPUT_RECORD", "input"},
|
||||
{"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"POINTER_IMAGE", "input"}, {"QUICKSAVE", "input"}, {"QUICKSAVE_KEY", "input"}, {"QUICKLOAD_KEY", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"FREECAM_PATCH", "input"}, {"FREECAM_PAD", "input"}, {"FREECAM_KEY", "input"}, {"INPUT_RECORD", "input"},
|
||||
{"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"},
|
||||
{"BIND_RCLICK", "input"}, {"BIND_L", "input"}, {"BIND_R", "input"}, {"BIND_ZL", "input"}, {"BIND_ZR", "input"},
|
||||
{"BIND_PLUS", "input"}, {"BIND_MINUS", "input"}, {"BIND_LEFT", "input"}, {"BIND_UP", "input"},
|
||||
@@ -190,6 +190,8 @@ static const CfgMeta metas[] = {
|
||||
{"QUICKSAVE", "0", "0|1", LIVE}, // quicksave.c: one key saves (an autosave), another loads it
|
||||
{"QUICKSAVE_KEY", "f6", NULL, LIVE}, {"QUICKLOAD_KEY", "f7", NULL, LIVE}, // Half-Life's keys; a key name or none
|
||||
{"WALK_KEY", "none", NULL, LIVE}, {"WALK_SCALE", "0.51", "0.2..0.9", LIVE},
|
||||
// freecam.c: the patch set of its hook (off: the game's camera code as shipped), then the combo and key that step it
|
||||
{"FREECAM_PATCH", "0", "0|1", RESTART}, {"FREECAM_PAD", "none", NULL, LIVE}, {"FREECAM_KEY", "none", NULL, LIVE},
|
||||
// Gameplay Tweaks
|
||||
{"GAMEPLAY_TWEAKS_ENABLED", "0", "0|1", LIVE},
|
||||
{"GAMEPLAY_ULTRAHAND_ROTATE", "1", "0|1", LIVE}, {"GAMEPLAY_ULTRAHAND_C_AXIS", "1", "0|1", LIVE},
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
// Free camera for TotK 1.4.3: the view leaves Link and flies with the gamepad while the game goes on (docs/controls.md,
|
||||
// "Free camera").
|
||||
//
|
||||
// The camera component update (main+0x628460, called with the component as x0 = x19 from main+0x627dc8, the camera
|
||||
// actor's component array +0x228, slot +0x270) copies the component's pose into its sead camera and builds the view
|
||||
// matrix from it. Component fields (doubles unless noted): eye +0xe8, target +0x110, up +0x128 (floats), then near,
|
||||
// far, vertical view angle and aspect +0x134..+0x140 (the fov and aspect sets of recomp/patches-v143.txt load the last
|
||||
// two). Two one-shot overrides come after: a non-zero eye at +0x180 or target at +0x198 replaces the pose for that
|
||||
// update and is cleared (main+0x628fdc, main+0x629004). Additive offsets follow at +0x1b0 (flag) / +0x1c0 (eye),
|
||||
// +0x1d8 / +0x1e8 (target) and +0x200 (up, three floats, applied when any is non-zero and never cleared by the game).
|
||||
//
|
||||
// The freecam set's one site (main+0x6286d4, `ldr x8, [x19, #0x18]`, the first instruction every path to the pose
|
||||
// copy runs) calls freecam_hook, which performs that load and, while the free camera is on, writes the overrides.
|
||||
// The game's own eye and target stay as they were, so the game camera takes over the update after the hook stops.
|
||||
// The up offset is the game's state: the hook keeps the component's value and puts it back when the free camera ends,
|
||||
// and makes the up vector the world's +Y meanwhile, so the horizon stays level.
|
||||
//
|
||||
// Which components: a 1.4.3 frame updates three. Two share the player camera's pose (both must move, or the scene
|
||||
// and what follows the second disagree); the third rests at the default pose, eye (0, 0, 10) towards the origin. The
|
||||
// first component seen away from that default anchors the pick, and every component whose eye is within MATCH_M of
|
||||
// the anchor is driven. When no driven component has been updated for LOST_NS (a load replaced them) the next one
|
||||
// away from the default anchors again; the free camera keeps its own position.
|
||||
//
|
||||
// Input (runtime/input.c freecam_gate): TOTK_FREECAM_PAD or TOTK_FREECAM_KEY steps it off, move, lock and off again
|
||||
// (both none by default, so the player opts in). While it moves the game gets no input; the left stick flies along the
|
||||
// view and to the side, ZR and ZL straight up and down, the right stick and the mouse turn, and each press of L or R
|
||||
// halves or doubles the speed. Keys work through their bindings: the keys' sticks, and the keys bound to ZL, ZR, L and
|
||||
// R. Every driven component steps the flight by the wall-clock time since the last step, so the speed is the same at
|
||||
// any frame rate and game speed. Locked, the view stays where the flight left it and the game gets its input back.
|
||||
// The game steers Link by the camera it draws, which takes the overrides, so Link walks where the stick points on
|
||||
// screen with the stick as it is.
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cfg.h"
|
||||
#include "host.h"
|
||||
#include "input.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
#if __has_include("patches.h")
|
||||
#include "patches.h"
|
||||
#endif
|
||||
|
||||
#define SPEED_START 8.0 // metres a second at full deflection
|
||||
#define SPEED_MIN 0.25 // 8 m/s halved five times
|
||||
#define SPEED_MAX 512.0 // 8 m/s doubled six times
|
||||
#define TURN_DEG_S 110.0 // the right stick's turn rate at full deflection
|
||||
#define PITCH_MAX_DEG 85.0 // short of straight up or down, where the view's up vector would fail
|
||||
#define TARGET_M 10.0 // the target's distance in front of the eye
|
||||
#define MATCH_M 2.0
|
||||
#define LOST_NS 500000000ull
|
||||
#define STEP_MAX_S 0.1 // a longer gap (a load, a hitch) moves the camera no further than this
|
||||
#define MAX_DRIVEN 8
|
||||
|
||||
static PlatMutex pad_lock = PLAT_MUTEX_INIT;
|
||||
static FreecamPad pad_now; // the last poll's input (input thread), under pad_lock
|
||||
static int speed_clicks; // R presses minus L presses not yet applied (input thread adds, the hook takes)
|
||||
static double mouse_deg[2]; // under pad_lock: mouse turn not yet applied, degrees (right +, down +)
|
||||
// + 1 at every switch (input thread); modulo 3 the stage (FREECAM_OFF, _MOVE, _LOCK). One value, so the hook never
|
||||
// sees a switch without the stage it switched to.
|
||||
static unsigned generation;
|
||||
|
||||
int freecam_state(void) { return __atomic_load_n(&generation, __ATOMIC_ACQUIRE) % 3; }
|
||||
|
||||
void freecam_pad(const FreecamPad *p) {
|
||||
plat_mutex_lock(&pad_lock);
|
||||
pad_now = *p;
|
||||
plat_mutex_unlock(&pad_lock);
|
||||
}
|
||||
|
||||
void freecam_mouse(double right_deg, double down_deg) {
|
||||
plat_mutex_lock(&pad_lock);
|
||||
mouse_deg[0] += right_deg;
|
||||
mouse_deg[1] += down_deg;
|
||||
plat_mutex_unlock(&pad_lock);
|
||||
}
|
||||
|
||||
void freecam_speed_click(int faster) { __atomic_add_fetch(&speed_clicks, faster ? 1 : -1, __ATOMIC_RELAXED); }
|
||||
|
||||
#ifdef RT_PATCH_PAGE
|
||||
#define HOST_FREECAM (RT_PATCH_PAGE + 0xf50)
|
||||
|
||||
enum {
|
||||
OFF_LINK = 0x18, OFF_EYE = 0xe8, OFF_TARGET = 0x110, OFF_UP = 0x128,
|
||||
OFF_EYE_OVERRIDE = 0x180, OFF_TARGET_OVERRIDE = 0x198, OFF_UP_OFFSET = 0x200,
|
||||
SPAN = OFF_UP_OFFSET + 12 - OFF_EYE, // the fields the hook reads and writes, from OFF_EYE
|
||||
};
|
||||
|
||||
int freecam_available(void) { return rt_game_version == 143 && rt_patch_enabled(rt_patch_set("freecam")); }
|
||||
|
||||
void freecam_cycle(void) {
|
||||
unsigned gen = __atomic_add_fetch(&generation, 1, __ATOMIC_ACQ_REL);
|
||||
static const char *const names[] = {"off", "move", "lock"};
|
||||
rt_log("freecam: %s", names[gen % 3]);
|
||||
}
|
||||
|
||||
// Game thread only (the camera update runs on one thread). A component stays listed from its first drive until its
|
||||
// up offset is put back (the first update after the switch goes off) or, while off, until it has gone LOST_NS
|
||||
// without an update (freed by a load).
|
||||
static struct {
|
||||
unsigned flight; // (generation + 2) / 3: the same from move through lock, new at the next move
|
||||
int started; // pos, yaw and pitch hold a pose
|
||||
double pos[3], yaw, pitch, speed; // radians; yaw 0 looks along +Z, pitch > 0 up
|
||||
uint64_t last_step, anchor_seen;
|
||||
int anchored; // anchor holds the eye of the components being driven
|
||||
double anchor[3];
|
||||
int n;
|
||||
struct { uint64_t cam, seen; float up_offset[3]; } driven[MAX_DRIVEN];
|
||||
} fc;
|
||||
|
||||
static void read3(uint64_t at, double v[3]) { memcpy(v, (const void *)(uintptr_t)at, 3 * sizeof(double)); }
|
||||
static void write3(uint64_t at, const double v[3]) { memcpy((void *)(uintptr_t)at, v, 3 * sizeof(double)); }
|
||||
|
||||
static int at_default(const double eye[3], const double target[3]) {
|
||||
return eye[0] == 0 && eye[1] == 0 && eye[2] == 10 && target[0] == 0 && target[1] == 0 && target[2] == 0;
|
||||
}
|
||||
|
||||
static void direction(double d[3]) {
|
||||
d[0] = sin(fc.yaw) * cos(fc.pitch);
|
||||
d[1] = sin(fc.pitch);
|
||||
d[2] = cos(fc.yaw) * cos(fc.pitch);
|
||||
}
|
||||
|
||||
static int driven_index(uint64_t cam) {
|
||||
for (int i = 0; i < fc.n; i++)
|
||||
if (fc.driven[i].cam == cam) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void drop(int i) { fc.driven[i] = fc.driven[--fc.n]; }
|
||||
|
||||
// The free camera starts where the game camera is: its eye, looking at its target.
|
||||
static void start(const double eye[3], const double target[3], uint64_t now) {
|
||||
double d[3] = {target[0] - eye[0], target[1] - eye[1], target[2] - eye[2]};
|
||||
double len = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
|
||||
memcpy(fc.pos, eye, sizeof fc.pos);
|
||||
fc.yaw = len > 1e-6 ? atan2(d[0], d[2]) : 0;
|
||||
fc.pitch = len > 1e-6 ? asin(fmax(-1.0, fmin(1.0, d[1] / len))) : 0;
|
||||
fc.started = 1;
|
||||
fc.last_step = now;
|
||||
rt_log("freecam: starting at (%.1f %.1f %.1f)", eye[0], eye[1], eye[2]);
|
||||
}
|
||||
|
||||
// A new component joins while it shares the anchor's eye; the first one away from the default pose sets the anchor.
|
||||
static int pick(uint64_t cam, const double eye[3], const double target[3]) {
|
||||
if (at_default(eye, target)) return -1;
|
||||
if (fc.anchored) {
|
||||
double dx = eye[0] - fc.anchor[0], dy = eye[1] - fc.anchor[1], dz = eye[2] - fc.anchor[2];
|
||||
if (dx * dx + dy * dy + dz * dz > MATCH_M * MATCH_M) return -1;
|
||||
} else {
|
||||
memcpy(fc.anchor, eye, sizeof fc.anchor);
|
||||
fc.anchored = 1;
|
||||
}
|
||||
if (fc.n == MAX_DRIVEN) { // full after several loads: the one unseen longest was freed by a load
|
||||
int oldest = 0;
|
||||
for (int k = 1; k < fc.n; k++)
|
||||
if (fc.driven[k].seen < fc.driven[oldest].seen) oldest = k;
|
||||
drop(oldest);
|
||||
}
|
||||
int i = fc.n++;
|
||||
fc.driven[i].cam = cam;
|
||||
memcpy(fc.driven[i].up_offset, (const void *)(uintptr_t)(cam + OFF_UP_OFFSET), sizeof fc.driven[i].up_offset);
|
||||
rt_log("freecam: driving camera component %#llx", (unsigned long long)cam);
|
||||
return i;
|
||||
}
|
||||
|
||||
static double axis(float v) { return v > 1 ? 1 : v < -1 ? -1 : v; }
|
||||
|
||||
// Flight since the last step: L and R presses scale the speed, the right stick turns, the left stick moves along the
|
||||
// view and to the side, the triggers along the world's up.
|
||||
// Every driven component steps; the second one of a frame comes microseconds after the first and moves that little.
|
||||
static void step(uint64_t now) {
|
||||
double dt = (now - fc.last_step) / 1e9;
|
||||
fc.last_step = now;
|
||||
if (dt <= 0) return;
|
||||
if (dt > STEP_MAX_S) dt = STEP_MAX_S;
|
||||
FreecamPad p;
|
||||
double mouse[2];
|
||||
plat_mutex_lock(&pad_lock);
|
||||
p = pad_now;
|
||||
mouse[0] = mouse_deg[0], mouse[1] = mouse_deg[1];
|
||||
mouse_deg[0] = mouse_deg[1] = 0;
|
||||
plat_mutex_unlock(&pad_lock);
|
||||
int clicks = __atomic_exchange_n(&speed_clicks, 0, __ATOMIC_RELAXED);
|
||||
if (clicks) {
|
||||
fc.speed *= exp2(clicks);
|
||||
fc.speed = fc.speed < SPEED_MIN ? SPEED_MIN : fc.speed > SPEED_MAX ? SPEED_MAX : fc.speed;
|
||||
}
|
||||
double turn = TURN_DEG_S * M_PI / 180 * dt, limit = PITCH_MAX_DEG * M_PI / 180;
|
||||
// right turns towards -yaw (see right[] below); the mouse's degrees come on top of the stick's
|
||||
fc.yaw = remainder(fc.yaw - axis(p.rx) * turn - mouse[0] * M_PI / 180, 2 * M_PI);
|
||||
fc.pitch += axis(p.ry) * turn - mouse[1] * M_PI / 180;
|
||||
fc.pitch = fc.pitch > limit ? limit : fc.pitch < -limit ? -limit : fc.pitch;
|
||||
double d[3], right[3];
|
||||
direction(d);
|
||||
// world +Y up, right-handed: right = d x Y, level
|
||||
double rl = sqrt(d[0] * d[0] + d[2] * d[2]);
|
||||
right[0] = -d[2] / rl, right[1] = 0, right[2] = d[0] / rl;
|
||||
double fwd = axis(p.ly), side = axis(p.lx), lift = axis(p.rt) - axis(p.lt), dist = fc.speed * dt;
|
||||
for (int k = 0; k < 3; k++) fc.pos[k] += (d[k] * fwd + right[k] * side) * dist;
|
||||
fc.pos[1] += lift * dist;
|
||||
}
|
||||
|
||||
static void drive(uint64_t cam) {
|
||||
double d[3], target[3];
|
||||
direction(d);
|
||||
for (int k = 0; k < 3; k++) target[k] = fc.pos[k] + d[k] * TARGET_M;
|
||||
write3(cam + OFF_EYE_OVERRIDE, fc.pos);
|
||||
write3(cam + OFF_TARGET_OVERRIDE, target);
|
||||
// up + offset = +Y: the game adds the offset to its up vector before it builds the view
|
||||
float up[3], offset[3];
|
||||
memcpy(up, (const void *)(uintptr_t)(cam + OFF_UP), sizeof up);
|
||||
offset[0] = -up[0], offset[1] = 1.0f - up[1], offset[2] = -up[2];
|
||||
if (offset[0] == 0 && offset[1] == 0 && offset[2] == 0) offset[1] = 1e-6f; // all zero would skip the offset
|
||||
memcpy((void *)(uintptr_t)(cam + OFF_UP_OFFSET), offset, sizeof offset);
|
||||
}
|
||||
|
||||
// The site's own instruction first: x8 = [x19 + 0x18]. x19 is the camera component (read only: the lifter keeps
|
||||
// X19-X29 in locals across a host call).
|
||||
static void freecam_hook(Cpu *c) {
|
||||
uint64_t cam = c->x[19];
|
||||
memcpy(&c->x[8], (const void *)(uintptr_t)(cam + OFF_LINK), sizeof c->x[8]);
|
||||
unsigned gen = __atomic_load_n(&generation, __ATOMIC_ACQUIRE);
|
||||
int state = gen % 3, active = state != FREECAM_OFF;
|
||||
if (!active && !fc.n) return; // the common case: one load, a division and two compares
|
||||
if ((gen + 2) / 3 != fc.flight) { // a new flight starts at the game camera, at the start speed
|
||||
fc.flight = (gen + 2) / 3;
|
||||
fc.started = 0, fc.anchored = 0, fc.speed = SPEED_START;
|
||||
plat_mutex_lock(&pad_lock); // mouse motion from before the switch does not turn the new flight
|
||||
mouse_deg[0] = mouse_deg[1] = 0;
|
||||
plat_mutex_unlock(&pad_lock);
|
||||
}
|
||||
uint64_t now = plat_now_ns();
|
||||
int i = driven_index(cam);
|
||||
if (!active) {
|
||||
if (i >= 0) {
|
||||
memcpy((void *)(uintptr_t)(cam + OFF_UP_OFFSET), fc.driven[i].up_offset, sizeof fc.driven[i].up_offset);
|
||||
drop(i);
|
||||
}
|
||||
for (int k = fc.n - 1; k >= 0; k--)
|
||||
if (now - fc.driven[k].seen > LOST_NS) drop(k); // freed by a load while it waited
|
||||
return;
|
||||
}
|
||||
if (!mem_guest_readable(cam + OFF_EYE, SPAN)) return;
|
||||
if (fc.anchored && now - fc.anchor_seen > LOST_NS) fc.anchored = 0; // a load replaced the components
|
||||
double eye[3], target[3];
|
||||
read3(cam + OFF_EYE, eye);
|
||||
read3(cam + OFF_TARGET, target);
|
||||
if (i < 0 && (i = pick(cam, eye, target)) < 0) return;
|
||||
if (!fc.started) start(eye, target, now);
|
||||
fc.driven[i].seen = fc.anchor_seen = now;
|
||||
if (state == FREECAM_MOVE) step(now); // locked, the view holds its pose
|
||||
drive(cam);
|
||||
}
|
||||
|
||||
__attribute__((constructor)) static void freecam_register(void) {
|
||||
if (rt_game_version == 143) rt_register_host(HOST_FREECAM, freecam_hook);
|
||||
}
|
||||
#else
|
||||
int freecam_available(void) { return 0; }
|
||||
void freecam_cycle(void) {}
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
// Generated by tools/build_shaders.py from runtime/shaders/hdr_tonemap.frag; do not edit.
|
||||
// source sha256 2680db17a9c8cd3ad85bcbc75d67e46e84179dfbe4ac7e7904fcdc935febe4ca
|
||||
// source sha256 92e96e90540b3b7b022393843a05a1bc2addaf9f2afc535d8204faace6cebdf0
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
static const uint32_t hdr_tonemap_spv[] = {
|
||||
@@ -15,7 +15,7 @@ static const uint32_t hdr_tonemap_spv[] = {
|
||||
0x00000002, 0x00050048, 0x00000437, 0x00000000, 0x00000023, 0x00000000, 0x00040047, 0x00000439,
|
||||
0x00000021, 0x00000004, 0x00040047, 0x00000439, 0x00000022, 0x00000000, 0x00040047, 0x0000043e,
|
||||
0x00000006, 0x00000010, 0x00030047, 0x0000043f, 0x00000002, 0x00050048, 0x0000043f, 0x00000000,
|
||||
0x00000023, 0x00000000, 0x00050048, 0x0000043f, 0x00000001, 0x00000023, 0x000005a0, 0x00040047,
|
||||
0x00000023, 0x00000000, 0x00050048, 0x0000043f, 0x00000001, 0x00000023, 0x000005c0, 0x00040047,
|
||||
0x00000441, 0x00000021, 0x00000000, 0x00040047, 0x00000441, 0x00000022, 0x00000000, 0x00040047,
|
||||
0x00000493, 0x0000001e, 0x00000000, 0x00020013, 0x00000002, 0x00030021, 0x00000003, 0x00000002,
|
||||
0x00030016, 0x00000006, 0x00000020, 0x00040017, 0x00000007, 0x00000006, 0x00000003, 0x00040017,
|
||||
@@ -81,7 +81,7 @@ static const uint32_t hdr_tonemap_spv[] = {
|
||||
0x0004003b, 0x00000430, 0x00000431, 0x00000002, 0x00040020, 0x00000432, 0x00000002, 0x00000073,
|
||||
0x0004001c, 0x00000436, 0x00000073, 0x0000042d, 0x0003001e, 0x00000437, 0x00000436, 0x00040020,
|
||||
0x00000438, 0x00000002, 0x00000437, 0x0004003b, 0x00000438, 0x00000439, 0x00000002, 0x0004002b,
|
||||
0x00000080, 0x0000043d, 0x0000005a, 0x0004001c, 0x0000043e, 0x00000073, 0x0000043d, 0x0004001e,
|
||||
0x00000080, 0x0000043d, 0x0000005c, 0x0004001c, 0x0000043e, 0x00000073, 0x0000043d, 0x0004001e,
|
||||
0x0000043f, 0x0000043e, 0x00000073, 0x00040020, 0x00000440, 0x00000002, 0x0000043f, 0x0004003b,
|
||||
0x00000440, 0x00000441, 0x00000002, 0x00040020, 0x00000442, 0x00000002, 0x00000006, 0x0006002c,
|
||||
0x00000007, 0x00000463, 0x00000128, 0x00000128, 0x00000128, 0x0004002b, 0x00000006, 0x0000046f,
|
||||
|
||||
+145
-3
@@ -148,6 +148,10 @@ static void script_load(void) {
|
||||
rt_log("input: script %s, %d events", path, script_n);
|
||||
}
|
||||
|
||||
// Under lock: the Switch buttons the input script pressed in the last poll, apart from the keys' and the gamepad's, so
|
||||
// a gamepad combo can count a scripted press as the gamepad's without counting the keys bound to the same buttons
|
||||
static uint64_t script_seen;
|
||||
|
||||
static void script_apply(uint64_t *b, int32_t sl[2], int32_t sr[2]) {
|
||||
if (!script_state) script_load();
|
||||
if (!script_n) return;
|
||||
@@ -269,7 +273,8 @@ static void rec_apply(uint64_t b, const int32_t sl[2], const int32_t sr[2]) {
|
||||
|
||||
void input_direct_mouse_sample(int enabled, int32_t *dx, int32_t *dy) {
|
||||
plat_mutex_lock(&lock);
|
||||
enabled = enabled && !g_block && !g_menu;
|
||||
// the moving free camera takes the mouse (freecam_gate)
|
||||
enabled = enabled && !g_block && !g_menu && freecam_state() != FREECAM_MOVE;
|
||||
*dx = script_mouse[0]; *dy = script_mouse[1];
|
||||
script_mouse[0] = script_mouse[1] = 0;
|
||||
if (!enabled) { *dx = *dy = 0; }
|
||||
@@ -803,15 +808,149 @@ static int pad_physical(uint8_t pd[PAD_COUNT]) {
|
||||
|
||||
// Under lock, state 1: the open gamepad's buttons (Switch bits after TOTK_PAD_LAYOUT and the TOTK_BIND_* lines) and
|
||||
// sticks; 0 without a connected gamepad.
|
||||
// Under lock: the last pad_read's inputs by position, [PAD_GUIDE] the Home / Guide button (no Switch button), and its
|
||||
// left and right trigger axes, 0..32767: what the gamepad combos and the free camera read
|
||||
#define PAD_GUIDE PAD_COUNT
|
||||
static uint8_t pad_seen[PAD_COUNT + 1];
|
||||
static int16_t trigger_seen[2];
|
||||
|
||||
static int pad_read(uint64_t *b, int32_t sl[2], int32_t sr[2]) {
|
||||
uint8_t pd[PAD_COUNT] = {0};
|
||||
if (!pad_physical(pd)) return 0;
|
||||
if (!pad_physical(pd)) {
|
||||
memset(pad_seen, 0, sizeof pad_seen);
|
||||
memset(trigger_seen, 0, sizeof trigger_seen);
|
||||
return 0;
|
||||
}
|
||||
memcpy(pad_seen, pd, sizeof pd);
|
||||
pad_seen[PAD_GUIDE] = SDL_GetGamepadButton(pad, SDL_GAMEPAD_BUTTON_GUIDE);
|
||||
trigger_seen[0] = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_LEFT_TRIGGER);
|
||||
trigger_seen[1] = SDL_GetGamepadAxis(pad, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER);
|
||||
*b |= input_map_pad_buttons(pd, pad_layout_get());
|
||||
stick(SDL_GAMEPAD_AXIS_LEFTX, SDL_GAMEPAD_AXIS_LEFTY, stick_dead_get(0), sl);
|
||||
stick(SDL_GAMEPAD_AXIS_RIGHTX, SDL_GAMEPAD_AXIS_RIGHTY, stick_dead_get(1), sr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t input_pad_combo(const char *env, const char *s) {
|
||||
uint32_t mask = 0;
|
||||
char name[32];
|
||||
size_t n = 0;
|
||||
for (const char *c = s;; c++) {
|
||||
if (*c && *c != '+' && *c != ' ') {
|
||||
if (n < sizeof name - 1) name[n++] = *c;
|
||||
continue;
|
||||
}
|
||||
if (n) {
|
||||
name[n] = 0;
|
||||
int p = !strcasecmp(name, "guide") || !strcasecmp(name, "home") ? PAD_GUIDE : input_pad_id(name);
|
||||
if (p == PAD_NONE) {
|
||||
rt_log("input: %s=%s: %s is not a gamepad button (south east west north lstick rstick "
|
||||
"l r zl zr start back guide dpad_*, paddles)", env, s, name);
|
||||
return 0;
|
||||
}
|
||||
mask |= 1u << p;
|
||||
n = 0;
|
||||
}
|
||||
if (!*c) break;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
// TOTK_FREECAM_PAD (live): the combo that switches the free camera (freecam.c), for example zl+zr+lstick (LT+RT+L3);
|
||||
// none, the default (the settings table), for no combo. Under lock.
|
||||
static uint32_t freecam_pad_mask(void) {
|
||||
static unsigned seen;
|
||||
static int read;
|
||||
static uint32_t mask;
|
||||
unsigned v = cfg_version();
|
||||
if (read && v == seen) return mask;
|
||||
read = 1, seen = v;
|
||||
const char *s = cfg_value("TOTK_FREECAM_PAD");
|
||||
mask = *s && strcasecmp(s, "none") ? input_pad_combo("TOTK_FREECAM_PAD", s) : 0;
|
||||
return mask;
|
||||
}
|
||||
|
||||
// TOTK_FREECAM_KEY (live): the key that switches the free camera; none, the default (the settings table), for no key.
|
||||
// Under lock.
|
||||
static int freecam_key(void) {
|
||||
static unsigned seen;
|
||||
static int read, key;
|
||||
unsigned v = cfg_version();
|
||||
if (read && v == seen) return key;
|
||||
read = 1, seen = v;
|
||||
const char *s = cfg_value("TOTK_FREECAM_KEY");
|
||||
key = !*s || !strcasecmp(s, "none") ? KEY_NONE : input_key_id(s);
|
||||
if (key == KEY_NONE && *s && strcasecmp(s, "none"))
|
||||
rt_log("input: TOTK_FREECAM_KEY=%s is not a key name (docs/controls.md)", s);
|
||||
return key;
|
||||
}
|
||||
|
||||
static float trigger_unit(int16_t v) { // 0..1 past a 5 % dead zone
|
||||
float t = v / 32767.0f;
|
||||
return t < 0.05f ? 0 : (t - 0.05f) / 0.95f;
|
||||
}
|
||||
|
||||
// The free camera combo, latched like Minus+Plus (input_map.c, chord): once every button of it is down (on the gamepad,
|
||||
// or pressed by an input script) the free camera steps once (off, move, lock), and the buttons stay hidden from the
|
||||
// game until all are released; the free camera key steps it on its press. While the free camera moves it gets the
|
||||
// input and the game gets nothing, so Link stands still: the sticks (the keys' sticks merged into sl and sr), the
|
||||
// trigger axes or else ZL and ZR as buttons, a press of L or R as a speed click, and the mouse's motion, which
|
||||
// input_direct_mouse_sample then keeps from the game's camera. ZL, ZR, L and R are the merged Switch buttons, so the
|
||||
// keys bound to them count. Locked, the game gets the input as it is (freecam.c: the game steers Link by the camera it
|
||||
// draws). Off for other updates and with the freecam patch set off. Under lock.
|
||||
static void freecam_gate(uint64_t *b, int32_t sl[2], int32_t sr[2]) {
|
||||
static int held, key_held, available = -1, shoulder[2];
|
||||
if (available < 0) available = freecam_available();
|
||||
uint32_t mask = available ? freecam_pad_mask() : 0, raw = 0;
|
||||
int layout = pad_layout_get();
|
||||
for (int p = PAD_SOUTH; p <= PAD_GUIDE; p++) {
|
||||
if (!(mask >> p & 1)) continue;
|
||||
// A position counts as down on the gamepad or when the input script presses the Switch buttons it stands for,
|
||||
// as a gamepad would; the keys bound to those buttons do not (the free camera key is theirs). Home has no
|
||||
// Switch button: gamepad only.
|
||||
uint8_t one[PAD_COUNT] = {0};
|
||||
if (p < PAD_COUNT) one[p] = 1;
|
||||
if (pad_seen[p] || (p < PAD_COUNT && script_seen & input_map_pad_buttons(one, layout))) raw |= 1u << p;
|
||||
}
|
||||
if (!mask) held = 0;
|
||||
else if (held) held = raw != 0;
|
||||
else if (raw == mask) {
|
||||
held = 1;
|
||||
freecam_cycle();
|
||||
}
|
||||
int key = available ? freecam_key() : KEY_NONE;
|
||||
int key_down = key != KEY_NONE && ikb_foreground() && ikb_down(key);
|
||||
if (key_down && !key_held) freecam_cycle();
|
||||
key_held = key_down;
|
||||
if (available && freecam_state() == FREECAM_MOVE) {
|
||||
float lt = trigger_unit(trigger_seen[0]), rt = trigger_unit(trigger_seen[1]);
|
||||
if (*b >> B_ZL & 1) lt = 1;
|
||||
if (*b >> B_ZR & 1) rt = 1;
|
||||
FreecamPad fp = {sl[0] / (float)STICK_MAX, sl[1] / (float)STICK_MAX, sr[0] / (float)STICK_MAX,
|
||||
sr[1] / (float)STICK_MAX, lt, rt};
|
||||
freecam_pad(&fp);
|
||||
for (int k = 0; k < 2; k++) {
|
||||
int down = (int)(*b >> (k ? B_R : B_L) & 1);
|
||||
if (down && !shoulder[k]) freecam_speed_click(k);
|
||||
shoulder[k] = down;
|
||||
}
|
||||
if (ikb_captured() && ikb_foreground() && input_cursor_allowed()) {
|
||||
int32_t x, y;
|
||||
ikb_mouse_take(&x, &y); // what the stick emulation left (none in that mode: it is in sr already)
|
||||
float deg = 0.08f * mouse_sens_get(); // the game camera's rate a count (mouse_direct.c DEG_PER_COUNT)
|
||||
if (x || y) freecam_mouse(x * deg, y * deg);
|
||||
}
|
||||
*b = 0;
|
||||
sl[0] = sl[1] = sr[0] = sr[1] = 0;
|
||||
return;
|
||||
}
|
||||
shoulder[0] = shoulder[1] = 1; // a shoulder held when the free camera starts is no click
|
||||
if (!held) return;
|
||||
uint8_t sub[PAD_COUNT] = {0};
|
||||
for (int p = PAD_SOUTH; p < PAD_COUNT; p++) sub[p] = mask >> p & 1;
|
||||
*b &= ~input_map_pad_buttons(sub, pad_layout_get());
|
||||
}
|
||||
|
||||
int input_pad_stick_percent(double pct[2]) {
|
||||
int ok = 0;
|
||||
pct[0] = pct[1] = 0;
|
||||
@@ -928,7 +1067,9 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
mouse_camera(k, 0);
|
||||
pick(&sr[0], &sr[1], k[0], k[1]);
|
||||
}
|
||||
script_apply(&b, sl, sr);
|
||||
script_seen = 0;
|
||||
script_apply(&script_seen, sl, sr);
|
||||
b |= script_seen;
|
||||
wheel_route(&b, sl, sr);
|
||||
gameplay_tweaks_apply(__atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED), input_gameplay_active(), &b, &sl[0], &sl[1], &sr[0], &sr[1]);
|
||||
rec_apply(b, sl, sr);
|
||||
@@ -939,6 +1080,7 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx
|
||||
static int overlay_held; // L3+R3 step the performance overlay (F10)
|
||||
int overlay = input_overlay_gate(&overlay_held, &b);
|
||||
sl[0] = st[0], sl[1] = st[1], sr[0] = st[2], sr[1] = st[3];
|
||||
freecam_gate(&b, sl, sr); // TOTK_FREECAM_PAD steps the free camera, which takes the pad while moving (freecam.c)
|
||||
plat_mutex_unlock(&lock);
|
||||
if (toggle) menu_toggle();
|
||||
if (overlay) menu_perf_cycle();
|
||||
|
||||
@@ -91,9 +91,25 @@ void input_menu(int open);
|
||||
// of the combo, sticks are lx, ly, rx, ry. Returns 1 in the poll where the combo goes down (toggle the menu once).
|
||||
int input_menu_gate(int *held, int menu_open, uint64_t *buttons, int32_t sticks[4]);
|
||||
int input_overlay_gate(int *held, uint64_t *buttons); // L3+R3: 1 in the poll both go down
|
||||
// A gamepad combo setting: buttons by position joined with '+' (guide+south: Home and the bottom face button, the
|
||||
// pad: names of the bind_ lines plus guide or home). Bit p is PAD_* p, bit PAD_COUNT the Home button; 0 for an empty
|
||||
// value or one with a name that is no button, which logs a line naming env.
|
||||
uint32_t input_pad_combo(const char *env, const char *s);
|
||||
int input_pad_read(uint64_t *buttons, int32_t *lx, int32_t *ly);
|
||||
// The gamepad layout in effect (PAD_LAYOUT_*, input_map.h; TOTK_PAD_LAYOUT, live); -1 without a gamepad. Any thread.
|
||||
int input_pad_layout(void);
|
||||
|
||||
// Free camera (freecam.c). input.c steps it with TOTK_FREECAM_PAD and, while it moves, hands it the gamepad and gives
|
||||
// the game none: sticks -1..1 with up +y after the dead zone, triggers 0..1; each L or R press is one speed click.
|
||||
// Locked, the view stays and the game gets the input.
|
||||
typedef struct { float lx, ly, rx, ry, lt, rt; } FreecamPad;
|
||||
enum { FREECAM_OFF, FREECAM_MOVE, FREECAM_LOCK };
|
||||
int freecam_available(void); // game 1.4.3 with the freecam patch set on
|
||||
int freecam_state(void); // FREECAM_*
|
||||
void freecam_cycle(void); // off, move, lock, off; logs; input thread
|
||||
void freecam_pad(const FreecamPad *p);
|
||||
void freecam_speed_click(int faster); // R (1) doubles the speed, L (0) halves it
|
||||
void freecam_mouse(double right_deg, double down_deg); // a turn from the mouse, added at the next step
|
||||
// How far the open gamepad's left (pct[0]) and right (pct[1]) sticks are from the centre now, in percent of full
|
||||
// deflection, before the dead zone: the menu shows it on the dead zone rows, so a drifting stick's resting value can be
|
||||
// read off. 0 (and both 0) without a connected gamepad. Any thread.
|
||||
|
||||
+4
-4
@@ -66,13 +66,13 @@ const char *input_pad_name(int pad) { return pad > PAD_NONE && pad < PAD_COUNT ?
|
||||
|
||||
void input_map_reset(void) { input_map = defaults; }
|
||||
|
||||
static int key_id(const char *name) {
|
||||
int input_key_id(const char *name) {
|
||||
for (int k = KEY_A; k < KEY_COUNT; k++)
|
||||
if (key_names[k] && !strcasecmp(key_names[k], name)) return k;
|
||||
return KEY_NONE;
|
||||
}
|
||||
|
||||
static int pad_id(const char *name) {
|
||||
int input_pad_id(const char *name) {
|
||||
for (int p = PAD_SOUTH; p < PAD_COUNT; p++)
|
||||
if (!strcasecmp(pad_names[p], name)) return p;
|
||||
return PAD_NONE;
|
||||
@@ -133,12 +133,12 @@ int input_map_bind(const char *button, const char *list) {
|
||||
int ok = 0;
|
||||
if (!strncasecmp(tok, "pad:", 4) && action < B_SL_LEFT) {
|
||||
const char *name = trim(tok + 4);
|
||||
int p = pad_id(name);
|
||||
int p = input_pad_id(name);
|
||||
if (!strcasecmp(name, "default")) pad_def = ok = 1;
|
||||
else if (p && np < INPUT_PAD_BINDING_MAX) pads[np++] = (uint8_t)p, ok = 1;
|
||||
} else if (!strncasecmp(tok, "key:", 4)) {
|
||||
const char *name = trim(tok + 4);
|
||||
int k = key_id(name);
|
||||
int k = input_key_id(name);
|
||||
if (!strcasecmp(name, "default")) key_def = ok = 1;
|
||||
else if (k && nk < INPUT_BINDING_MAX) keys[nk++] = (uint8_t)k, ok = 1;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@ void input_map_reset(void);
|
||||
// stick directions the keys drive), then SHAKE. Keys: a-z 0-9 space tab lshift ... (key_names in input_map.c). Pads: south east ...
|
||||
const char *input_action_name(int action);
|
||||
const char *input_key_name(int key);
|
||||
int input_key_id(const char *name); // KEY_NONE for a name without a key
|
||||
int input_pad_id(const char *name); // PAD_NONE for a name without a gamepad button
|
||||
const char *input_pad_name(int pad);
|
||||
// Replaces every binding of the action `button` (an action name) with `list`: comma separated "pad:<name>" and
|
||||
// "key:<name>" entries, "key:default" / "pad:default" for that part's defaults, or "none" for no input. A part the list
|
||||
|
||||
@@ -27,8 +27,8 @@ layout(location = 0) in vec4 uv;
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
layout(set = 0, binding = 0, std140) uniform SupportBuffer {
|
||||
vec4 pad[90];
|
||||
vec4 hdr; // byte 1440 (vk_exec_draw.c support_fill): game white / HUD white, peak / game white, hue correction
|
||||
vec4 pad[92];
|
||||
vec4 hdr; // byte 1472 (vk_exec_draw.c support_fill): game white / HUD white, peak / game white, hue correction
|
||||
} support_buffer;
|
||||
layout(set = 0, binding = 1) uniform sampler2D fp_t_tcb_8;
|
||||
layout(set = 0, binding = 2) uniform sampler2D fp_t_tcb_A;
|
||||
|
||||
@@ -122,6 +122,8 @@ static const char *pad_label(int p) {
|
||||
return menu_text((UiTextId)(UI_PAD_SOUTH + (p - PAD_SOUTH)));
|
||||
}
|
||||
|
||||
const char *binds_pad_label(int pad) { return pad_label(pad); }
|
||||
|
||||
// The layout the gamepad cells show: the one in effect, or without a gamepad the one the setting names (Xbox for auto).
|
||||
static int shown_layout(void) {
|
||||
int l = input_pad_layout();
|
||||
|
||||
@@ -15,3 +15,5 @@ bool binds_modal(void);
|
||||
// A key setting (TOTK_ name) as a row of one key cell, set by pressing the key as a binding's cell is; Delete sets it
|
||||
// to none. note (NULL none) follows the description.
|
||||
void binds_key_row(const char *setting, UiTextId label, UiTextId desc, const char *note);
|
||||
// A gamepad input by position (PAD_*): the label the open pad has on a face button, else its place on the pad.
|
||||
const char *binds_pad_label(int pad);
|
||||
@@ -996,6 +996,37 @@ static void row_quicksave_keys(void) {
|
||||
key_taken("TOTK_QUICKLOAD_KEY", note[1], sizeof note[1]));
|
||||
}
|
||||
|
||||
// The free camera (freecam.c). Its switch is the patch set of the hook, read at start, so it is off by default and the
|
||||
// row says "after restart". Then the combo: the trigger and shoulder pairs with a stick click, named as the open pad
|
||||
// labels its buttons, or none; totk.ini takes any combo of button positions, shown as written. The key is any key or
|
||||
// mouse button, taken by the bindings' capture window (binds_key_row) as quick save's are; Delete leaves it without
|
||||
// one. A key the bindings also use says which action it presses. On other game versions the switch and the combo are
|
||||
// greyed, and while the hook does not run (the switch off, or on but not yet restarted) the combo is greyed; the key
|
||||
// row, which opt_disable_next does not grey, says why in its note.
|
||||
static void rows_freecam(void) {
|
||||
UiTextId why = rt_game_version != 143 ? UI_MENU_FREECAM_PAD_V143 : UI_MENU_FREECAM_OFF_NOTE;
|
||||
if (rt_game_version != 143) opt_disable_next(UI_MENU_FREECAM_PAD_V143);
|
||||
opt_toggle("TOTK_FREECAM_PATCH", UI_MENU_FREECAM, UI_MENU_FREECAM_DESC);
|
||||
static const char *const combos[] = {"zl+zr+lstick", "zl+zr+rstick", "l+r+lstick", "l+r+rstick", "none"};
|
||||
static const int pads[][3] = {{PAD_ZL, PAD_ZR, PAD_LSTICK}, {PAD_ZL, PAD_ZR, PAD_RSTICK},
|
||||
{PAD_L, PAD_R, PAD_LSTICK}, {PAD_L, PAD_R, PAD_RSTICK}};
|
||||
enum { N = sizeof combos / sizeof *combos };
|
||||
static char shown[N - 1][128];
|
||||
const char *names[N];
|
||||
for (int i = 0; i < N - 1; i++) {
|
||||
snprintf(shown[i], sizeof shown[i], "%s + %s + %s", binds_pad_label(pads[i][0]), binds_pad_label(pads[i][1]),
|
||||
binds_pad_label(pads[i][2]));
|
||||
names[i] = shown[i];
|
||||
}
|
||||
names[N - 1] = menu_text(UI_MENU_OFF);
|
||||
if (!freecam_available()) opt_disable_next(why);
|
||||
opt_choice_list("TOTK_FREECAM_PAD", UI_MENU_FREECAM_PAD, combos, names, N, UI_MENU_FREECAM_PAD_DESC);
|
||||
static char note[64];
|
||||
binds_key_row("TOTK_FREECAM_KEY", UI_MENU_FREECAM_KEY, UI_MENU_FREECAM_KEY_DESC,
|
||||
freecam_available() ? key_taken("TOTK_FREECAM_KEY", note, sizeof note)
|
||||
: menu_text(why));
|
||||
}
|
||||
|
||||
// The note under the prompts. The settings name a folder of prompts (input_prompts_folder: the prompts and the pad
|
||||
// layout, as a layout that puts A on the right button needs the face buttons named the other way round), but the game
|
||||
// reads its fonts and UI archive once at start (romfs.c overlay_init). While the folder in use differs: when the
|
||||
@@ -1136,6 +1167,7 @@ static void tab_controls(float scale) {
|
||||
row_quicksave_keys();
|
||||
row_walk_key();
|
||||
opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f");
|
||||
rows_freecam();
|
||||
rows_gameplay_tweaks();
|
||||
// Analog sticks: one dead zone row per stick, falling back to TOTK_STICK_DEADZONE (both sticks) while unset. With
|
||||
// a gamepad connected each row shows its stick's deflection now, before the dead zone: a drifting stick's resting
|
||||
|
||||
@@ -366,6 +366,23 @@ static const char *const text_en[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_WALK_SCALE] = "Walk scale",
|
||||
[UI_MENU_WALK_SCALE_DESC] = "The tilt the keyboard's sticks get while the walk key is held. Half is a walk, the "
|
||||
"full tilt a run.",
|
||||
[UI_MENU_FREECAM] = "Free camera",
|
||||
[UI_MENU_FREECAM_DESC] = "Lets a combo or a key below detach the view from Link and fly it. Off by default: "
|
||||
"with it off the game's camera code runs as shipped. Takes effect after a restart. "
|
||||
"Game version 1.4.3.",
|
||||
[UI_MENU_FREECAM_OFF_NOTE] = "Turn on Free camera above, then restart",
|
||||
[UI_MENU_FREECAM_PAD] = "Free camera combo",
|
||||
[UI_MENU_FREECAM_PAD_DESC] = "Gamepad buttons pressed together that step the view through three stages: it leaves "
|
||||
"Link and flies, it stays where it was left while Link plays on, and it comes back. While it flies the game "
|
||||
"gets no input: the left stick flies along the view and sideways, the triggers up and down, the right stick "
|
||||
"turns, and each press of L or R halves or doubles the speed. Locked, Link walks where the left stick points "
|
||||
"on screen. Game version 1.4.3.",
|
||||
[UI_MENU_FREECAM_PAD_V143] = "Game version 1.4.3 only",
|
||||
[UI_MENU_FREECAM_KEY] = "Free camera key",
|
||||
[UI_MENU_FREECAM_KEY_DESC] = "A key that steps the view through the same stages: it leaves Link and flies, it "
|
||||
"stays while Link plays on, and it comes back. While it flies: W A S D fly along the view and sideways, the "
|
||||
"keys bound to ZR and ZL (X and Z by default) up and down, the mouse and the arrow keys turn, and the keys "
|
||||
"bound to L and R (Q and R) halve or double the speed. Game version 1.4.3.",
|
||||
[UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Gameplay tweaks",
|
||||
[UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Gameplay tweaks",
|
||||
[UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Mouse wheel controls for Ultrahand rotation and distance, item and weapon switching, and smooth map zoom.",
|
||||
@@ -987,6 +1004,23 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_WALK_SCALE] = "Сила шага",
|
||||
[UI_MENU_WALK_SCALE_DESC] = "Отклонение стиков клавиатуры при удержании клавиши шага. Половина — шаг, полное "
|
||||
"отклонение — бег.",
|
||||
[UI_MENU_FREECAM] = "Свободная камера",
|
||||
[UI_MENU_FREECAM_DESC] = "Позволяет сочетанию или клавише ниже отделить камеру от Линка и летать ею. По "
|
||||
"умолчанию выключена: тогда код камеры игры работает без изменений. Включается после "
|
||||
"перезапуска. Версия игры 1.4.3.",
|
||||
[UI_MENU_FREECAM_OFF_NOTE] = "Включите «Свободную камеру» выше и перезапустите игру",
|
||||
[UI_MENU_FREECAM_PAD] = "Сочетание свободной камеры",
|
||||
[UI_MENU_FREECAM_PAD_DESC] = "Кнопки геймпада, нажатые вместе, переключают камеру по трём режимам: она отделяется "
|
||||
"от Линка и летает, остаётся на месте, пока Линком снова можно управлять, и возвращается. Пока камера летает, "
|
||||
"игра не получает ввод: левый стик ведёт камеру вдоль взгляда и вбок, курки — вверх и вниз, правый стик "
|
||||
"поворачивает, а каждое нажатие L или R уменьшает или увеличивает скорость вдвое. Когда камера закреплена, "
|
||||
"Линк идёт туда, куда левый стик указывает на экране. Версия игры 1.4.3.",
|
||||
[UI_MENU_FREECAM_PAD_V143] = "Только для версии игры 1.4.3",
|
||||
[UI_MENU_FREECAM_KEY] = "Клавиша свободной камеры",
|
||||
[UI_MENU_FREECAM_KEY_DESC] = "Клавиша, которая переключает те же режимы: камера отделяется от Линка и летает, "
|
||||
"остаётся на месте, пока Линком снова можно управлять, и возвращается. Пока она летает: W A S D ведут камеру "
|
||||
"вдоль взгляда и вбок, клавиши ZR и ZL (по умолчанию X и Z) — вверх и вниз, мышь и стрелки поворачивают, а "
|
||||
"клавиши L и R (Q и R) уменьшают или увеличивают скорость вдвое. Версия игры 1.4.3.",
|
||||
[UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Геймплей",
|
||||
[UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Настройки геймплея",
|
||||
[UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Управление колесом мыши: вращение и дистанция предметов в Ультраруке, выбор оружия и предметов, плавный зум карты.",
|
||||
@@ -1792,6 +1826,23 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_WALK_SCALE] = "Intensidade do andar",
|
||||
[UI_MENU_WALK_SCALE_DESC] = "A inclinação dos analógicos do teclado enquanto a tecla de andar está segura. Metade "
|
||||
"é andar, a inclinação total é correr.",
|
||||
[UI_MENU_FREECAM] = "Câmera livre",
|
||||
[UI_MENU_FREECAM_DESC] = "Permite que uma combinação ou uma tecla abaixo solte a câmera do Link e a faça voar."
|
||||
" Desligada por padrão: assim o código de câmera do jogo roda como foi lançado. Vale "
|
||||
"depois de reiniciar. Versão 1.4.3 do jogo.",
|
||||
[UI_MENU_FREECAM_OFF_NOTE] = "Ligue a Câmera livre acima e reinicie",
|
||||
[UI_MENU_FREECAM_PAD] = "Combinação da câmera livre",
|
||||
[UI_MENU_FREECAM_PAD_DESC] = "Botões do controle pressionados juntos que passam a câmera por três etapas: ela se "
|
||||
"solta do Link e voa, fica parada onde foi deixada enquanto o Link volta a ser controlado, e volta. Enquanto "
|
||||
"ela voa o jogo não recebe comandos: o analógico esquerdo voa na direção da visão e para os lados, os gatilhos "
|
||||
"sobem e descem, o analógico direito gira, e cada toque em L ou R reduz a velocidade à metade ou a dobra. Com "
|
||||
"a câmera parada, o Link anda para onde o analógico esquerdo aponta na tela. Versão do jogo 1.4.3.",
|
||||
[UI_MENU_FREECAM_PAD_V143] = "Só na versão 1.4.3 do jogo",
|
||||
[UI_MENU_FREECAM_KEY] = "Tecla da câmera livre",
|
||||
[UI_MENU_FREECAM_KEY_DESC] = "Uma tecla que passa a câmera pelas mesmas etapas: ela se solta do Link e voa, fica "
|
||||
"parada enquanto o Link volta a ser controlado, e volta. Enquanto ela voa: W A S D voam na direção da visão e "
|
||||
"para os lados, as teclas de ZR e ZL (X e Z por padrão) sobem e descem, o mouse e as setas giram, e as teclas "
|
||||
"de L e R (Q e R) reduzem a velocidade à metade ou a dobram. Versão do jogo 1.4.3.",
|
||||
[UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "Ajustes de jogabilidade",
|
||||
[UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "Ajustes de jogabilidade",
|
||||
[UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "Controles com a roda do mouse para rotação e distância na Ultramão, seleção de armas e itens, e zoom suave no mapa.",
|
||||
@@ -2548,6 +2599,14 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_WALK_KEY_TAKEN] = "同时为 %s",
|
||||
[UI_MENU_WALK_SCALE] = "步行幅度",
|
||||
[UI_MENU_WALK_SCALE_DESC] = "按住步行键时键盘摇杆的推动幅度。一半为走路,推满为奔跑。",
|
||||
[UI_MENU_FREECAM] = "自由镜头",
|
||||
[UI_MENU_FREECAM_DESC] = "允许用下方的组合键或按键让镜头脱离林克自由飞行。默认关闭:关闭时游戏的镜头代码保持原样运行。重启后生效。仅限游戏版本 1.4.3。",
|
||||
[UI_MENU_FREECAM_OFF_NOTE] = "请先打开上方的“自由镜头”,然后重启",
|
||||
[UI_MENU_FREECAM_PAD] = "自由镜头组合键",
|
||||
[UI_MENU_FREECAM_PAD_DESC] = "同时按下的手柄按键,让镜头依次切换三个阶段:脱离林克自由飞行、停在原处而林克恢复操作、回到林克。飞行期间游戏不接收输入:左摇杆沿视线方向和左右移动,扳机键上升和下降,右摇杆转动视角,每按一次 L 或 R 速度减半或加倍。镜头固定时,林克朝左摇杆在屏幕上指向的方向移动。游戏版本 1.4.3。",
|
||||
[UI_MENU_FREECAM_PAD_V143] = "仅限游戏版本 1.4.3",
|
||||
[UI_MENU_FREECAM_KEY] = "自由镜头键",
|
||||
[UI_MENU_FREECAM_KEY_DESC] = "让镜头依次切换相同阶段的按键:脱离林克自由飞行、停在原处而林克恢复操作、回到林克。飞行期间:W A S D 沿视线方向和左右移动,ZR 和 ZL 对应的按键(默认 X 和 Z)上升和下降,鼠标和方向键转动视角,L 和 R 对应的按键(默认 Q 和 R)让速度减半或加倍。游戏版本 1.4.3。",
|
||||
[UI_MENU_GROUP_GAMEPLAY_TWEAKS] = "游戏操作微调",
|
||||
[UI_MENU_GAMEPLAY_TWEAKS_ENABLED] = "启用操作微调",
|
||||
[UI_MENU_GAMEPLAY_TWEAKS_ENABLED_DESC] = "使用鼠标滚轮控制究极手物体旋转与距离、武器与道具切换以及地图平滑缩放。",
|
||||
|
||||
@@ -156,6 +156,9 @@ typedef enum {
|
||||
UI_QS_SAVED, UI_QS_LOADING, UI_QS_NOT_NOW, UI_QS_NONE, UI_QS_FAILED, UI_QS_LOAD_FAILED,
|
||||
UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC,
|
||||
UI_MENU_WALK_KEY, UI_MENU_WALK_KEY_DESC, UI_MENU_WALK_KEY_TAKEN, UI_MENU_WALK_SCALE, UI_MENU_WALK_SCALE_DESC,
|
||||
UI_MENU_FREECAM, UI_MENU_FREECAM_DESC, UI_MENU_FREECAM_OFF_NOTE,
|
||||
UI_MENU_FREECAM_PAD, UI_MENU_FREECAM_PAD_DESC, UI_MENU_FREECAM_PAD_V143,
|
||||
UI_MENU_FREECAM_KEY, UI_MENU_FREECAM_KEY_DESC,
|
||||
|
||||
// Controls tab: Gameplay tweaks
|
||||
UI_MENU_GROUP_GAMEPLAY_TWEAKS,
|
||||
|
||||
+7
-4
@@ -1754,11 +1754,14 @@ void vk_dlaa_frame(void) {
|
||||
// is always drawn, whatever fxaa says (skipping it would leave the 3D picture out), unless DLSS already wrote that
|
||||
// target this frame.
|
||||
// The stock translator's hash, the one with tools/xlate patch 0010 (PCSS, PR #89) applied, the one with patches 0010
|
||||
// and 0011 (the shadow filter spread) applied, and that one with the zero_locals job flag (Mesa, vk_caps.c).
|
||||
// A scaling draw this list misses still scales DLSS's picture, not
|
||||
// the jittered scene: after DLSS ran, passes larger than the light target sample DLSS's output (vk_dlaa_swap_img).
|
||||
// and 0011 (the shadow filter spread) applied, and that one with the zero_locals job flag (Mesa, vk_caps.c). Patch 0017
|
||||
// (soft shadows per cascade) adds two support buffer fields, which every translated shader declares, so the last two
|
||||
// change with it: the two after them. A scaling draw this list misses still scales DLSS's picture, not the jittered
|
||||
// scene: after DLSS ran, passes larger than the light target sample DLSS's output (vk_dlaa_swap_img). That draw then
|
||||
// scales an output-sized picture as if it were the scene, and the screen shows the scene's share of it, the top left,
|
||||
// stretched over the whole screen.
|
||||
static const uint64_t FXAA_FS[] = {0xf450003ebeb3dc52ull, 0x0a12f4bc2a9a4fbeull, 0x5c43ae18948d52cbull,
|
||||
0xaad42238801d31d8ull};
|
||||
0xaad42238801d31d8ull, 0xde20aef90fea4ce6ull, 0x755964e8dce7f34dull};
|
||||
// The fragment shader of the FXAA's first pass, the copy of the scene target into the scratch target (this build's
|
||||
// translator; another hash leaves the draw alone). See vk_dlaa_skip_draw for why FSR's frames skip it.
|
||||
static const uint64_t FXAA_COPY_FS[] = {0xa0fd34391f2af811ull};
|
||||
|
||||
+111
-19
@@ -16,6 +16,7 @@
|
||||
// 9365-9488, 9489-9921, 10013-10079 @ b75be8cf (MIT, Copyright (c) 2026 jhaizhou); the uniform-buffer spans, texture and
|
||||
// sampler descriptor lookups and the dispatch flow follow LAS Recomp runtime/nvn/vulkan/exec.c:1851-1908, 2300-2516
|
||||
// @ da35b83a (MIT, Copyright (c) 2026 Peiikai). The support buffer layout is Ryujinx's SupportBuffer.cs (MIT).
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
@@ -36,8 +37,10 @@
|
||||
#define MAX_DESC 1024
|
||||
#define CHUNK_BYTES (4u << 20)
|
||||
#define ZERO_BYTES 65536u
|
||||
#define SUPPORT_BYTES 1456u // Ryujinx SupportBuffer (std140): alpha_test, is_bgra[8], viewport_inverse, viewport_size, ...;
|
||||
// 1408 pcss and 1424 shadow_spread (translator patches 0010, 0011), 1440 HDR (support_fill)
|
||||
#define SUPPORT_BYTES 1488u // Ryujinx SupportBuffer (std140): alpha_test, is_bgra[8], viewport_inverse, viewport_size, ...;
|
||||
// 1408 pcss, 1424 shadow_spread, 1440 pcss_depth and 1456 pcss_scale (translator patches 0010,
|
||||
// 0011, 0017), 1472 HDR (support_fill)
|
||||
#define SUP_IN 11 // support_in: viewport size, point size, then pcss_depth and pcss_scale per cascade
|
||||
#define NVN_STAGE_VS 0
|
||||
#define NVN_STAGE_FS 1
|
||||
#define NVN_STAGE_CS 5
|
||||
@@ -245,7 +248,7 @@ typedef struct {
|
||||
uint64_t vgen;
|
||||
int vb_valid;
|
||||
uint8_t support[SUPPORT_BYTES]; // last support buffer and where it lives
|
||||
float sup_in[3]; // the support_fill arguments it was filled from
|
||||
float sup_in[SUP_IN]; // the support_fill arguments it was filled from
|
||||
VkBuffer sup_buf;
|
||||
VkDeviceSize sup_off;
|
||||
int sup_valid;
|
||||
@@ -286,7 +289,7 @@ static struct { int mode; uint64_t calls, cmds, empty; } DD = {-1};
|
||||
typedef struct { int cls, use; uint64_t bytes; } RsCount;
|
||||
typedef struct {
|
||||
uint32_t hn; // words of h the last signature filled; 0: none
|
||||
uint64_t h[24]; // generations, feedback images, support inputs, base instance
|
||||
uint64_t h[28]; // generations, feedback images, support inputs, base instance
|
||||
const VkPipeInfo *info; // the pipeline whose RsList ranges body holds, as of bind op generation gen
|
||||
uint64_t gen;
|
||||
uint8_t body[RS_BYTES];
|
||||
@@ -510,6 +513,7 @@ typedef struct VkExecDraw {
|
||||
VkDescSlot d[MAX_DESC];
|
||||
VkBufferView bv[MAX_DESC];
|
||||
RsRange rs_tmp[MAX_DESC]; // rs_list's
|
||||
struct { uint64_t addr; float key[8], out[8]; int valid; } PCSS; // pcss_cascades' last camera block and answer
|
||||
} VkExecDraw;
|
||||
|
||||
static VkExecDraw *draw_new(VkExec *ex) {
|
||||
@@ -2060,17 +2064,23 @@ static VkDescriptorSet alloc_set_batched(VkExec *ex, VkDescriptorSetLayout layou
|
||||
return alloc_set(ex, layout);
|
||||
}
|
||||
|
||||
static void support_in(const VkExec *ex, float in[3]) { // what support_fill reads: viewport size, point size
|
||||
static const float *pcss_params(void);
|
||||
static void pcss_cascades(const VkExec *ex, float out[8]);
|
||||
|
||||
// What support_fill reads: viewport size, point size, and the soft shadows' per-cascade factors (pcss_cascades).
|
||||
static void support_in(const VkExec *ex, float in[SUP_IN]) {
|
||||
float k = ex->pass_scale > 1 ? (float)ex->pass_scale : 1.0f;
|
||||
in[0] = ex->in_pass && ex->has_vp ? ex->vp[0][2] * k : (float)ex->pass_w;
|
||||
in[1] = ex->in_pass && ex->has_vp ? ex->vp[0][3] * k : (float)ex->pass_h;
|
||||
in[2] = ex->point_size > 0 ? ex->point_size : 1.0f;
|
||||
pcss_cascades(ex, in + 3);
|
||||
}
|
||||
|
||||
// TOTK_PCSS (percent, 0 = off): the pcss field of the support buffer, which translator patch 0010 reads in every
|
||||
// explicit-LOD compare on a 2D array texture (the sun cascades). x: penumbra width in UV per unit of light-space depth
|
||||
// between receiver and blocker (0 keeps the game's single compare), y and z: the narrowest and widest disc radius,
|
||||
// w: the blocker search radius, all in UV of the cascade map. Radii are in UV, so they hold at any TOTK_SHADOW_SCALE.
|
||||
// w: the blocker search radius, all in UV of the second cascade's map (pcss_cascades scales them for the others).
|
||||
// Radii are in UV, so they hold at any TOTK_SHADOW_SCALE.
|
||||
// TOTK_PCSS_K overrides the depth-to-penumbra factor at 100 percent, for tuning.
|
||||
static const float *pcss_params(void) {
|
||||
static float p[4] = {-1, 0, 0, 0};
|
||||
@@ -2086,6 +2096,86 @@ static const float *pcss_params(void) {
|
||||
return p;
|
||||
}
|
||||
|
||||
// The pcss_depth and pcss_scale fields (translator patch 0017): per sun cascade, what turns the pcss values into that
|
||||
// cascade's. The pcss radii are in UV of whichever cascade map a pixel reads, and the game's cascades differ a lot in
|
||||
// how much ground a UV spans: the measured cascades (1.4.3, Gerudo and Hyrule Field) end at about 4 to 8, 27 to 31, 120
|
||||
// and 450 m, and each map spans 3.5 to 5 times the ground of the one before. With the same UV radius everywhere a shadow
|
||||
// turned that much softer at every cascade step, a step that moves with the camera (issue #1291). The pcss values keep
|
||||
// their meaning in the second cascade, which holds most of the shadows on screen (from a few metres in front of Link
|
||||
// to about 30 m) and so is the softness players chose with pcss; the other cascades are measured against it.
|
||||
//
|
||||
// The lighting shaders read the cascades from the camera block c4 (fragment stage, 0x940 bytes, the block
|
||||
// runtime/vk_contact.c reads): rows 42 + 4c to 45 + 4c take a view-space position to cascade c's map as a projective
|
||||
// matrix (u, v, depth, w; the first cascade's w row is 0 0 0 1, the others' are not: the far maps are warped to give
|
||||
// more texels near the camera), and row 58 holds the distances where the cascades end. For each cascade the
|
||||
// derivatives of its u, v and depth along the ground are taken at the view axis (view space looks along -z) where the
|
||||
// cascade begins and where it ends, and averaged geometrically over those two points:
|
||||
// scale = s_c / s_1, with s the geometric mean of |du/dp| and |dv/dp| (UV per metre): the search and widest radius
|
||||
// cover the same ground as in the second cascade;
|
||||
// depth = (s_c / d_c) / (s_1 / d_1), with d = |d depth/dp| (depth per metre): the same penumbra per metre between
|
||||
// blocker and receiver.
|
||||
// The narrowest radius stays in texels (the shader keeps it), so the far cascades come back to about the game's own
|
||||
// filter. A draw without that block, or with values that do not make a cascade, gets 1 everywhere: the same UV values in
|
||||
// every cascade, as before this field.
|
||||
static int pcss_measure(const float *u, int c, float dist, float *s, float *d) {
|
||||
const float *m = u + 4 * (42 + 4 * c); // rows u, v, depth, w
|
||||
float p[3] = {0, 0, -dist}, h[4];
|
||||
for (int r = 0; r < 4; r++) h[r] = m[4 * r] * p[0] + m[4 * r + 1] * p[1] + m[4 * r + 2] * p[2] + m[4 * r + 3];
|
||||
if (!(h[3] > 1e-6f)) return 0;
|
||||
float len[3];
|
||||
for (int r = 0; r < 3; r++) { // d(h_r / h_3)/dp = (row_r - (h_r / h_3) row_w) / h_3
|
||||
float q = h[r] / h[3], g[3];
|
||||
for (int k = 0; k < 3; k++) g[k] = (m[4 * r + k] - q * m[12 + k]) / h[3];
|
||||
len[r] = sqrtf(g[0] * g[0] + g[1] * g[1] + g[2] * g[2]);
|
||||
}
|
||||
*s = sqrtf(len[0] * len[1]), *d = len[2];
|
||||
return *s > 1e-7f && *s < 1e4f && *d > 1e-7f && *d < 1e4f;
|
||||
}
|
||||
|
||||
static void pcss_measure_all(const float *u, float out[8]) {
|
||||
const float *end = u + 4 * 58;
|
||||
float s[4], d[4];
|
||||
for (int c = 0; c < 4; c++) {
|
||||
float near = c ? end[c - 1] : 0.0f, far = end[c];
|
||||
if (!(far > near) || !(far < 1e5f)) return;
|
||||
float s0, d0, s1, d1;
|
||||
if (!pcss_measure(u, c, c ? near : 0.5f * far, &s0, &d0) || !pcss_measure(u, c, far, &s1, &d1)) return;
|
||||
s[c] = sqrtf(s0 * s1), d[c] = sqrtf(d0 * d1);
|
||||
}
|
||||
float r[8];
|
||||
for (int c = 0; c < 4; c++) {
|
||||
float sc = s[c] / s[1], dc = (s[c] / d[c]) / (s[1] / d[1]);
|
||||
if (!(sc > 1e-4f && sc < 1e2f) || !(dc > 1e-3f && dc < 1e3f)) return;
|
||||
r[c] = dc, r[4 + c] = sc;
|
||||
}
|
||||
memcpy(out, r, sizeof r);
|
||||
static volatile int32_t logged;
|
||||
if (!__atomic_exchange_n(&logged, 1, __ATOMIC_RELAXED))
|
||||
rt_log("vk: soft shadows per cascade (cascades end at %.1f, %.1f, %.1f and %.1f m): ground scale %.3f, 1, %.3f, "
|
||||
"%.3f; penumbra factor %.3f, 1, %.3f, %.3f", end[0], end[1], end[2], end[3], out[4], out[6], out[7], out[0],
|
||||
out[2], out[3]);
|
||||
}
|
||||
|
||||
// support_in asks for every draw that binds the support buffer, twice (bind_sig and bind_resources), and the camera
|
||||
// block changes once a frame: the answer is kept with the block's address and its first cascade's u row and cascade
|
||||
// ends, which move whenever the camera or the sun does.
|
||||
static void pcss_cascades(const VkExec *ex, float out[8]) {
|
||||
for (int i = 0; i < 8; i++) out[i] = 1.0f;
|
||||
if (!(pcss_params()[0] > 0)) return;
|
||||
const p_bind_buf *b = &ex->ubo[NVN_STAGE_FS][1];
|
||||
if (!b->addr || b->size != 0x940) return;
|
||||
const float *u = (const float *)(uintptr_t)b->addr;
|
||||
float key[8];
|
||||
memcpy(key, u + 4 * 42, 16), memcpy(key + 4, u + 4 * 58, 16);
|
||||
VkExecDraw *D = ex->draw;
|
||||
if (D && D->PCSS.valid && D->PCSS.addr == b->addr && !memcmp(key, D->PCSS.key, sizeof key)) {
|
||||
memcpy(out, D->PCSS.out, sizeof D->PCSS.out);
|
||||
return;
|
||||
}
|
||||
pcss_measure_all(u, out);
|
||||
if (D) D->PCSS.addr = b->addr, memcpy(D->PCSS.key, key, sizeof key), memcpy(D->PCSS.out, out, sizeof D->PCSS.out), D->PCSS.valid = 1;
|
||||
}
|
||||
|
||||
// The shadow_spread field of the support buffer: the factor translator patch 0011 applies to the lighting shaders' sun
|
||||
// shadow filter offset (element 56 .xy of their lighting block), 1 / TOTK_SHADOW_SCALE. The game spaces its four
|
||||
// compares for its own shadow map texels; with maps TOTK_SHADOW_SCALE times larger, the same offset in UV spans that
|
||||
@@ -2102,7 +2192,8 @@ static const float *shadow_spread_params(void) {
|
||||
return p;
|
||||
}
|
||||
|
||||
static void support_fill(uint8_t *b, float w, float h, float point_size) {
|
||||
static void support_fill(uint8_t *b, const float in[SUP_IN]) {
|
||||
float w = in[0], h = in[1], point_size = in[2];
|
||||
memset(b, 0, SUPPORT_BYTES);
|
||||
float inv[4] = {w > 0 ? 2.0f / w : 0, h > 0 ? 2.0f / h : 0, 0, 0}, size[4] = {w, h, 0, 0};
|
||||
memcpy(b + 144, inv, 16);
|
||||
@@ -2111,11 +2202,12 @@ static void support_fill(uint8_t *b, float w, float h, float point_size) {
|
||||
memcpy(b + 1392, &point_size, 4); // point_size (translator patch 0008): vertex shaders that write none output it
|
||||
memcpy(b + 1408, pcss_params(), 16); // pcss (translator patch 0010): soft sun shadows in the cascade compares
|
||||
memcpy(b + 1424, shadow_spread_params(), 16); // shadow_spread (translator patch 0011): sun shadow filter width
|
||||
memcpy(b + 1440, in + 3, 32); // pcss_depth and pcss_scale (translator patch 0017): soft shadows per cascade
|
||||
for (int i = 0; i < 73; i++) memcpy(b + 192 + 16 * i, &one, 4); // render scale 1: the host renders at guest size
|
||||
if (vk_hdr_wanted()) { // read by the HDR tonemap only (shaders/hdr_tonemap.frag), which declares it past the translator's
|
||||
float hdr[4];
|
||||
vk_hdr_support(hdr);
|
||||
memcpy(b + 1440, hdr, 16);
|
||||
memcpy(b + 1472, hdr, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2396,13 +2488,13 @@ static int bind_sig(const VkExec *ex, const VkPipeInfo *info) {
|
||||
PUT(vk_mem_gen() + vk_usnap_gen() + ex->drop_n); // all only grow in a submission; drop_n: copies a chunk passed
|
||||
for (int i = 0; i < ex->nfbl && i < 9; i++) PUT((uintptr_t)ex->fbl_img[i]);
|
||||
if (l->sup) {
|
||||
float in[3];
|
||||
float in[SUP_IN + 1] = {0};
|
||||
support_in(ex, in);
|
||||
uint64_t a;
|
||||
uint32_t ps;
|
||||
memcpy(&a, in, 8), memcpy(&ps, &in[2], 4);
|
||||
PUT(a);
|
||||
PUT(ps);
|
||||
for (int i = 0; i < SUP_IN; i += 2) {
|
||||
uint64_t a;
|
||||
memcpy(&a, &in[i], 8);
|
||||
PUT(a);
|
||||
}
|
||||
}
|
||||
if (l->c0) PUT(D->c0_binst);
|
||||
for (int i = 0; i < l->np; i++) PUT(ubo_ptr(ex, l->p[i].st, l->p[i].res));
|
||||
@@ -2587,11 +2679,11 @@ static void bind_resources(VkExec *ex, const VkPipeInfo *info, const uint64_t *b
|
||||
if (meta) memset(&meta[nd], 0, cnt * sizeof *meta);
|
||||
#define BI_CUR(k) (D->BI.cur = meta ? &meta[nd + (k)] : NULL)
|
||||
if (b->kind == VK_PIPE_SUPPORT) {
|
||||
float in[3];
|
||||
float in[SUP_IN];
|
||||
support_in(ex, in);
|
||||
if (!D->B.sup_valid || MX_NE(in, D->B.sup_in, sizeof in)) { // support_fill reads only these
|
||||
uint8_t tmp[SUPPORT_BYTES];
|
||||
support_fill(tmp, in[0], in[1], in[2]);
|
||||
support_fill(tmp, in);
|
||||
MX_CPY(D->B.sup_in, in, sizeof in);
|
||||
if (!D->B.sup_valid || MX_NE(tmp, D->B.support, SUPPORT_BYTES)) { // a new buffer only when the contents changed
|
||||
VkBuffer sb;
|
||||
@@ -3517,7 +3609,7 @@ static struct {
|
||||
uint32_t ndesc, cdesc;
|
||||
NVNbufferRange vin[17]; // the vertex ranges MQ.vb[nvb - 1] was resolved from, under vk_mem_gen vgen
|
||||
uint64_t vgen;
|
||||
float sup_in[3]; // the support buffer last filled for the list and its inputs
|
||||
float sup_in[SUP_IN]; // the support buffer last filled for the list and its inputs
|
||||
VkDescriptorBufferInfo sup;
|
||||
float par_in[4]; // the fragment shader's parameters last written and their inputs
|
||||
VkDescriptorBufferInfo par;
|
||||
@@ -3617,12 +3709,12 @@ static int mo_desc(VkExec *ex, const VkPipeInfo *info, MoDraw *q) {
|
||||
VkDescSlot *o = &d[nd];
|
||||
int st = nvn_stage_of(b->stage);
|
||||
if (b->kind == VK_PIPE_SUPPORT) {
|
||||
float in[3];
|
||||
float in[SUP_IN];
|
||||
support_in(ex, in);
|
||||
if (!MQ.sup.buffer || memcmp(in, MQ.sup_in, sizeof in)) {
|
||||
VkBuffer sb;
|
||||
VkDeviceSize so;
|
||||
support_fill(scratch(ex, SUPPORT_BYTES, &sb, &so), in[0], in[1], in[2]);
|
||||
support_fill(scratch(ex, SUPPORT_BYTES, &sb, &so), in);
|
||||
MQ.sup = (VkDescriptorBufferInfo){sb, so, SUPPORT_BYTES};
|
||||
memcpy(MQ.sup_in, in, sizeof in);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user