Просмотр исходного кода

【文档】更正镜内 mip 偏差的技术描述

经 Unity 官方文档复核,原描述里的「越省带宽」不准确。

- streamingMipmapBias 不参与 GPU 采样 LOD,只决定流送系统保留哪些 mip 常驻;
  省的是上传与磁盘 I/O(以及可能的常驻显存)。
- 补充它仅在开启贴图流送时生效,且受 streamingMipmapsMaxLevelReduction
  (游戏设为 4 − 贴图品质)截断,贴图品质为高时最多丢 2 级。
- 补充常驻级别按所有启用相机中最精细需求聚合,主相机开超分时的 -1.5 可能使镜内正偏差失效。
- 同步更正游戏内配置描述与 docs/configuration.md、docs/principle.md、docs/compatibility.md。
PJ568 1 месяц назад
Родитель
Сommit
90029d9e93
4 измененных файлов с 29 добавлено и 7 удалено
  1. 2 2
      docs/compatibility.md
  2. 22 4
      docs/configuration.md
  3. 4 0
      docs/principle.md
  4. 1 1
      src/PerformanceScope.Plugin/PluginConfig.cs

+ 2 - 2
docs/compatibility.md

@@ -12,7 +12,7 @@
 
 - **无法独立设置镜内超分档**:全游戏只有一套挂在主相机上的 `SSAA`/`SSAAImpl`,镜内画面是其一部分;独立的镜内 FSR/DLSS 需要另挂一套组件,本插件不做。
 - **瞄准中改分辨率可能有一帧闪烁**:因为会销毁并重建 RenderTexture;可将“瞄准中立即应用”关闭以规避。
-- **镜内低分辨率下纹理锯齿会更明显**:镜内相机的 mipmap bias 只在 `Init()` 时设置一次,默认随画质档变化;可将「镜内贴图 mip 模式」设为「自定义」并用「Mip 偏差」覆盖它来调节。
+- **镜内低分辨率下纹理锯齿会更明显**:镜内相机的 mipmap bias 只在 `Init()` 时设置一次,默认随画质档变化;可将「镜内贴图 mip 模式」设为「自定义」并用「Mip 偏差」覆盖它来调节。注意它改变的是**常驻 mip 与上传/磁盘 I/O**,且贴图品质为高时最多只能丢 2 级(偏差大于 2 会被截断),详见配置参考。
 - **与其它改 `SetResolution` 的模组可能冲突**:若第三方 prefix 改写同一入参,插件检测到目标未生效后会暂停重试直至你更改目标值,避免反复重建 RenderTexture。
 - **版本敏感**:依赖具体类型与方法,EFT 更新后可能失效。
 - **CI 限制**:客户端插件必须引用专有程序集,公共 runner 无法构建,故仓库只保留 `test.yml`(跑纯逻辑单测);发行包用 `scripts/release.sh` 本地一键发布。
@@ -37,7 +37,7 @@
 
 - **No independent in-scope upscaler setting**: the game has a single `SSAA`/`SSAAImpl` on the main camera and the scoped image is part of it; a truly independent in-scope FSR/DLSS would require attaching a second component, which this plugin does not do.
 - **Changing resolution while scoped may flash for one frame** because the RenderTexture is destroyed and recreated; turn off "瞄准中立即应用" to avoid it.
-- **Texture aliasing becomes more visible at low in-scope resolutions**: the scope camera's mipmap bias is only set once in `Init()` and defaults to a quality-dependent value; set "镜内贴图 mip 模式 | Scope Mip Mode" to "自定义" (custom) and override it with "Mip 偏差 | Mip Bias" to adjust.
+- **Texture aliasing becomes more visible at low in-scope resolutions**: the scope camera's mipmap bias is only set once in `Init()` and defaults to a quality-dependent value; set "镜内贴图 mip 模式 | Scope Mip Mode" to "自定义" (custom) and override it with "Mip 偏差 | Mip Bias" to adjust. Note that it changes **mip residency and upload/disk I/O**, and at high texture quality at most 2 levels can be dropped (anything above 2 is truncated); see the configuration reference for details.
 - **Possible conflict with other mods that patch `SetResolution`**: if a third-party prefix rewrites the same argument, the plugin detects the target not taking effect and pauses retries until you change the target, avoiding repeated RenderTexture rebuilds.
 - **Version sensitive**: it depends on specific types and methods and may break after an EFT update.
 - **CI limitation**: a client plugin must reference proprietary assemblies, which public runners cannot build, so the repository keeps only `test.yml` (pure-logic unit tests); release packages are produced locally with `scripts/release.sh`.

