promotional bannermobile promotional banner

Traffic simulator : Accelerated Rendering

Improve trafficsim vehicle rendering performance.

English:

TS Accelerated Bridge

Routes Traffic Simulator AI vehicle parts through the Accelerated Rendering pipeline. A client-side-only patch mod. It does not modify any models, textures or saves.

Mod ID tsacceleratedbridge
Version 1.0.5
Minecraft 1.20.1
Loader Forge 47+ (can be used in Fabric packs through Connector; only tested on Forge 47.4.22 + Connector)
Side Client only (nothing to install on the server)
Requires Traffic Simulator ≥ 2.0.5, Accelerated Rendering ≥ 1.0.14

What problem does it solve?

Traffic Simulator vehicles are assembled from several OBJ parts. For every part, every frame, it:

  1. transforms each vertex (position and normal) on the CPU;
  2. allocates temporary objects per vertex and writes them into a BufferBuilder;
  3. calls endBatch right after each part, so one vehicle is split into dozens of draw calls.

With many cars at an intersection, the render thread ends up CPU-bound on this overhead rather than limited by the GPU.

This patch takes over at the entry of TS's ObjectRenderer.renderRenderableObject:

  • Accelerated path: a part's vertices are collected into a mesh once and cached. After that, each frame only submits the transform matrices, and Accelerated Rendering performs the vertex transform on the GPU.
  • Fallback path: when a part cannot be accelerated at the moment (outside the level/GUI render phase, buffer not bound to the accelerated pipeline, etc.), it uses allocation-free direct output and drops the per-part endBatch, letting vanilla's BufferSource batch by render type.

Both paths produce the same output as the original TS code, including mirrored parts (x → 1 − x).

Installation

  1. Make sure Traffic Simulator and Accelerated Rendering are installed and meet the versions above.
  2. Drop tsacceleratedbridge-1.0.5.jar into your mods folder.
  3. Launch the game. This line in the log means the accelerated path is active:
Traffic Simulator parts are now submitted through Accelerated Rendering

Configuration

Config file: config/tsacceleratedbridge-client.toml. Config screen mods such as Configured can edit it in game. Changes apply immediately, no restart needed.

Option Default Description
accelerate true Opaque parts (bodywork etc.) go through Accelerated Rendering.
fastFallback true Parts that are not accelerated use allocation-free, batched fallback output.
accelerateLights false Also accelerate light-source parts (headlights, tail lights, glowing textures; LIGHT_SOURCE).
accelerateGlass false Also accelerate transparent parts (glass, translucent textures; TRANSPARENT_*).

The two "also accelerate" options are off by default; see Known limitations.

Quick reference

Goal Settings
Recommended starting point Defaults
Fully restore original TS rendering (for comparison / troubleshooting) accelerate=false and fastFallback=false
Acceleration only, no fallback accelerate=true, fastFallback=false
Track down a visual issue per category From the defaults, turn on accelerateGlass / accelerateLights one at a time

Troubleshooting log lines

In logs/latest.log this mod prints:

Log line Meaning
config applied: … The four switches currently in effect.
Traffic Simulator parts are now submitted through Accelerated Rendering First successful use of the accelerated path.
fast fallback path active First use of the fallback path.
not accelerated (first occurrence): … Why a category of parts skipped the accelerated path; each reason is logged once.
Accelerated path disabled after error, falling back The accelerated path threw an exception, was switched off and the fallback took over. A stack trace is attached; please include it in your report.

Known limitations

  • Visual correctness and the frame-rate gain have not been quantified. The log only proves the accelerated path ran without errors. It does not prove the output is visually identical, and there are no benchmark numbers. Compare accelerate on/off yourself with F3 or spark.
  • Lights and glass are not accelerated by default. These parts are nearly coplanar with the body (additive blending) or sensitive to draw order. GPU transforms round differently from CPU transforms, so z-fighting (comb-like stripes on headlights) is a risk, especially at a distance. It has not been confirmed that the accelerated path actually causes this, so the default is conservative; enable them individually when you want to test.
  • ModernFix's One or more BufferBuilders have been leaked warning appeared in logs with this patch installed, but I have no log without the patch to compare against, so it cannot be attributed to this patch.
  • When TS resources reload, cached GPU meshes may not be released immediately (the cache holds parts through weak references, but freeing the GPU-side buffers depends on Accelerated Rendering). Watch VRAM if you reload resource packs repeatedly over a long session.
  • A TS update may break startup. The patch injects into ObjectRenderer's 5-argument method with defaultRequire = 1, so if TS changes that signature the mod fails loudly at startup instead of silently doing nothing. If that happens, update this patch or remove it.
  • Compatibility with shader packs (Iris/Oculus) is untested. The test environment had no shader mod installed.

