fix(ShaderBake): 分格线与 UV 编号一直不显示

Matrix4x4 * Vector3 会走隐式的 Vector3→Vector4 转换,w 恒为 0,
TryGetFaceViewportBounds 里那句 clip.w <= 0.0001f 于是把每一格都判成
"不在画面里",网格线、每格编号、选中框从来没画出来过。改成显式给 w=1。

顺带补两处:开窗时先走一遍 RefreshFaceUi,网格行列数不再停在 UXML 默认值;
状态栏初始文案清空,第一次渲染就能正常写成"已渲染"。
This commit is contained in:
2026-11-07 10:06:31 +08:00
parent 90bdbb14df
commit c7ac38869b
3 changed files with 8 additions and 2 deletions
@@ -180,6 +180,9 @@ namespace XericUI.ShaderBake.Editor
RestorePrefs(); RestorePrefs();
SyncUiFromSettings(); SyncUiFromSettings();
// 面片网格的行列数只在 RefreshFaceUi 里回写,开窗时得先走一遍,
// 否则那行字会停在 UXML 的默认值上,和实际渲染的格子对不上
RefreshFaceUi();
AdoptSelectionIfEmpty(); AdoptSelectionIfEmpty();
AssignSource(m_Source.sourceShader, m_Source.sourceMaterial, true); AssignSource(m_Source.sourceShader, m_Source.sourceMaterial, true);
DoRender(); DoRender();
+1 -1
View File
@@ -231,7 +231,7 @@
<!-- ── 底部状态栏 ── --> <!-- ── 底部状态栏 ── -->
<x:Toolbar name="status-bar" class="status-bar"> <x:Toolbar name="status-bar" class="status-bar">
<ui:Label name="status-message" class="status-message" text="未渲染" /> <ui:Label name="status-message" class="status-message" text="" />
<x:ToolbarSpacer class="toolbar-gap" /> <x:ToolbarSpacer class="toolbar-gap" />
<ui:Label name="status-source" class="status-readout" text="-" /> <ui:Label name="status-source" class="status-readout" text="-" />
<ui:Label name="status-size" class="status-readout" text="-" /> <ui:Label name="status-size" class="status-readout" text="-" />
+4 -1
View File
@@ -299,7 +299,10 @@ namespace XericUI.ShaderBake
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
Vector3 corner = new Vector3((i & 1) == 0 ? x0 : x1, (i & 2) == 0 ? y0 : y1, 0f); Vector3 corner = new Vector3((i & 1) == 0 ? x0 : x1, (i & 2) == 0 ? y0 : y1, 0f);
Vector4 clip = viewProjection * local.MultiplyPoint3x4(corner); Vector3 world = local.MultiplyPoint3x4(corner);
// 必须显式给 w=1:Matrix4x4 * Vector3 会走隐式 Vector3→Vector4(w=0),
// 于是 clip.w 恒为 0,下面的可见性判断会把每一格都判成"不在画面里"
Vector4 clip = viewProjection * new Vector4(world.x, world.y, world.z, 1f);
if (clip.w <= 0.0001f) if (clip.w <= 0.0001f)
return false; return false;
float u = (clip.x / clip.w + 1f) * 0.5f; float u = (clip.x / clip.w + 1f) * 0.5f;