diff --git a/runtime/cfg.c b/runtime/cfg.c index 84abed08..11cebb4a 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -30,7 +30,7 @@ static int save_ok = 1; // the last cfg_save_to wrote (o // Every name the runtime reads (and the patch sets in generated/), without the prefix. A file key outside this list is // logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line. static const char *const known[] = { - "AB", "APP_POOL", "ASSUME_FOCUS", "ASTC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS", + "AB", "ANISO", "APP_POOL", "ASSUME_FOCUS", "ASTC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_OFF", "AUDIO_PREFILL_MS", "BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT", "BIND_LSTICK_RIGHT", "BIND_LSTICK_UP", "BIND_MINUS", "BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_RSTICK_DOWN", "BIND_RSTICK_LEFT", "BIND_RSTICK_RIGHT", "BIND_RSTICK_UP", @@ -47,7 +47,7 @@ static const char *const known[] = { "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHECK", "RESOLVE_CHECK", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES", "ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE", - "SHADER_MEMO", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", "SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "SWKBD_ANSWER", + "SHADER_MEMO", "SHADOW_SCALE", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", "SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "SWKBD_ANSWER", "SWKBD_TEST", "TEST_PREPARE_SHADERS", "TEX_ALIAS", "TEX_MEMO", "TIMER_1MS", "TRACE", "UBO_SNAPSHOT", "UPSCALER", "VK_DYN_VERTEX", "VK_NO_FLOAT64", "VK_PRESENT", "VK_RECORDER", "VK_SSBO_ALIGN", "VK_SUBGROUP", "VK_SUBGROUP_PIN", "VK_VALIDATION", "VOLUME", "VRAM_HEADROOM", "VS_OUTS", "WINDOW_SIZE", "XLATE", "XLATE_ID", "XLATE_PROCS", "ZSTD_CHECK", "ZSTD_NATIVE", @@ -59,7 +59,7 @@ static const struct { const char *key, *section; } sections[] = { {"REALTIME", "frame rate"}, {"CLOTH_REALTIME", "frame rate"}, {"HIGHFPS_FIX", "frame rate"}, {"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"PERF_OVERLAY", "display"}, {"VK_PRESENT", "display"}, {"GPU_INDEX", "display"}, {"OUTPUT_RES", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"}, - {"SHARPNESS", "display"}, + {"SHARPNESS", "display"}, {"ANISO", "display"}, {"SHADOW_SCALE", "display"}, {"MENU_LANG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"}, {"VOLUME", "audio"}, {"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, @@ -93,6 +93,7 @@ static const CfgMeta metas[] = { {"PERF_OVERLAY", "off", "off|fps|full", LIVE}, {"OUTPUT_RES", "1920x1080", NULL, RESTART}, {"RENDER_SCALE", "game", "game|50|67|75|100|125|150|200", RESTART}, {"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE}, + {"ANISO", "16", "game|2|4|8|16", RESTART}, {"SHADOW_SCALE", "1", "1..4", RESTART}, // Game {"FPS_LIMIT", "60", "30|60|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE}, {"REALTIME", "1", "0|1", RESTART}, {"CLOTH_REALTIME", "1", "0|1", RESTART}, diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 64c3c4c0..a9ee648f 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -438,6 +438,19 @@ static void row_render_scale(void) { opt_choice_list("TOTK_RENDER_SCALE", UI_MENU_RENDER_SCALE, vals, names, N, UI_MENU_RENDER_SCALE_DESC); } +static void row_aniso(void) { + static const char *const vals[] = {"game", "2", "4", "8", "16"}; + static const char *names[] = {NULL, "2x", "4x", "8x", "16x"}; + names[0] = menu_text(UI_MENU_ANISO_GAME); + opt_choice_list("TOTK_ANISO", UI_MENU_ANISO, vals, names, 5, UI_MENU_ANISO_DESC); +} + +static void row_shadow_scale(void) { + static const char *const vals[] = {"1", "2", "3", "4"}; + static const char *const names[] = {"960 (1x)", "1920 (2x)", "2880 (3x)", "3840 (4x)"}; + opt_choice_list("TOTK_SHADOW_SCALE", UI_MENU_SHADOW_SCALE, vals, names, 4, UI_MENU_SHADOW_SCALE_DESC); +} + static void row_gpu(void) { const char *vals[MAX_GPUS + 1], *names[MAX_GPUS + 1]; char idx[MAX_GPUS][4]; @@ -528,6 +541,8 @@ static void tab_screen(float scale) { static const UiTextId up[] = {UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR}; opt_choice("TOTK_UPSCALER", UI_MENU_UPSCALER, up, 2, UI_MENU_UPSCALER_DESC); opt_slider("TOTK_SHARPNESS", UI_MENU_SHARPNESS, 0, 100, UI_MENU_SHARPNESS_DESC, 5, "%.0f %%"); + row_aniso(); + row_shadow_scale(); opt_end(); } diff --git a/runtime/ui_text.c b/runtime/ui_text.c index f93107ae..aa31587e 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -63,6 +63,13 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_UPSCALER_FSR] = "AMD FSR 1", [UI_MENU_UPSCALER_BILINEAR] = "Bilinear", [UI_MENU_SHARPNESS] = "FSR sharpness", [UI_MENU_SHARPNESS_DESC] = "Sharpening after FSR scaling; 0 turns it off.", + [UI_MENU_ANISO] = "Anisotropic filtering", + [UI_MENU_ANISO_DESC] = "Keeps ground and walls seen at a steep angle sharp. The game's own level is the Switch's; " + "16x costs little on a desktop GPU.", + [UI_MENU_ANISO_GAME] = "The game's", + [UI_MENU_SHADOW_SCALE] = "Shadow resolution", + [UI_MENU_SHADOW_SCALE_DESC] = "Draws the sun's shadow maps this many times larger on each side than the game's 960x960: " + "sharper shadow edges and leaf shadows. Takes effect at the next start.", [UI_MENU_FPS_LIMIT] = "Frame rate limit", [UI_MENU_FPS_LIMIT_DESC] = "The most frames per second the game draws. Above 60 is experimental and needs Game speed " @@ -281,6 +288,13 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_UPSCALER_FSR] = "AMD FSR 1", [UI_MENU_UPSCALER_BILINEAR] = "Билинейное", [UI_MENU_SHARPNESS] = "Резкость FSR", [UI_MENU_SHARPNESS_DESC] = "Повышение резкости после масштабирования FSR; 0 выключает его.", + [UI_MENU_ANISO] = "Анизотропная фильтрация", + [UI_MENU_ANISO_DESC] = "Сохраняет чёткость земли и стен под острым углом. Уровень самой игры — как на Switch; " + "16x почти ничего не стоит настольной видеокарте.", + [UI_MENU_ANISO_GAME] = "Как в игре", + [UI_MENU_SHADOW_SCALE] = "Разрешение теней", + [UI_MENU_SHADOW_SCALE_DESC] = "Карты теней от солнца рисуются во столько раз больше по каждой стороне, чем 960x960 " + "самой игры: края теней и тени листвы чётче. Действует после перезапуска.", [UI_MENU_FPS_LIMIT] = "Ограничение частоты кадров", [UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Выше 60 — экспериментальный режим, нужна «Скорость " diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 6eb805cf..680e9cfe 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -36,6 +36,8 @@ typedef enum { UI_MENU_RENDER_SCALE, UI_MENU_RENDER_SCALE_DESC, UI_MENU_RENDER_SCALE_GAME, UI_MENU_UPSCALER, UI_MENU_UPSCALER_DESC, UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR, UI_MENU_SHARPNESS, UI_MENU_SHARPNESS_DESC, + UI_MENU_ANISO, UI_MENU_ANISO_DESC, UI_MENU_ANISO_GAME, + UI_MENU_SHADOW_SCALE, UI_MENU_SHADOW_SCALE_DESC, // Game UI_MENU_FPS_LIMIT, UI_MENU_FPS_LIMIT_DESC, UI_MENU_FPS_30, UI_MENU_FPS_60, UI_MENU_FPS_120, UI_MENU_FPS_144, diff --git a/runtime/vk.h b/runtime/vk.h index 961f2f35..fdfaf319 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -268,6 +268,9 @@ typedef struct { uint8_t fb_usage; // created with ATTACHMENT_FEEDBACK_LOOP usage (VK_FEEDBACK_LAYOUT, attachable images) uint8_t fb_learned; // a draw sampled it while it was a written attachment of the open pass: its passes // attach it in ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT (vk_exec.c vk_exec_pass_begin) + uint8_t scale; // 1, or TOTK_SHADOW_SCALE for a shadow map made larger than the game's (vk_texture.c + // shadow_scale_of): width and height above are the larger ones, the game's regions + // are multiplied by it } VkTexImage; const VkTexImage *vk_texture_get(const tex_t *t); // created and made current; NULL for BUFFER or unmapped formats // A texture slot; a slot whose texture was finalized follows the live texture at the same storage (hle_nvn.c). diff --git a/runtime/vk_exec.c b/runtime/vk_exec.c index d82c0574..0abd2b63 100644 --- a/runtime/vk_exec.c +++ b/runtime/vk_exec.c @@ -192,6 +192,7 @@ static void resolve_target(const tex_t *t, const view_t *v, int has_v, int depth } o->image = img->image; o->img = img; + o->scale = img->scale ? img->scale : 1; o->format = fmt; o->view_type = layers > 1 ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D; o->aspect = depth_slot ? img->aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) @@ -227,7 +228,7 @@ static void resolve_rt(VkExec *ex) { ex->rt_resolved = 1; const p_set_rt *r = &ex->rt; int n = r->n < 0 ? 0 : r->n > 8 ? 8 : r->n; - uint32_t w = UINT32_MAX, h = UINT32_MAX, layers = UINT32_MAX, samples = 0; + uint32_t w = UINT32_MAX, h = UINT32_MAX, layers = UINT32_MAX, samples = 0, scale = 1; for (int i = 0; i < 8; i++) { VkExecTarget *t = &ex->color[i]; resolve_target(i < n ? r->color[i] : NULL, &r->cview[i], i < n && r->has_cview[i], 0, t); @@ -238,6 +239,7 @@ static void resolve_rt(VkExec *ex) { if (t->height < h) h = t->height; if (t->layers < layers) layers = t->layers; if (!samples) samples = t->samples; + if (t->scale > scale) scale = t->scale; } VkExecTarget *d = &ex->depth; resolve_target(r->depth, &r->dview, r->has_dview, 1, d); @@ -249,6 +251,7 @@ static void resolve_rt(VkExec *ex) { if (d->height < h) h = d->height; if (d->layers < layers) layers = d->layers; if (!samples) samples = d->samples; + if (d->scale > scale) scale = d->scale; } ex->pass_noatt = w == UINT32_MAX; if (ex->pass_noatt) { @@ -260,6 +263,7 @@ static void resolve_rt(VkExec *ex) { ex->vp[0][1], ex->vp[0][2], ex->vp[0][3]); } ex->pass_w = w, ex->pass_h = h, ex->pass_layers = layers; + ex->pass_scale = ex->pass_noatt ? 1 : scale; ex->pass_ncolor = (uint32_t)n; ex->pass_samples = samples ? samples : 1; ex->pipe.samples = (uint8_t)ex->pass_samples; @@ -511,8 +515,9 @@ VkBuffer vk_exec_inline_buffer(VkDeviceSize size) { VkRect2D vk_exec_scissor(const VkExec *ex) { int64_t w = ex->pass_w, h = ex->pass_h; if (!ex->has_scissor) return (VkRect2D){{0, 0}, {(uint32_t)w, (uint32_t)h}}; - int64_t x0 = ex->scissor.x, y0 = ex->scissor.y; - int64_t x1 = x0 + ex->scissor.w, y1 = y0 + ex->scissor.h; + int64_t k = ex->pass_scale > 1 ? ex->pass_scale : 1; + int64_t x0 = ex->scissor.x * k, y0 = ex->scissor.y * k; + int64_t x1 = x0 + (int64_t)ex->scissor.w * k, y1 = y0 + (int64_t)ex->scissor.h * k; if (x0 < 0) x0 = 0; if (y0 < 0) y0 = 0; if (x1 > w) x1 = w; diff --git a/runtime/vk_exec.h b/runtime/vk_exec.h index c81d5c61..b0095f63 100644 --- a/runtime/vk_exec.h +++ b/runtime/vk_exec.h @@ -35,6 +35,7 @@ typedef struct { uint32_t width, height, samples; // extent of that level; with blocks, in blocks int32_t nvn_format; // NVNformat of the view (VkPipeState.color_fmt / depth_fmt) const VkTexImage *img; // the image (fb_usage, fb_learned) + uint8_t scale; // VkTexImage.scale } VkExecTarget; // The replay state. One instance lives for the run: NVN state is queue state and carries over from one submission to @@ -52,6 +53,8 @@ typedef struct VkExec { int rt_resolved; // color[] and depth hold this command buffer's images for rt VkExecTarget color[8], depth; // resolved targets uint32_t pass_w, pass_h, pass_layers; // render area and layer count of the open (or next) pass + uint32_t pass_scale; // its targets' VkTexImage.scale: game viewports and scissors + // are multiplied by it int pass_noatt; // the pass has no attachment: its size follows the draws (vk_exec_noatt_dims) VkFormat pass_color[8], pass_depth, pass_stencil; // attachment formats of the pass (VkPipelineRenderingCreateInfo); // VK_FORMAT_UNDEFINED: none diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index e9326df5..e23741e9 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -1240,8 +1240,9 @@ static VkDescriptorSet alloc_set(VkExec *ex, VkDescriptorSetLayout layout) { } static void support_in(const VkExec *ex, float in[3]) { // what support_fill reads: viewport size, point size - in[0] = ex->in_pass && ex->has_vp ? ex->vp[0][2] : (float)ex->pass_w; - in[1] = ex->in_pass && ex->has_vp ? ex->vp[0][3] : (float)ex->pass_h; + 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; } @@ -1670,7 +1671,10 @@ static void record_fixed(VkExec *ex) { VkCommandBuffer cb = ex->cb; if (ex->dirty & VK_EXEC_DIRTY_VIEWPORT) { float x = 0, y = 0, w = (float)ex->pass_w, h = (float)ex->pass_h; - if (ex->has_vp) x = ex->vp[0][0], y = ex->vp[0][1], w = ex->vp[0][2], h = ex->vp[0][3]; + if (ex->has_vp) { + float k = ex->pass_scale > 1 ? (float)ex->pass_scale : 1.0f; + x = ex->vp[0][0] * k, y = ex->vp[0][1] * k, w = ex->vp[0][2] * k, h = ex->vp[0][3] * k; + } if (w < 1) w = 1; if (h < 1) h = 1; VkViewport v = {x, y + h, w, -h, ex->depth_range[0], ex->depth_range[1]}; // the y flip: negative height diff --git a/runtime/vk_exec_xfer.c b/runtime/vk_exec_xfer.c index 34548153..ffb3b420 100644 --- a/runtime/vk_exec_xfer.c +++ b/runtime/vk_exec_xfer.c @@ -352,10 +352,11 @@ static int sub_resolve(const tex_t *t, const view_t *v, int has_v, const NVNcopy s->level = has_v && v->set_levels ? v->base_level : 0; s->layer0 = has_v && v->set_layers ? v->min_layer : 0; uint32_t lw = max1(img->width >> s->level), lh = max1(img->height >> s->level); - s->x = r->xoffset, s->y = r->yoffset, s->z = r->zoffset; + int k = img->scale > 1 ? img->scale : 1; // a larger shadow map: the game's region in its texels + s->x = r->xoffset * k, s->y = r->yoffset * k, s->z = r->zoffset; s->nz = r->depth > 0 ? (uint32_t)r->depth : 1; - s->w = r->width > 0 ? (uint32_t)r->width : defaults_to_level ? (s->x < (int32_t)lw ? lw - (uint32_t)s->x : 0) : 0; - s->h = r->height > 0 ? (uint32_t)r->height : defaults_to_level ? (s->y < (int32_t)lh ? lh - (uint32_t)s->y : 0) : 0; + s->w = r->width > 0 ? (uint32_t)r->width * k : defaults_to_level ? (s->x < (int32_t)lw ? lw - (uint32_t)s->x : 0) : 0; + s->h = r->height > 0 ? (uint32_t)r->height * k : defaults_to_level ? (s->y < (int32_t)lh ? lh - (uint32_t)s->y : 0) : 0; int is3d = img->type == VK_IMAGE_TYPE_3D; uint32_t layers = is3d ? 1 : (uint32_t)s->z + s->nz, first = is3d ? 0 : s->layer0; if (s->level >= img->levels || s->x < 0 || s->y < 0 || s->z < 0 || !s->w || !s->h || @@ -411,6 +412,10 @@ static int buffer_side(const VkExec *ex, const Sub *s, uint64_t addr, uint64_t * static void copy_buffer_image(VkExec *ex, const p_copy_b2t *p, int to_image) { Sub s; if (!sub_resolve(p->tex, &p->view, p->has_view, &p->r, 1, &s)) return; + if (s.img->scale > 1) { // the buffer holds the game's texel count, the image more + warn_once(W_REGION, "buffer copy of a shadow map enlarged by TOTK_SHADOW_SCALE: skipped"); + return; + } uint64_t size; VkBufferImageCopy c; VkMemSpan m; diff --git a/runtime/vk_texture.c b/runtime/vk_texture.c index b65f21e7..e2fda908 100644 --- a/runtime/vk_texture.c +++ b/runtime/vk_texture.c @@ -273,6 +273,33 @@ static void init_image(Tex *e, VkCommandBuffer cb) { } } +// TOTK_SHADOW_SCALE (1 to 4): the game's shadow maps are made this many times larger on each side. TotK renders its +// sun cascades into a 960x960 DEPTH16 2D array of 4 layers and its static shadows into 1440x1440 and 720x720 arrays of 2, +// whatever the output resolution, and shrinks the cascades under load (872, 848, 800, 480 and so on). Those are made +// larger here: render passes into them scale the game's viewports and scissors (vk_exec.c resolve_rt, pass_scale), +// copies scale their regions (vk_exec_xfer.c sub_resolve), and shaders sample them with normalised coordinates, so the +// game sees nothing of it. A map whose storage the CPU writes (mirrored) or that aliases pool memory keeps its size, +// as its texels must match the guest layout. +static int shadow_scale(void) { + static int scale = -1; + if (scale < 0) { + int s = cfg_int("TOTK_SHADOW_SCALE"); + s = s < 1 ? 1 : s > 4 ? 4 : s; + rt_log("vk: shadow map scale %d", s); + scale = s; + } + return scale; +} + +static int shadow_scale_of(const nvn_texdesc *d, const TexVkFormat *f, uint32_t samples, int mirrored) { + int scale = shadow_scale(); + if (scale == 1 || mirrored || samples > 1 || d->format != NVN_FORMAT_DEPTH16 || !f->depth) return 1; + if (d->target != NVN_TEXTURE_TARGET_2D_ARRAY || d->width != d->height || d->width < 256 || d->depth < 2 || d->depth > 4) + return 1; + uint32_t most = vk_ctx()->props.limits.maxImageDimension2D; + return d->width * (uint32_t)scale <= most ? scale : 1; +} + // defer_init: the caller records the image's first transition (init_image or alias_copy). static Tex *create_tex(const tex_t *t, const TexKey *k, int defer_init) { static volatile long n_unmapped, n_unsupported, n_failed, n_unbound; @@ -300,6 +327,8 @@ static Tex *create_tex(const tex_t *t, const TexKey *k, int defer_init) { case NVN_TEXTURE_TARGET_CUBEMAP: case NVN_TEXTURE_TARGET_CUBEMAP_ARRAY: layers = L.layers; break; default: break; } + int scale = shadow_scale_of(d, &f, d->samples > 1 ? (uint32_t)d->samples : 1, tex_mirrored(t)); + w *= (uint32_t)scale, h *= (uint32_t)scale; uint32_t levels = umax(d->levels, 1), most = 1; for (uint32_t s = umax(umax(w, h), depth); s > 1; s >>= 1) most++; if (levels > most) levels = most; @@ -342,7 +371,7 @@ static Tex *create_tex(const tex_t *t, const TexKey *k, int defer_init) { e->f = f; e->pub.addr = k->addr; VkImage img = VK_NULL_HANDLE; - if (nvn_gpu_only(k->addr)) { // storage in a physical or virtual pool: alias the pool memory (section 3.2) + if (scale == 1 && nvn_gpu_only(k->addr)) { // storage in a physical or virtual pool: alias the pool memory (section 3.2) if (vkCreateImage(c->device, &ci, NULL, &img) == VK_SUCCESS && !bind_pool_memory(c, e, img)) { vkDestroyImage(c->device, img, NULL); img = VK_NULL_HANDLE; @@ -384,6 +413,7 @@ static Tex *create_tex(const tex_t *t, const TexKey *k, int defer_init) { p->bound = e->bound_to != NULL; p->block_views = (uint8_t)block_views; p->fb_usage = (uint8_t)fb_usage; + p->scale = (uint8_t)scale; if (!defer_init) { init_image(e, vk_upload_begin()); @@ -1421,6 +1451,7 @@ static VkCompareOp compare_op(uint32_t f) { } static struct { int init, mirror_clamp_edge, minmax, border_no_format; } sf; +static float aniso_force; // TOTK_ANISO: 0 = the game's level, else the least level of mipmapped colour samplers static void sampler_features(VkCtx *c) { if (sf.init) return; @@ -1432,6 +1463,9 @@ static void sampler_features(VkCtx *c) { sf.mirror_clamp_edge = f12.samplerMirrorClampToEdge; sf.minmax = f12.samplerFilterMinmax; sf.border_no_format = c->has_custom_border_color && cbf.customBorderColors && cbf.customBorderColorWithoutFormat; + const char *an = cfg_value("TOTK_ANISO"); + aniso_force = strcmp(an, "game") ? (float)atoi(an) : 0; + rt_log("vk: anisotropic filtering: %s", aniso_force > 1 ? an : "the game's"); sf.init = 1; } @@ -1466,13 +1500,23 @@ static VkSampler make_sampler(VkCtx *c, const samp_par *d) { if (si.maxLod < si.minLod) si.maxLod = si.minLod; float lim = c->props.limits.maxSamplerLodBias; si.mipLodBias = fmaxf(-lim, fminf(lim, d->lod_bias)); - if (d->aniso > 1) { + float aniso = d->aniso; + // TOTK_ANISO raises the level for filtered, mipmapped colour samplers only: depth-compare (shadow) samplers and + // nearest or unmipmapped ones (data maps, LUTs) keep what the game set. + if (aniso_force > 1 && !d->cmp_mode && si.magFilter == VK_FILTER_LINEAR && si.minFilter == VK_FILTER_LINEAR && + (mf == NVN_MIN_FILTER_LINEAR_MIPMAP_NEAREST || mf == NVN_MIN_FILTER_LINEAR_MIPMAP_LINEAR) && aniso < aniso_force) + aniso = aniso_force; + if (aniso > 1) { si.anisotropyEnable = VK_TRUE; - si.maxAnisotropy = fminf(d->aniso, c->props.limits.maxSamplerAnisotropy); + si.maxAnisotropy = fminf(aniso, c->props.limits.maxSamplerAnisotropy); } if (d->cmp_mode) { si.compareEnable = VK_TRUE; si.compareOp = compare_op(d->cmp_func); + // A depth-compare sampler set to nearest returns 0 or 1 per tap, and the game's shaders smooth shadow edges by + // a few taps spaced for its own shadow map texels. With TOTK_SHADOW_SCALE those taps cover a fraction of the + // area and the edges turn hard and stepped; linear filtering makes every tap a 2x2 PCF instead. + if (shadow_scale() > 1) si.magFilter = si.minFilter = VK_FILTER_LINEAR; } VkSamplerCustomBorderColorCreateInfoEXT cb = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT}; VkSamplerReductionModeCreateInfo rm = {.sType = VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO}; diff --git a/totk.ini.example b/totk.ini.example index f8213a99..68e9f306 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -115,6 +115,13 @@ # from 0 (off) to 100. Changes while the game runs take effect at once. # upscaler = fsr # sharpness = 80 +# Anisotropic filtering of mipmapped textures: game (the level the game asks for, as on the Switch) or 2, 4, 8, 16. +# Keeps ground and walls seen at a steep angle sharp. Depth-compare (shadow) and nearest-filtered samplers keep the +# game's setting. Read at start. +# aniso = 16 +# Shadow map resolution: the game's sun cascades are 960x960 (and its static shadow maps 1440 and 720) whatever the game +# resolution; 2 to 4 draws them that many times larger on each side, for sharper shadows. 1 = the game's. Read at start. +# shadow_scale = 1 [language] # Language: a Windows locale such as de-DE, or a Switch code (en-US, ja, zh-Hant, ...). Default: the Windows locale.