+ 22 - 4
docs/configuration.md

@@ -16,7 +16,7 @@
 | 2. 镜内分辨率 · Scope Resolution | 绝对像素 \| Absolute Pixels | `1024` | 镜内方形 RenderTexture 的边长。 |
 | 2. 镜内分辨率 · Scope Resolution | 瞄准中立即应用 \| Apply While Scoped | `true` | 关闭时,瞄准期间的改动推迟到退出镜内后应用。 |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 镜内贴图 mip 模式 \| Scope Mip Mode | `游戏默认` | 游戏默认 / 自定义。自定义时覆盖镜内相机的贴图 mip 偏差。 |
-| 3. 镜内贴图与细节 · Scope Textures & Details | Mip 偏差 \| Mip Bias | `3` | `-2`…`8`;绝对值覆盖镜内 `streamingMipmapBias`,越大纹理越糊、越省带宽。 |
+| 3. 镜内贴图与细节 · Scope Textures & Details | Mip 偏差 \| Mip Bias | `3` | `-2`…`8`;绝对值覆盖镜内 `streamingMipmapBias`,越大常驻 mip 越粗。 |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内泛光 \| Disable Scope Bloom | `false` | 勾选则关闭镜内相机的泛光(`bloomOptimized`)。 |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内终极泛光 \| Disable Scope Ultimate Bloom | `false` | 勾选则关闭镜内相机的终极泛光(`ultimateBloom`)。 |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内色散 \| Disable Scope Chromatic Aberration | `false` | 勾选则关闭镜内相机的色散(`chromaticAberration`)。 |
@@ -38,7 +38,16 @@
 
 覆盖对象是镜内相机自己的 `UnityEngine.StreamingController.streamingMipmapBias`。游戏在 `EFT.CameraControl.OpticCameraManager.Init()` 中把它设为 `GraphicsSettingsGroup.TextureQualityToMipBias(TextureQuality)`,即 `Clamp(2 − 贴图品质, 0, 2)`(`TextureQuality` 取 0–2,因此游戏默认值落在 0–2 之间);全仓库只有这一处写镜内相机的该值,且不会每帧刷新。
 
-「镜内贴图 mip 模式」设为「自定义」时,插件按「Mip 偏差」的**绝对值**覆盖它,值越大纹理越糊、越省带宽。覆盖只在镜内相机创建时执行一次即可持久,无需每帧。
+「镜内贴图 mip 模式」设为「自定义」时,插件按「Mip 偏差」的**绝对值**覆盖它。
+
+这个值的语义需要说清楚:
+
+- 它**不参与 GPU 采样时的 LOD 计算**,只决定流送系统让哪些 mip **常驻**。正值让常驻集合更粗,采样因此被夹到更粗的顶层——这才是「看起来更糊」的成因;它省的是**上传与磁盘 I/O(以及可能的常驻显存)**,不是 GPU 采样带宽。
+- **只在开启贴图流送时生效**;关掉流送时游戏改用全局贴图上限,该偏差无任何作用。
+- **受 `streamingMipmapsMaxLevelReduction` 截断**:游戏把它设为 `4 − 贴图品质`,贴图品质为「高」时只有 2 级可丢,因此偏差大于 `2` 的部分通常不会带来额外效果;该项还**优先于内存预算**。
+- **常驻级别按所有启用相机中最精细的需求聚合**(游戏设了 `streamingMipmapsAddAllCameras = true`)。启用 DLSS/FSR 时主相机是 `−1.5`(更细),可能把纹理常驻「钉」在高分辨率上,此时镜内即使设正值也可能既省不到显存、也看不出变化。
+
+覆盖只在镜内相机创建时执行一次即可持久,无需每帧。
 
 > 注意:`streamingMipmapBias` 是绝对值覆盖,而非在游戏默认值上叠加偏移;想保持游戏行为就选「游戏默认」。
 