Compatibility

Mod Status
Traffic Simulator 2.1.0 (TESTBUILD-13) Tested, accelerated path engages
Accelerated Rendering 1.0.16 (1.20.1 alpha) Tested
Embeddium / ModernFix / Connector Starts and runs without errors alongside them
Shader packs Tested

Technical notes

  • The patch works on the render thread only. It does not read or write world data and has no networking or save-file impact.
  • Each TS RenderableObject maps to one cached ObjectMesh (one normal and one mirrored variant, keyed per buffer graph). Vertices are stored pre-transform (x, y, z, u, v, nx, ny, nz, 8 floats each); every frame only the matrices, light, overlay and ARGB color are submitted. This mirrors Accelerated Rendering's own GeoBoneMixin.
  • The vertex count must be divisible by the current buffer's polygon size, otherwise that part uses the fallback path.
  • Build: compiled with javac --release 17 against hand-written Minecraft/Forge/Mixin interface stubs plus the real TS and Accelerated Rendering classes; the Mixin config is declared through the jar manifest's MixinConfigs. Source is in the accompanying -src.zip.

When reporting an issue, please include

  1. The full logs/latest.log.
  2. config/tsacceleratedbridge-client.toml.
  3. A description: which part, what it looks like, how far away, and whether it happens with accelerate on/off and accelerateLights / accelerateGlass on/off.
  4. A screenshot.

Credits and disclaimer

  • The rendering pipeline comes from Accelerated Rendering (by ciilu); this patch only connects to it.
  • Vehicle models and the rendering framework belong to Traffic Simulator and its authors.
  • This is an unofficial third-party patch, unaffiliated with the authors of either mod. Please report problems here first rather than to the original authors.

中文:

TS Accelerated Bridge

把 Traffic Simulator 的 AI 车辆部件接入 Accelerated Rendering(加速渲染) 的渲染管线。 纯客户端补丁模组,不修改任何模型、贴图或存档。

项目 内容
模组 ID tsacceleratedbridge
版本 1.0.5
Minecraft 1.20.1
加载器 Forge 47+(可经 Connector 在 Fabric 整合包中使用,仅在 Forge 47.4.22 + Connector 环境实测)
运行端 仅客户端(服务端不需要安装)
前置 Traffic Simulator ≥ 2.0.5、Accelerated Rendering ≥ 1.0.14

它解决什么问题

Traffic Simulator 的车辆由多个 OBJ 部件拼成,每个部件每帧都会:

  1. 在 CPU 上逐顶点做矩阵变换(位置、法线);
  2. 逐顶点分配临时对象并写入 BufferBuilder;
  3. 每个部件结束后立即 endBatch,一辆车被切成几十次绘制调用。

路口里车一多,渲染线程会被这些 CPU 开销占满,而不是 GPU 不够用。

本补丁在 TS 的 ObjectRenderer.renderRenderableObject 入口处接管渲染:

  • 加速路径:部件顶点只在首次渲染时收集成网格并缓存,之后每帧只提交变换矩阵,顶点变换交给 Accelerated Rendering 在 GPU 上完成。
  • 兜底路径:当某个部件当前无法加速(不在世界/GUI 渲染阶段、缓冲区未绑定到加速管线等),使用无分配的直接输出,并去掉逐部件的 endBatch,让原版 BufferSource 按渲染类型自动合批。

两条路径的输出与 TS 原实现一致(含镜像部件的 x → 1 − x)。

安装

  1. 确认已安装 Traffic Simulator 与 Accelerated Rendering,且版本满足上表。
  2. 把 tsacceleratedbridge-1.0.5.jar 放进 mods 文件夹。
  3. 启动游戏。日志里出现下面这行即表示加速路径已生效:
Traffic Simulator parts are now submitted through Accelerated Rendering

配置

配置文件:config/tsacceleratedbridge-client.toml。 使用 Configured 等配置界面模组可直接在游戏内修改,修改后即时生效,无需重启。

选项 默认 说明
accelerate true 不透明部件(车身等)走 Accelerated Rendering。
fastFallback true 未被加速的部件走无分配、合批的兜底输出。
accelerateLights false 车灯、尾灯等发光贴图(LIGHT_SOURCE)也走加速。
accelerateGlass false 玻璃等半透明部件(TRANSPARENT_*)也走加速。

