Fix disappearing 3D faces at extreme zoom via projected raster sizing - #1516
Draft
skyrimHuang wants to merge 6 commits into
Draft
Fix disappearing 3D faces at extreme zoom via projected raster sizing#1516skyrimHuang wants to merge 6 commits into
skyrimHuang wants to merge 6 commits into
Conversation
skyrimHuang
requested review from
Hparty,
domchen,
richardshan0614 and
shlzxjp
as code owners
July 29, 2026 11:00
Hparty
reviewed
Jul 29, 2026
Hparty
left a comment
Collaborator
There was a problem hiding this comment.
这个方向治的是"纹理超限"的标,建议再往下挖一层根因,光栅尺寸本身不合理才是本:
-
缺少可视区域裁剪。
rasterLayer目前按localBounds × contentScale全量光栅化,而叶层实际可见的只是它投影进 compositor 目标的那一小部分。实测 zoom≈783 时,一个 1556×1556 的叶层,可见区域只有 23.6×16.7 个 local 单位——也就是说绝大部分光栅内容从来不上屏。可以看一下 #1432 之前的录制路径是怎么做这个裁剪的(提示:Matrix3DUtils::InverseMapRect),那套语义是验证过的。 -
光栅密度没有对齐叶层自身的变换。现在密度只乘了
contentScale(画布 zoom),没考虑叶层 3D 变换(含透视)对"local 单位 → 屏幕像素"的缩放:透视缩小的叶层会按 zoom 全密度光栅化,产生比视口还大的纹理(实测 18472×13099);反过来透视放大的叶层会欠采样变糊。可以想想怎么从叶层的实际投影推导出正确的光栅密度。
这两个根因解决后,光栅尺寸约等于叶层在 compositor 上的投影(≤ 视口),结构上碰不到 GPU 纹理上限,4096 钳制自然就不需要了。另外留一个延伸问题给你分析:compositor 目标本身(Context3DCompositor 按 renderRect 分配)在极端 zoom 下同样可以超限(实测 8313×6294),这层要怎么处理也一起想想。
有不确定的地方欢迎随时找我讨论。
skyrimHuang
marked this pull request as draft
July 29, 2026 12:36
…e leaf transform to avoid oversized textures. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… computation to align with tgfx conventions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ity derivation keep leaf textures within viewport scale. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…sity stays finite near the camera plane. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
skyrimHuang
force-pushed
the
bugfix/skyrimHuang_3D
branch
from
July 31, 2026 11:44
6452c89 to
ae4def3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
在极致 zoom 或强透视变换下,3D 场景中的叶层会出现"小方块消失"——某些
face 在渲染时缺失,露出背景或底色。原 PR 用
clamp(raster ≤ 4096)试图规避这一现象,但只是治标:被 clamp 的纹理 UV 会错位,且 clamp 触发时说明
raster 尺寸已经严重失控。
根本原因
Render3DContext::rasterLayer用localBounds × contentScale计算 raster尺寸,存在两个根源问题:
一小部分,却按完整
localBounds分配纹理,导致 zoom 越大浪费越大。contentScale,忽略了叶层 3D 变换(尤其透视)对"local 单位 → 屏幕像素"的实际缩放:透视缩小的叶层
被过采样产生远超视口的纹理(实测 200000×100000+),最终
Surface::Make失败返回
null,fragment 无 image → 消失。方案
将 raster 尺寸从"local × contentScale"改为"投影到 viewport 后的实际覆盖范围":
Matrix3DUtils::ComputeVisibleFootprints):把localBounds4 个角通过 3×3 homography 正向投影到 compositor 齐次空间(X, Y, W),在未除 W的状态下用 Sutherland-Hodgman 对 5 个平面依次裁剪(近相机平面
W > 0+ viewport 4 边)。剩余的多边形顶点分别映射回local 空间和 compositor 空间,得到成对的
localFootprint/destFootprint。destFootprint决定 raster 尺寸——它天然被 viewport 限制,不再失控。destFootprint.size / localFootprint.size——两个都是 clip 后的AABB,比值稳定,即使投影贴近近相机平面也不会奇异。
对于走 3D compositor 路径以外的场景(例如 non-preserve3D 或 fallback 到 2D 的
BackgroundBlur 变体),输出保持完全一致;受影响的仅为 6 个真正调用 3D
compositor 的 sub-baseline(见"截图基准"一节)。
变更范围
src/core/Matrix3DUtils.{h,cpp}:新增ComputeVisibleFootprintssrc/layers/compositing3d/Render3DContext.{h,cpp}:重写 raster 尺寸与密度的派生逻辑,抽出
ComputeRasterInfo私有 static 方法src/layers/compositing3d/Context3DCompositor.*侧改动,UV 映射的texSize / localBounds语义保持一致截图基准
6 个 sub-baseline 输出改变(3 个 mac 后端一致),需要
/accept-baseline:BackgroundBlurTest/BackgroundBlur3DLayer_Nested3DBackgroundBlurTest/BackgroundBlur3DLayer_NestedOffscreenBackgroundBlurTest/BackgroundBlur3DLayer_Preserve3DHello2DTest/Layer3DTreeLayerTest/Contour3DWithDropShadowLayerTest/Matrix_3D_2D_3D_Preserve3D