@@ -85,7 +94,7 @@ The plugin ships no custom UI or hotkeys. Install [BepInEx ConfigurationManager]
 | 2. 镜内分辨率 · Scope Resolution | 绝对像素 \| Absolute Pixels | `1024` | Edge length of the square scope RenderTexture. |
 | 2. 镜内分辨率 · Scope Resolution | 瞄准中立即应用 \| Apply While Scoped | `true` | When off, changes made while scoped are deferred until you unscope. |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 镜内贴图 mip 模式 \| Scope Mip Mode | `游戏默认` | Game default / custom. Custom overrides the scope camera's texture mip bias. |
-| 3. 镜内贴图与细节 · Scope Textures & Details | Mip 偏差 \| Mip Bias | `3` | `-2`…`8`; an absolute override of the scope `streamingMipmapBias`; higher = blurrier textures and less bandwidth. |
+| 3. 镜内贴图与细节 · Scope Textures & Details | Mip 偏差 \| Mip Bias | `3` | `-2`…`8`; an absolute override of the scope `streamingMipmapBias`; larger keeps coarser mips resident. |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内泛光 \| Disable Scope Bloom | `false` | Check to disable the scope camera's bloom (`bloomOptimized`). |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内终极泛光 \| Disable Scope Ultimate Bloom | `false` | Check to disable the scope camera's ultimate bloom (`ultimateBloom`). |
 | 3. 镜内贴图与细节 · Scope Textures & Details | 关闭镜内色散 \| Disable Scope Chromatic Aberration | `false` | Check to disable the scope camera's chromatic aberration (`chromaticAberration`). |
@@ -107,7 +116,16 @@ On by default. When on, changing the target value while scoped rebuilds the scop
 
 What is overridden is the scope camera's own `UnityEngine.StreamingController.streamingMipmapBias`. In `EFT.CameraControl.OpticCameraManager.Init()` the game sets it to `GraphicsSettingsGroup.TextureQualityToMipBias(TextureQuality)`, i.e. `Clamp(2 − texture quality, 0, 2)` (`TextureQuality` is 0–2, so the game default lands in the 0–2 range); this is the only place in the whole codebase that writes that value on the scope camera, and it is not refreshed every frame.
 
-When "镜内贴图 mip 模式 | Scope Mip Mode" is set to "自定义" (custom), the plugin overrides it with the **absolute value** of "Mip 偏差 | Mip Bias"; a higher value means blurrier textures and less bandwidth. The override is applied once when the scope camera is created and persists, so no per-frame work is needed.
+When "镜内贴图 mip 模式 | Scope Mip Mode" is set to "自定义" (custom), the plugin overrides it with the **absolute value** of "Mip 偏差 | Mip Bias".
+
+The semantics of that value need to be stated clearly:
+
+- It does **not** take part in the GPU sampling LOD calculation; it only decides which mips the streaming system keeps **resident**. A positive value makes the resident set coarser, so sampling is clamped to a coarser top level — that is what "looks blurrier" actually means. What it saves is **upload and disk I/O (and possibly resident VRAM)**, not GPU sampling bandwidth.
+- It **only applies while texture streaming is enabled**; with streaming off the game uses a global texture limit instead and this bias does nothing.
+- It is **truncated by `streamingMipmapsMaxLevelReduction`**: the game sets it to `4 − texture quality`, so at high texture quality only 2 levels can be dropped, and anything above `2` usually adds nothing; that setting also **takes priority over the memory budget**.
+- **Residency aggregates the finest demand across all enabled cameras** (the game sets `streamingMipmapsAddAllCameras = true`). With DLSS/FSR enabled the main camera runs at `−1.5` (finer), which may pin the texture residency to a high resolution, in which case a positive in-scope value may save neither memory nor visible quality.
+
+The override is applied once when the scope camera is created and persists, so no per-frame work is needed.
 
 > Note: `streamingMipmapBias` is an absolute override, not an offset added on top of the game default; pick "游戏默认" (game default) to keep the game behavior.
 

+ 4 - 0
docs/principle.md

@@ -80,6 +80,8 @@
 
 `EFT.CameraControl.OpticCameraManager.Init()` 会把镜内相机自己的 `UnityEngine.StreamingController.streamingMipmapBias` 设为 `GraphicsSettingsGroup.TextureQualityToMipBias(TextureQuality)`,映射为 `Clamp(2 − 画质, 0, 2)`(`TextureQuality` 取 0–2)。全仓库只有这一处写镜内相机的该值。因此插件在镜内相机创建时覆盖一次即可持久,**不需要每帧**。
 