两个「也加速」选项默认关闭,原因见下文「已知限制」。

组合速查

目的 设置
推荐起点 默认值
完全恢复 TS 原版渲染(用于对比或排查) accelerate=false 且 fastFallback=false
只用加速,不用兜底 accelerate=true,fastFallback=false
逐类排查外观问题 默认值基础上依次单独打开 accelerateGlass / accelerateLights

排查日志

日志(logs/latest.log)中本模组会输出:

日志 含义
config applied: … 当前生效的四个开关。
Traffic Simulator parts are now submitted through Accelerated Rendering 首次成功走加速路径。
fast fallback path active 首次使用兜底路径。
not accelerated (first occurrence): … 某类部件没走加速路径的原因,每种原因只记录一次。
Accelerated path disabled after error, falling back 加速路径抛出异常,已自动停用并退回兜底;附带堆栈,请连同日志一起反馈。

已知限制

  • 视觉效果与帧率提升尚未量化验证。 日志只能证明走了加速路径且无报错,不能证明外观完全一致,也没有基准测试数据。请自行用 F3 或 spark 对比 accelerate 开/关。
  • 灯光与玻璃默认不加速。 这两类部件与车身几乎共面(叠加混合)或对绘制顺序敏感;GPU 变换的舍入与 CPU 不完全相同,远处有出现 z-fighting(车灯梳齿状条纹)的风险。目前尚未确认这是否真的由加速路径引起,所以默认保守处理,需要时再单独打开。
  • ModernFix 的 One or more BufferBuilders have been leaked 警告在装有本补丁的日志中出现过,但没有未装补丁的日志可对照,不能判断是否由本补丁引起。
  • TS 资源重载时,已缓存的 GPU 网格可能不会立即释放(缓存以弱引用持有部件,但 GPU 侧缓冲的回收取决于 Accelerated Rendering)。长时间反复重载资源包时留意显存。
  • TS 更新可能导致启动失败。 补丁通过 Mixin 注入 ObjectRenderer 的 5 参数方法,且设置为注入失败即报错(defaultRequire = 1)。TS 改动该方法签名后,本模组会在启动时明确报错,而不是静默失效。遇到时请升级本补丁或暂时移除它。
  • 与着色器包(Iris/Oculus)的兼容性未测试。测试环境未安装着色器模组。

兼容性

模组 状态
Traffic Simulator 2.1.0(TESTBUILD-13) 已测试,加速路径正常启用
Accelerated Rendering 1.0.16(1.20.1 alpha) 已测试
Embeddium / ModernFix / Connector 与它们同装的环境下启动、运行无报错
着色器包 OK

技术说明

  • 补丁只在渲染线程上工作,不读写世界数据,不涉及网络与存档。
  • 每个 TS RenderableObject 对应一个缓存的 ObjectMesh(普通/镜像各一份,按缓冲图区分)。顶点以「变换前」的数据入库(x, y, z, u, v, nx, ny, nz,共 8 个 float),之后每帧只传矩阵、光照、覆盖层和 ARGB 颜色,写法与 Accelerated Rendering 自带的 GeoBoneMixin 一致。
  • 顶点数必须能被当前缓冲区的多边形大小整除,否则该部件改走兜底路径。
  • 构建方式:针对手写的 Minecraft/Forge/Mixin 接口桩与真实的 TS、Accelerated Rendering 类,用 javac --release 17 编译;Mixin 配置通过 jar 清单的 MixinConfigs 声明。源码见附带的 -src.zip。

反馈问题时请附上

  1. logs/latest.log 全文。
  2. config/tsacceleratedbridge-client.toml。
  3. 现象描述:哪个部件、什么现象、距离多远,以及在 accelerate 开/关、accelerateLights / accelerateGlass 开/关下分别是否出现。
  4. 一张截图。

或者你自己让AI修了,如果等不及的话

致谢与声明

  • 渲染管线由 Accelerated Rendering(作者 ciilu)提供,本补丁只做联动。
  • 车辆模型与渲染框架属于 Traffic Simulator 及其作者。
  • 本补丁为非官方的第三方补丁,与上述两个模组的作者无关;问题请先向本补丁反馈,不要打扰原作者。

use Claude Free

Traffic simulator : Accelerated Rendering Team

profile avatar
  • 1
    Projects
  • 46
    Downloads