+该偏差只影响流送系统保留哪些 mip **常驻**(进而影响上传/磁盘 I/O 与可能的常驻显存),**不参与 GPU 采样 LOD 计算**;观感变糊是「常驻集合变粗后采样被迫夹取」的结果。它仅在开启贴图流送时生效,并受 `QualitySettings.streamingMipmapsMaxLevelReduction`(游戏设为 `4 − 贴图品质`)截断——贴图品质为高时最多只能丢 2 级。常驻级别还要按所有启用相机中最精细的需求聚合(游戏设了 `streamingMipmapsAddAllCameras = true`),因此主相机在开超分时的 `−1.5` 可能使镜内正偏差失效。
+
 ### 镜内细节
 
 `EFT.CameraControl.OpticComponentUpdater.CopyComponentFromOptic(OpticSight)` 会按每瞄具的 `ScopeEffectsData` 设置镜内相机上的组件开关(`chromaticAberration`、`bloomOptimized`、`ultimateBloom`、`fisheye`、`cc_FastVignette`、`tonemapping` 等)。**这些不会被每帧覆盖**,所以插件用该方法的 postfix 覆盖一次即可持久。插件对其中四个提供**逐项开关**(泛光、终极泛光、色散、鱼眼),并按瞄具实例缓存原始值,使取消勾选能正确还原。
@@ -200,6 +202,8 @@ There are two write points for the in-scope texture mip and the in-scope details
 
 `EFT.CameraControl.OpticCameraManager.Init()` sets the scope camera's own `UnityEngine.StreamingController.streamingMipmapBias` to `GraphicsSettingsGroup.TextureQualityToMipBias(TextureQuality)`, which maps to `Clamp(2 − texture quality, 0, 2)` (`TextureQuality` is 0–2). This is the only place in the whole codebase that writes that value on the scope camera. The plugin therefore overrides it once when the scope camera is created, and it persists — **no per-frame work is needed**.
 
+The bias only affects which mips the streaming system keeps **resident** (hence upload/disk I/O and possibly resident VRAM); it does **not** take part in the GPU sampling LOD calculation. The blurrier look comes from the coarser resident set clamping sampling. It only applies while texture streaming is on, and it is truncated by `QualitySettings.streamingMipmapsMaxLevelReduction` (the game sets it to `4 − texture quality`), so at high texture quality at most 2 levels can be dropped. Residency also aggregates the finest demand across all enabled cameras (the game sets `streamingMipmapsAddAllCameras = true`), so the main camera's `−1.5` under an upscaler can make a positive in-scope bias ineffective.
+
 ### In-scope details
 
 `EFT.CameraControl.OpticComponentUpdater.CopyComponentFromOptic(OpticSight)` sets the component toggles on the scope camera according to each optic's `ScopeEffectsData` (`chromaticAberration`, `bloomOptimized`, `ultimateBloom`, `fisheye`, `cc_FastVignette`, `tonemapping`, etc.). **These are not overwritten every frame**, so the plugin overrides them once in that method's postfix and the result persists. The plugin exposes **individual toggles** for four of them (bloom, ultimate bloom, chromatic aberration, fisheye) and caches the original values per optic instance so that unchecking a toggle restores correctly.

+ 1 - 1
src/PerformanceScope.Plugin/PluginConfig.cs

@@ -139,7 +139,7 @@ namespace PerformanceScope
                 "Mip 偏差 | Mip Bias",
                 ScopeMipMath.DefaultCustomBias,
                 new ConfigDescription(
-                    "绝对值覆盖镜内相机的 streamingMipmapBias:越大纹理越糊、越省带宽;游戏默认值取决于贴图品质,范围为 0 到 2。\nAbsolute override for the optic camera's streamingMipmapBias: higher is blurrier and cheaper. The game default depends on texture quality and ranges from 0 to 2.",
+                    "绝对值覆盖镜内相机的 streamingMipmapBias:数值越大常驻 mip 越粗、越糊。它影响常驻 mip 与上传/磁盘 I/O,不影响 GPU 采样 LOD,且仅在开启贴图流送时生效。\nAbsolute override for the optic camera's streamingMipmapBias: a larger value keeps coarser mips resident and looks blurrier. It affects mip residency and upload/disk I/O, not the GPU sampling LOD, and only applies while texture streaming is on.",
                     new AcceptableValueRange<float>(ScopeMipMath.MinBias, ScopeMipMath.MaxBias),
                     new ConfigurationManagerAttributes { Order = 2 }));