合并 dev2 的 23 条 ShaderBake 提交(2026-11-07)到 dev_chart
文件集与 XChart 那侧不交叉(只共用 CHANGELOG.md),冲突两侧都是各自新增的行、 没有任何一方删过对方的内容,所以两边条目都保留:P29b/P25-P23/P26 三条在前, Bake Shader 窗口那一块接在后面。未推送。
This commit is contained in:
@@ -27,13 +27,30 @@ namespace XericUI.ShaderBake.Editor
|
||||
private const string kUssPath = "Packages/com.lrss3.xericuiactionvessel/Editor/ShaderBake/BakeShaderWindow.uss";
|
||||
private const string kRowUxmlPath = "Packages/com.lrss3.xericuiactionvessel/Editor/ShaderBake/BakeShaderPropertyRow.uxml";
|
||||
private const string kGlobalRowUxmlPath = "Packages/com.lrss3.xericuiactionvessel/Editor/ShaderBake/BakeShaderGlobalRow.uxml";
|
||||
private const string kDebugViewShaderPath = "Packages/com.lrss3.xericuiactionvessel/Editor/ShaderBake/ShaderBakeDebugView.shader";
|
||||
|
||||
private const string kPrefSettings = "XericUI.ShaderBake.Settings";
|
||||
private const string kPrefAutoRefresh = "XericUI.ShaderBake.AutoRefresh";
|
||||
private const string kPrefChecker = "XericUI.ShaderBake.Checker";
|
||||
private const string kPrefDebugView = "XericUI.ShaderBake.DebugView";
|
||||
private const string kPrefDetailWidth = "XericUI.ShaderBake.DetailWidth";
|
||||
private const string kPrefSource = "XericUI.ShaderBake.SourceAsset";
|
||||
|
||||
/// <summary> 测试视图用的那张 shader(Editor 目录下,见 ShaderBakeDebugView.shader) </summary>
|
||||
private const string kDebugViewShader = "Hidden/XericUI/ShaderBake/Debug View";
|
||||
|
||||
/// <summary>
|
||||
/// 实时预览的节拍上限:有焦点时按 60fps 排,失焦降到 20fps。
|
||||
///
|
||||
/// <para>这只是"最早什么时候重画",真正的帧率还受渲染耗时和编辑器自己的刷新率限制——
|
||||
/// 所以别处只管少做无用功,别指望靠调这个数字把卡顿调掉。</para>
|
||||
/// </summary>
|
||||
private const double kLiveIntervalFocused = 1.0 / 60.0;
|
||||
private const double kLiveIntervalBlurred = 1.0 / 20.0;
|
||||
|
||||
/// <summary> 覆盖率读数降频:它要 ReadPixels,会同步一次显卡,实时预览里做多了就是顿感来源 </summary>
|
||||
private const double kCoverageInterval = 2.0;
|
||||
|
||||
private const float kDefaultDetailWidth = 340f;
|
||||
private static readonly string[] kAntiAliasingChoices = { "1", "2", "4", "8" };
|
||||
private const string kCustomSize = "自定义";
|
||||
@@ -56,8 +73,10 @@ namespace XericUI.ShaderBake.Editor
|
||||
private ObjectField m_MaterialField;
|
||||
private Label m_SourceNote;
|
||||
private Button m_ExportButton;
|
||||
private ToolbarButton m_RenderButton;
|
||||
private ToolbarToggle m_AutoRefreshToggle;
|
||||
private ToolbarToggle m_CheckerToggle;
|
||||
private ToolbarButton m_DebugButton;
|
||||
private Label m_StatusMessage;
|
||||
private Label m_StatusSize;
|
||||
private Label m_StatusTime;
|
||||
@@ -68,14 +87,46 @@ namespace XericUI.ShaderBake.Editor
|
||||
private readonly List<Action> m_Syncers = new List<Action>();
|
||||
|
||||
private bool m_RenderPending;
|
||||
/// <summary> 实时预览关着时攒下的改动:还没重画,「重新渲染」按钮上会写着这件事 </summary>
|
||||
private bool m_PendingRefresh;
|
||||
private double m_LastRenderMs = -1;
|
||||
private double m_NextLiveRender;
|
||||
/// <summary> 上一次心跳的时刻;用来量两次心跳之间实际隔了多久 </summary>
|
||||
private double m_LastHeartbeatTime;
|
||||
/// <summary> 实测心跳间隔(毫秒),-1 = 还没量到 </summary>
|
||||
private float m_LiveFrameMs = -1f;
|
||||
private double m_NextStatusUpdate;
|
||||
private double m_NextCoverageCheck;
|
||||
/// <summary> 上一次结果的不透明像素占比,-1 = 没测出来 </summary>
|
||||
private float m_LastCoverage = -1f;
|
||||
/// <summary> 管线自检的探针(活着才能让自检那张图继续显示) </summary>
|
||||
private ShaderBakeRenderer m_SelfTestProbe;
|
||||
private RenderTexture m_SelfTestTarget;
|
||||
private Material m_SelfTestMaterial;
|
||||
/// <summary> 上一次写进日志的覆盖率百分比:只在变化时输出,避免拖滑块刷屏 </summary>
|
||||
private int m_LoggedCoverage = -1;
|
||||
/// <summary> 探针(自检 / 测试视图)活着才能让那张图继续显示;切回真实结果时才收掉 </summary>
|
||||
private readonly ShaderBakeOverrideRenderer m_Override = new ShaderBakeOverrideRenderer();
|
||||
private DebugView m_DebugView = DebugView.None;
|
||||
/// <summary> 测试视图那张材质:_Mode 决定画哪种图,建一次反复用 </summary>
|
||||
private Material m_DebugMaterial;
|
||||
private int m_SelectedFace;
|
||||
/// <summary> 给预览面板的分格数据:每帧重填,避免按格新建列表 </summary>
|
||||
private readonly List<ShaderBakePreviewPane.FaceCellRect> m_GridCells = new List<ShaderBakePreviewPane.FaceCellRect>();
|
||||
|
||||
/// <summary> 预览换成"量几何与 UV"的测试图。都不吃贴图、不吃光照,画不出来的原因只剩一个。
|
||||
/// Uv/Gradient/Checker 的取值与 shader 的 _Mode 一一对应 </summary>
|
||||
private enum DebugView
|
||||
{
|
||||
None = -1,
|
||||
/// <summary> 红=U、绿=V,一格四角即 00/10/01/11 </summary>
|
||||
Uv = 0,
|
||||
/// <summary> 灰度尺:主体沿 U、顶条沿 V,每 0.1 一档,量这一格跨了多少像素 </summary>
|
||||
Gradient = 1,
|
||||
/// <summary> 半 UV 棋盘 + 每格色相 + 左下角红/右上角蓝,看拉伸、斜切与镜像 </summary>
|
||||
Checker = 2,
|
||||
/// <summary>
|
||||
/// 内置 Unlit/Color 的一张绿面片:不吃贴图、不吃光照、不吃 UV,只回答"这套矩阵画得出东西吗"。
|
||||
/// 取值故意离开 shader 的 _Mode 范围——它用的是另一张 shader
|
||||
/// </summary>
|
||||
SolidColor = 20
|
||||
}
|
||||
|
||||
[MenuItem(XericRegistrationPaths.ToolBar + "/Bake Shader As Image", false, 20)]
|
||||
private static void OpenFromMenu()
|
||||
@@ -123,19 +174,54 @@ namespace XericUI.ShaderBake.Editor
|
||||
BuildGlobalTable();
|
||||
BindFaceGrid();
|
||||
BindToolbar();
|
||||
BindSections();
|
||||
BindSettings();
|
||||
BindDetailSplit();
|
||||
|
||||
RestorePrefs();
|
||||
SyncUiFromSettings();
|
||||
// 面片网格的行列数只在 RefreshFaceUi 里回写,开窗时得先走一遍,
|
||||
// 否则那行字会停在 UXML 的默认值上,和实际渲染的格子对不上
|
||||
RefreshFaceUi();
|
||||
AdoptSelectionIfEmpty();
|
||||
AssignSource(m_Source.sourceShader, m_Source.sourceMaterial, true);
|
||||
DoRender();
|
||||
|
||||
// 实时预览的节拍由这里驱动,域重载/关窗口时在 OnDisable 里摘掉
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
EditorApplication.update += OnEditorUpdate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器心跳:实时预览开着就按固定节拍重画,不管有没有"改动事件"。
|
||||
///
|
||||
/// <para>之所以不能只等控件回调:数字框是延迟提交的,拖标签刻度、在别处改材质、
|
||||
/// shader 里用 <c>_Time</c> 挪顶点,这些都不会发 ChangeEvent——表现就是"界面不跟着刷新"。
|
||||
/// 关掉实时预览时这里什么都不做,改动只标记成待刷新。</para>
|
||||
/// </summary>
|
||||
private void OnEditorUpdate()
|
||||
{
|
||||
if (m_Renderer == null || m_Preview == null || m_AutoRefreshToggle == null || !m_AutoRefreshToggle.value)
|
||||
return;
|
||||
double now = EditorApplication.timeSinceStartup;
|
||||
if (now < m_NextLiveRender)
|
||||
return;
|
||||
|
||||
// 实测两次心跳之间的间隔。它是"看到的帧率",和渲染本身花了多少毫秒不是一回事:
|
||||
// 卡在别处时两个数会差很远,只有摆出来才分得清是谁的问题
|
||||
if (m_LastHeartbeatTime > 0.0)
|
||||
{
|
||||
float delta = (float)((now - m_LastHeartbeatTime) * 1000.0);
|
||||
m_LiveFrameMs = m_LiveFrameMs < 0f ? delta : Mathf.Lerp(m_LiveFrameMs, delta, 0.3f);
|
||||
}
|
||||
m_LastHeartbeatTime = now;
|
||||
|
||||
m_NextLiveRender = now + (hasFocus ? kLiveIntervalFocused : kLiveIntervalBlurred);
|
||||
DoRender(true);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
SavePrefs();
|
||||
if (m_Exporter != null)
|
||||
m_Exporter.settingsReplaced -= OnSettingsReplaced;
|
||||
@@ -143,8 +229,9 @@ namespace XericUI.ShaderBake.Editor
|
||||
m_PropertyTable.Dispose();
|
||||
if (m_Preview != null)
|
||||
m_Preview.Dispose();
|
||||
// 临时材质一定要还:它挂着的是 shader,不销毁就是每次开关窗口漏一份
|
||||
ReleaseSelfTestTarget();
|
||||
// 探针那张 RT 归探针所有,先收探针;测试视图材质挂着 shader,不销毁就是每次开关窗口漏一份
|
||||
m_Override.Release();
|
||||
ReleaseDebugMaterial();
|
||||
if (m_Source != null) m_Source.Dispose(true);
|
||||
if (m_Renderer != null) m_Renderer.Dispose(true);
|
||||
m_Source = null;
|
||||
@@ -178,6 +265,7 @@ namespace XericUI.ShaderBake.Editor
|
||||
m_ExportButton = Require<ToolbarButton>("export-menu");
|
||||
m_AutoRefreshToggle = Require<ToolbarToggle>("auto-refresh");
|
||||
m_CheckerToggle = Require<ToolbarToggle>("show-checker");
|
||||
m_DebugButton = Require<ToolbarButton>("debug-view");
|
||||
m_StatusMessage = Require<Label>("status-message");
|
||||
m_StatusSize = Require<Label>("status-size");
|
||||
m_StatusTime = Require<Label>("status-time");
|
||||
@@ -249,10 +337,25 @@ namespace XericUI.ShaderBake.Editor
|
||||
|
||||
ToolbarButton render = rootVisualElement.Q<ToolbarButton>("render-now");
|
||||
if (render != null)
|
||||
{
|
||||
m_RenderButton = render;
|
||||
render.clicked += DoRender;
|
||||
}
|
||||
|
||||
if (m_AutoRefreshToggle != null)
|
||||
m_AutoRefreshToggle.RegisterValueChangedCallback(evt => { SavePrefs(); });
|
||||
{
|
||||
m_AutoRefreshToggle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
// 这个勾就是"要不要一直重画"的总开关:打开时把攒下的待刷新立刻补上,
|
||||
// 关掉时不再重画,只把它记成待刷新显示在「重新渲染」上
|
||||
m_LastHeartbeatTime = 0.0;
|
||||
m_LiveFrameMs = -1f;
|
||||
UpdateRenderButton();
|
||||
if (evt.newValue && m_PendingRefresh)
|
||||
DoRender();
|
||||
SavePrefs();
|
||||
});
|
||||
}
|
||||
|
||||
if (m_CheckerToggle != null)
|
||||
m_CheckerToggle.RegisterValueChangedCallback(evt =>
|
||||
@@ -261,6 +364,9 @@ namespace XericUI.ShaderBake.Editor
|
||||
SavePrefs();
|
||||
});
|
||||
|
||||
if (m_DebugButton != null)
|
||||
m_DebugButton.clicked += ShowDebugMenu;
|
||||
|
||||
Click("zoom-in", () => { if (m_Preview != null) { m_Preview.autoFit = false; m_Preview.ZoomIn(); } });
|
||||
Click("zoom-out", () => { if (m_Preview != null) { m_Preview.autoFit = false; m_Preview.ZoomOut(); } });
|
||||
Click("zoom-fit", () => { if (m_Preview != null) m_Preview.FitToView(); });
|
||||
@@ -283,6 +389,11 @@ namespace XericUI.ShaderBake.Editor
|
||||
private void ShowExportMenu()
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
if (m_DebugView != DebugView.None)
|
||||
{
|
||||
// 免得有人对着一张测试色块图等它导出成那张图——导出永远走真实材质
|
||||
menu.AddDisabledItem(new GUIContent("当前显示的是测试视图,导出仍按真实材质"), false);
|
||||
}
|
||||
m_Exporter.BuildMenu(menu, SuggestedExportName());
|
||||
if (m_ExportButton != null)
|
||||
menu.DropDown(m_ExportButton.worldBound);
|
||||
@@ -302,33 +413,6 @@ namespace XericUI.ShaderBake.Editor
|
||||
return "BakedImage";
|
||||
}
|
||||
|
||||
// ── 分组折叠 ────────────────────────────────────────────
|
||||
|
||||
private void BindSections()
|
||||
{
|
||||
// 头部是 Toggle(名字带 -head),外层同名容器只是分组壳,别拿它去 Q<Toggle>
|
||||
Collapsible("sec-source-head", "sec-source-body");
|
||||
Collapsible("sec-output-head", "sec-output-body");
|
||||
Collapsible("sec-surface-head", "sec-surface-body");
|
||||
Collapsible("sec-camera-head", "sec-camera-body");
|
||||
Collapsible("sec-globals-head", "sec-globals-body");
|
||||
Collapsible("sec-props-head", "sec-props-body");
|
||||
}
|
||||
|
||||
private void Collapsible(string headName, string bodyName)
|
||||
{
|
||||
Toggle head = rootVisualElement.Q<Toggle>(headName);
|
||||
VisualElement body = rootVisualElement.Q<VisualElement>(bodyName);
|
||||
if (head == null || body == null)
|
||||
{
|
||||
Debug.LogError("[ShaderBake] 分组节点不成对:" + headName + " / " + bodyName);
|
||||
return;
|
||||
}
|
||||
body.style.display = head.value ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
head.RegisterValueChangedCallback(evt =>
|
||||
body.style.display = evt.newValue ? DisplayStyle.Flex : DisplayStyle.None);
|
||||
}
|
||||
|
||||
// ── 输入源 ──────────────────────────────────────────────
|
||||
|
||||
private void BindSettings()
|
||||
@@ -423,7 +507,7 @@ namespace XericUI.ShaderBake.Editor
|
||||
{
|
||||
note.text = m_Source.shader == null
|
||||
? "未指定 shader"
|
||||
: (m_PropertyTable.rowCount + " 项可编辑属性(隐藏属性不列出)");
|
||||
: (m_PropertyTable.rowCount + " 项属性");
|
||||
if (!string.IsNullOrEmpty(textureHint))
|
||||
note.text += "\n" + textureHint;
|
||||
}
|
||||
@@ -483,7 +567,7 @@ namespace XericUI.ShaderBake.Editor
|
||||
{
|
||||
m_Renderer.settings.globals.AddEnvironmentPresets();
|
||||
RefreshGlobals();
|
||||
SetStatus("已加入常用光照/环境预设(勾选才生效)");
|
||||
SetStatus("已加入预设");
|
||||
}
|
||||
|
||||
// ── 输出 ────────────────────────────────────────────────
|
||||
@@ -573,6 +657,8 @@ namespace XericUI.ShaderBake.Editor
|
||||
{
|
||||
m_Renderer.settings.surface.ResetGrid();
|
||||
m_SelectedFace = 0;
|
||||
// 回到一格之后相机也得跟着回到"整个面片",否则画面还停在上一格的放大上
|
||||
m_Renderer.FitCameraToGeometry();
|
||||
Commit();
|
||||
});
|
||||
Click("face-zero", () =>
|
||||
@@ -584,6 +670,7 @@ namespace XericUI.ShaderBake.Editor
|
||||
cell.uvY = 0;
|
||||
Commit();
|
||||
});
|
||||
Click("face-fit", FitCameraOnSelectedFace);
|
||||
|
||||
BindInt("face-uv-x",
|
||||
() => SelectedFaceCell() != null ? SelectedFaceCell().uvX : 0,
|
||||
@@ -596,6 +683,9 @@ namespace XericUI.ShaderBake.Editor
|
||||
/// <summary>
|
||||
/// 在左/右加一列,或上/下加一行。新格的 UV 编号由 <see cref="ShaderBakeSurfaceSettings"/>
|
||||
/// 按贴边那一格往外推,所以向左加出来的一定是 [-1,0] 这种负号区间。
|
||||
///
|
||||
/// <para>加完自动把相机退回"能看到全部格子"——不然画面还停在上一格的放大上,
|
||||
/// 新加的格在哪、现在一共几×几,都看不出来。</para>
|
||||
/// </summary>
|
||||
private void ResizeGrid(bool negativeSide, bool column)
|
||||
{
|
||||
@@ -604,6 +694,7 @@ namespace XericUI.ShaderBake.Editor
|
||||
surface.AddColumn(!negativeSide);
|
||||
else
|
||||
surface.AddRow(!negativeSide);
|
||||
m_Renderer.FitCameraToGeometry();
|
||||
Commit();
|
||||
SetStatus(surface.gridColumns + " × " + surface.gridRows + " 格");
|
||||
}
|
||||
@@ -647,28 +738,23 @@ namespace XericUI.ShaderBake.Editor
|
||||
{
|
||||
faceInfo.text = meshMode
|
||||
? "外部网格不参与面片点选"
|
||||
: "选中第 " + (m_SelectedFace + 1) + " 格:UV (" + cell.uvX + ", " + cell.uvY + ")\n" +
|
||||
FaceCornerText(surface, cell);
|
||||
: "第 " + (m_SelectedFace + 1) + " 格 · UV (" + cell.uvX + ", " + cell.uvY + ")";
|
||||
}
|
||||
SetFaceFieldsEnabled(!meshMode);
|
||||
// 两个 UV 输入框绑的是"当前选中格",换格就得跟着换;
|
||||
// 它们只在 SyncUiFromSettings 里同步,点选走的是这条路径,不补这一句就一直停在旧格上
|
||||
SetFaceUvFields(cell);
|
||||
UpdateFaceOverlay();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 这一格四个顶点的实际 UV 写出来。"设为 UV0" 的约定就是四角落在 (0,0)(1,0)(0,1)(1,1),
|
||||
/// 再乘重复、加偏移;把结果摊开显示,是不是这个范围一眼就能核对。
|
||||
/// </summary>
|
||||
private static string FaceCornerText(ShaderBakeSurfaceSettings surface, ShaderBakeFaceCell cell)
|
||||
private void SetFaceUvFields(ShaderBakeFaceCell cell)
|
||||
{
|
||||
Vector2 min = Vector2.Scale(new Vector2(cell.uvX, cell.uvY), surface.uvTiling) + surface.uvOffset;
|
||||
Vector2 max = Vector2.Scale(new Vector2(cell.uvX + 1, cell.uvY + 1), surface.uvTiling) + surface.uvOffset;
|
||||
return "四角 UV:(" + Corners(min.x, max.x) + ", " + Corners(min.y, max.y) + ")";
|
||||
}
|
||||
|
||||
/// <summary> 一个轴的两个角值,左下在前 </summary>
|
||||
private static string Corners(float low, float high)
|
||||
{
|
||||
return low.ToString("0.##") + " / " + high.ToString("0.##");
|
||||
int uvX = cell != null ? cell.uvX : 0;
|
||||
int uvY = cell != null ? cell.uvY : 0;
|
||||
var x = rootVisualElement.Q<VisualElement>("face-uv-x") as INotifyValueChanged<int>;
|
||||
if (x != null) x.SetValueWithoutNotify(uvX);
|
||||
var y = rootVisualElement.Q<VisualElement>("face-uv-y") as INotifyValueChanged<int>;
|
||||
if (y != null) y.SetValueWithoutNotify(uvY);
|
||||
}
|
||||
|
||||
private void SetFaceFieldsEnabled(bool enabled)
|
||||
@@ -679,7 +765,7 @@ namespace XericUI.ShaderBake.Editor
|
||||
if (y != null) y.SetEnabled(enabled);
|
||||
}
|
||||
|
||||
/// <summary> 把选中格的屏幕框和 UV 编号贴到浏览图上 </summary>
|
||||
/// <summary> 把选中格的屏幕框、分格线和每格的 UV 编号贴到浏览图上 </summary>
|
||||
private void UpdateFaceOverlay()
|
||||
{
|
||||
if (m_Preview == null || m_Renderer == null)
|
||||
@@ -688,17 +774,46 @@ namespace XericUI.ShaderBake.Editor
|
||||
if (surface.kind == ShaderBakeSurfaceKind.Mesh && surface.sourceMesh != null)
|
||||
{
|
||||
m_Preview.SetFaceSelection(false, Vector2.zero, Vector2.zero, string.Empty);
|
||||
m_Preview.SetFaceGrid(null, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2 min, max;
|
||||
if (!m_Renderer.TryGetFaceViewportBounds(m_SelectedFace, out min, out max))
|
||||
int columns = Mathf.Max(surface.gridColumns, 1);
|
||||
int rows = Mathf.Max(surface.gridRows, 1);
|
||||
m_GridCells.Clear();
|
||||
for (int i = 0; i < columns * rows; i++)
|
||||
{
|
||||
Vector2 min, max;
|
||||
ShaderBakeFaceCell cell = surface.GetFace(i);
|
||||
if (!m_Renderer.TryGetFaceViewportBounds(i, out min, out max))
|
||||
continue;
|
||||
// 完全在画面外的那几格(按「选中格铺满」之后就只剩一格可见)不参与,
|
||||
// 否则它们的包围盒会被夹成零面积,编号全挤在画面边上
|
||||
if (max.x - min.x < 0.001f || max.y - min.y < 0.001f)
|
||||
continue;
|
||||
m_GridCells.Add(new ShaderBakePreviewPane.FaceCellRect
|
||||
{
|
||||
min = min,
|
||||
max = max,
|
||||
label = "U" + cell.uvX + " V" + cell.uvY
|
||||
});
|
||||
}
|
||||
m_Preview.SetFaceGrid(m_GridCells, columns, rows);
|
||||
|
||||
Vector2 selMin, selMax;
|
||||
if (!m_Renderer.TryGetFaceViewportBounds(m_SelectedFace, out selMin, out selMax))
|
||||
{
|
||||
m_Preview.SetFaceSelection(false, Vector2.zero, Vector2.zero, string.Empty);
|
||||
return;
|
||||
}
|
||||
ShaderBakeFaceCell cell = surface.GetFace(m_SelectedFace);
|
||||
m_Preview.SetFaceSelection(true, min, max, "UV (" + cell.uvX + ", " + cell.uvY + ")");
|
||||
// 分了格就由每格的编号说明 UV,选中框只留框,不然同一格里两行字叠着
|
||||
m_Preview.SetFaceSelection(true, selMin, selMax, columns * rows > 1 ? string.Empty : SelectedFaceLabel());
|
||||
}
|
||||
|
||||
private string SelectedFaceLabel()
|
||||
{
|
||||
ShaderBakeFaceCell cell = SelectedFaceCell();
|
||||
return cell == null ? string.Empty : "UV (" + cell.uvX + ", " + cell.uvY + ")";
|
||||
}
|
||||
|
||||
// ── 面片 ────────────────────────────────────────────────
|
||||
@@ -714,6 +829,8 @@ namespace XericUI.ShaderBake.Editor
|
||||
kind.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
m_Renderer.settings.surface.kind = (ShaderBakeSurfaceKind)evt.newValue;
|
||||
// 换了来源,内容的宽高比也跟着换,投影得按新的重算
|
||||
m_Renderer.FitCameraToGeometry();
|
||||
Commit();
|
||||
});
|
||||
}
|
||||
@@ -766,11 +883,13 @@ namespace XericUI.ShaderBake.Editor
|
||||
importModel.clicked += ImportModel;
|
||||
}
|
||||
|
||||
// 面片那些"改一个分量"的写法摊成方法,绑定处只留一行,读起来不至于全是三元组
|
||||
private void SetSizeX(float v) { Vector2 s = m_Renderer.settings.surface.size; s.x = v; m_Renderer.settings.surface.size = s; }
|
||||
private void SetSizeY(float v) { Vector2 s = m_Renderer.settings.surface.size; s.y = v; m_Renderer.settings.surface.size = s; }
|
||||
private void SetSegmentX(int v) { Vector2Int s = m_Renderer.settings.surface.segments; s.x = v; m_Renderer.settings.surface.segments = s; }
|
||||
private void SetSegmentY(int v) { Vector2Int s = m_Renderer.settings.surface.segments; s.y = v; m_Renderer.settings.surface.segments = s; }
|
||||
// 面片那些"改一个分量"的写法摊成方法,绑定处只留一行,读起来不至于全是三元组。
|
||||
// 形状一变,投影里记的宽高比就过期了,画面会被裁一半或留一圈边;
|
||||
// 这几项改完顺手重框一次,保证内容始终铺满输出
|
||||
private void SetSizeX(float v) { Vector2 s = m_Renderer.settings.surface.size; s.x = v; m_Renderer.settings.surface.size = s; m_Renderer.FitCameraToGeometry(); }
|
||||
private void SetSizeY(float v) { Vector2 s = m_Renderer.settings.surface.size; s.y = v; m_Renderer.settings.surface.size = s; m_Renderer.FitCameraToGeometry(); }
|
||||
private void SetSegmentX(int v) { Vector2Int s = m_Renderer.settings.surface.segments; s.x = v; m_Renderer.settings.surface.segments = s; m_Renderer.FitCameraToGeometry(); }
|
||||
private void SetSegmentY(int v) { Vector2Int s = m_Renderer.settings.surface.segments; s.y = v; m_Renderer.settings.surface.segments = s; m_Renderer.FitCameraToGeometry(); }
|
||||
private void SetUvOffsetX(float v) { Vector2 u = m_Renderer.settings.surface.uvOffset; u.x = v; m_Renderer.settings.surface.uvOffset = u; }
|
||||
private void SetUvOffsetY(float v) { Vector2 u = m_Renderer.settings.surface.uvOffset; u.y = v; m_Renderer.settings.surface.uvOffset = u; }
|
||||
private void SetUvTileX(float v) { Vector2 u = m_Renderer.settings.surface.uvTiling; u.x = v; m_Renderer.settings.surface.uvTiling = u; }
|
||||
@@ -866,88 +985,53 @@ namespace XericUI.ShaderBake.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用一个不吃贴图、不吃光照、不吃 UV 的内置纯色 shader,按<b>同一套</b>面片/相机/pass 再画一次。
|
||||
/// 画得出来就说明管线是通的,画面空的原因在被测 shader 那边(贴图没指定、pass、混合模式);
|
||||
/// 画不出来才是这里的问题(相机框不住、面片尺寸、pass 下标)。
|
||||
/// 相机改成只框选中的那一格。「框住面片」量的是整个网格,多格时一格只占画面中间一小块,
|
||||
/// 这就是"烘出来的尺寸和场景里贴上去不一样"的来源——铺满之后一格才等于一整张图。
|
||||
/// </summary>
|
||||
private void RunPipelineSelfTest()
|
||||
private void FitCameraOnSelectedFace()
|
||||
{
|
||||
Shader solid = Shader.Find("Unlit/Color");
|
||||
if (solid == null)
|
||||
if (!m_Renderer.FitCameraOnFace(m_SelectedFace))
|
||||
{
|
||||
SetSelfTestNote("自检不可用:这个工程里找不到 Unlit/Color");
|
||||
SetStatus("外部网格不分格");
|
||||
return;
|
||||
}
|
||||
ReleaseSelfTestTarget();
|
||||
|
||||
var probeMaterial = new Material(solid)
|
||||
{
|
||||
name = "ShaderBakeSelfTest",
|
||||
hideFlags = HideFlags.DontSave
|
||||
};
|
||||
probeMaterial.color = new Color(0.25f, 0.85f, 0.5f);
|
||||
|
||||
float coverage = -1f;
|
||||
string failure = string.Empty;
|
||||
// settings 是共享引用:自检必须和被测走同一套面片/相机/pass,才有控制变量的意义。
|
||||
// 探针还要活着:它一 Dispose 就把那张 RT 一起销毁了,而自检结果正是那张图。
|
||||
// 下一次正常渲染或关窗口时由 ReleaseSelfTestTarget 收掉。
|
||||
m_SelfTestMaterial = probeMaterial;
|
||||
m_SelfTestProbe = new ShaderBakeRenderer { settings = m_Renderer.settings, material = probeMaterial };
|
||||
try
|
||||
{
|
||||
RenderTexture rt = m_SelfTestProbe.Render();
|
||||
if (rt == null)
|
||||
failure = m_SelfTestProbe.lastError;
|
||||
else
|
||||
{
|
||||
Color average;
|
||||
if (ShaderBakeReadback.MeasureCoverage(rt, out coverage, out average))
|
||||
{
|
||||
// 把纯色结果直接显示出来:数字说有像素,眼睛说看到什么,两边对上才算过
|
||||
m_SelfTestTarget = rt;
|
||||
m_Preview.SetResult(rt, m_Renderer.settings.output.size);
|
||||
m_Preview.SetCoverage(coverage, average);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception evt)
|
||||
{
|
||||
failure = evt.Message;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(failure))
|
||||
{
|
||||
SetSelfTestNote("自检失败:" + failure);
|
||||
return;
|
||||
}
|
||||
if (coverage <= 0.001f)
|
||||
{
|
||||
SetSelfTestNote("自检未画出任何像素 → 问题在渲染管线。" + DescribePipeline() +
|
||||
" 先按「框住面片」再自检一次;仍为空就查 pass 下标与面片宽高。");
|
||||
SetStatus("管线自检:空画面");
|
||||
return;
|
||||
}
|
||||
SetSelfTestNote("自检通过:纯色面片不透明 " + Mathf.RoundToInt(coverage * 100f) +
|
||||
"%。管线是通的,画面空是被测 shader 自己的事(贴图、pass、混合模式、需要光照)");
|
||||
SetStatus("管线自检:正常");
|
||||
Commit();
|
||||
SetStatus("第 " + (m_SelectedFace + 1) + " 格已铺满");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把决定"画不画得见"的那几个数值摊开写一行。空画面的时候最缺的就是这个——
|
||||
/// 否则只能靠猜是相机框不住、面片太小还是 pass 选错。
|
||||
/// 用一张不吃贴图、不吃光照、不吃 UV 的内置纯色面片,按<b>同一套</b>面片 / 相机再画一次。
|
||||
/// 画得出来就说明管线是通的,画面空的原因在被测 shader 那边(贴图没指定、混合模式、需要光照);
|
||||
/// 画不出来才是这里的问题(相机框不住、面片尺寸)。
|
||||
///
|
||||
/// <para>它就是测试视图里的一种,所以结果会跟着实时预览一直留在画面上,
|
||||
/// 不再像从前那样被下一次重画顶掉。</para>
|
||||
/// </summary>
|
||||
private string DescribePipeline()
|
||||
private void RunPipelineSelfTest()
|
||||
{
|
||||
ShaderBakeSettings s = m_Renderer.settings;
|
||||
return "正交=" + s.camera.orthographic +
|
||||
" 半高=" + s.camera.orthographicSize.ToString("0.###") +
|
||||
" 近/远=" + s.camera.nearClipPlane.ToString("0.###") + "/" + s.camera.farClipPlane.ToString("0.###") +
|
||||
" 机位=" + s.camera.position +
|
||||
" 面片=" + s.surface.gridColumns + "×" + s.surface.gridRows + " 格 尺寸=" + s.surface.size +
|
||||
" 双面=" + s.surface.doubleSided +
|
||||
" pass=" + s.output.shaderPass +
|
||||
" 翻转Y=" + s.output.flipY;
|
||||
if (m_DebugView == DebugView.SolidColor)
|
||||
DoRender();
|
||||
else
|
||||
SetDebugView(DebugView.SolidColor);
|
||||
|
||||
if (m_DebugView != DebugView.SolidColor)
|
||||
{
|
||||
SetSelfTestNote("自检失败:纯色探针画不出来");
|
||||
return;
|
||||
}
|
||||
if (m_LastCoverage < 0f)
|
||||
{
|
||||
SetSelfTestNote("自检失败:读不回像素");
|
||||
return;
|
||||
}
|
||||
if (m_LastCoverage <= 0.001f)
|
||||
{
|
||||
SetSelfTestNote("自检失败:空画面");
|
||||
SetStatus("管线自检:空画面");
|
||||
return;
|
||||
}
|
||||
SetSelfTestNote("自检通过");
|
||||
SetStatus("管线自检:正常");
|
||||
}
|
||||
|
||||
private void SetSelfTestNote(string text)
|
||||
@@ -957,19 +1041,6 @@ namespace XericUI.ShaderBake.Editor
|
||||
note.text = text;
|
||||
}
|
||||
|
||||
private void ReleaseSelfTestTarget()
|
||||
{
|
||||
// 探针自己会回收那张 RT,所以先释放探针、再清引用,别两边各销毁一次
|
||||
if (m_SelfTestProbe != null)
|
||||
{
|
||||
m_SelfTestProbe.Dispose(true);
|
||||
m_SelfTestProbe = null;
|
||||
m_SelfTestTarget = null;
|
||||
}
|
||||
ShaderBakeRenderer.ReleaseTempObject(m_SelfTestMaterial, true);
|
||||
m_SelfTestMaterial = null;
|
||||
}
|
||||
|
||||
// ── 右侧细节栏宽度 ──────────────────────────────────────
|
||||
|
||||
private void BindDetailSplit()
|
||||
@@ -1115,11 +1186,28 @@ namespace XericUI.ShaderBake.Editor
|
||||
|
||||
// ── 渲染 ────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// 「重新渲染」按钮兼任待刷新指示灯:实时预览关掉的时候画面不会自己跟上参数,
|
||||
/// 只在按钮上写出来,比只靠状态栏一句话可靠。
|
||||
/// </summary>
|
||||
private void UpdateRenderButton()
|
||||
{
|
||||
if (m_RenderButton == null)
|
||||
return;
|
||||
bool pending = m_PendingRefresh && (m_AutoRefreshToggle == null || !m_AutoRefreshToggle.value);
|
||||
m_RenderButton.text = pending ? "重新渲染 · 待刷新" : "重新渲染";
|
||||
m_RenderButton.EnableInClassList("toolbar-emphasize", pending);
|
||||
}
|
||||
|
||||
private void RequestRender()
|
||||
{
|
||||
if (m_AutoRefreshToggle != null && !m_AutoRefreshToggle.value)
|
||||
{
|
||||
SetStatus("参数已改,按「重新渲染」出图");
|
||||
// 实时预览关着的时候,改完参数画面不会自己动,所以把"待刷新"直接写在按钮上——
|
||||
// 否则只有一条状态栏提示,很容易被下一次别的状态覆盖掉,看不出来画面已经旧了
|
||||
m_PendingRefresh = true;
|
||||
UpdateRenderButton();
|
||||
SetStatus("参数已改");
|
||||
return;
|
||||
}
|
||||
if (m_RenderPending)
|
||||
@@ -1137,12 +1225,34 @@ namespace XericUI.ShaderBake.Editor
|
||||
}
|
||||
|
||||
private void DoRender()
|
||||
{
|
||||
DoRender(false);
|
||||
}
|
||||
|
||||
/// <param name="fromHeartbeat">
|
||||
/// 实时预览的定时重画。心跳每秒几十次,状态栏那句"已渲染"要是照写不误,
|
||||
/// 刚按「选中格铺满」给出的提示就活不过一帧,所以心跳只更新画面与时间,不抢话。
|
||||
/// </param>
|
||||
private void DoRender(bool fromHeartbeat)
|
||||
{
|
||||
m_RenderPending = false;
|
||||
m_PendingRefresh = false;
|
||||
UpdateRenderButton();
|
||||
if (m_Renderer == null || m_Preview == null)
|
||||
return;
|
||||
// 真实结果回来了,自检那张临时图就该退场
|
||||
ReleaseSelfTestTarget();
|
||||
|
||||
bool measureCoverage = ShouldMeasureCoverage(fromHeartbeat);
|
||||
bool wantDebugView = m_DebugView != DebugView.None;
|
||||
if (wantDebugView && RenderDebugView(measureCoverage, fromHeartbeat))
|
||||
return;
|
||||
if (wantDebugView)
|
||||
{
|
||||
// 探针点不着就别让界面停在一个空视图上,也不让心跳每帧都撞一次同一个错误
|
||||
m_DebugView = DebugView.None;
|
||||
m_Override.Release();
|
||||
ReleaseDebugMaterial();
|
||||
UpdateDebugUi();
|
||||
}
|
||||
|
||||
double start = EditorApplication.timeSinceStartup;
|
||||
RenderTexture rt = m_Renderer.Render();
|
||||
@@ -1152,51 +1262,234 @@ namespace XericUI.ShaderBake.Editor
|
||||
{
|
||||
m_Preview.Clear();
|
||||
SetStatus(string.IsNullOrEmpty(m_Renderer.lastError) ? "渲染失败" : m_Renderer.lastError);
|
||||
UpdateSizeReadout();
|
||||
UpdateSizeReadout(true);
|
||||
return;
|
||||
}
|
||||
|
||||
m_Preview.SetResult(rt, m_Renderer.settings.output.size);
|
||||
if (measureCoverage)
|
||||
MeasureCoverage(rt, !fromHeartbeat);
|
||||
// 分格线与编号只跟参数、相机有关,而参数一改必然带一次非心跳渲染;
|
||||
// 心跳时再刷一遍等于每帧让 Yoga 重排整个覆盖层,这是预览发卡的来源之一
|
||||
if (!fromHeartbeat)
|
||||
UpdateFaceOverlay();
|
||||
UpdateSizeReadout(!fromHeartbeat);
|
||||
if (fromHeartbeat)
|
||||
return;
|
||||
if (string.IsNullOrEmpty(m_StatusMessage.text) || m_StatusMessage.text.StartsWith("导出") || m_StatusMessage.text.StartsWith("参数已改"))
|
||||
SetStatus("已渲染");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 覆盖率量的是"这一轮画面上有没有东西",慢变化,两秒一次足够;参数一改则立刻量。
|
||||
/// 心跳时每次都量的话,每帧都要同步一次显卡,实时预览就变成卡顿本身。
|
||||
/// 不量的时候沿用上一个读数,界面不会因此少信息。
|
||||
/// </summary>
|
||||
private bool ShouldMeasureCoverage(bool fromHeartbeat)
|
||||
{
|
||||
double now = EditorApplication.timeSinceStartup;
|
||||
if (!fromHeartbeat || now >= m_NextCoverageCheck)
|
||||
{
|
||||
m_NextCoverageCheck = now + kCoverageInterval;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void MeasureCoverage(RenderTexture rt, bool log)
|
||||
{
|
||||
float coverage;
|
||||
Color average;
|
||||
m_LastCoverage = ShaderBakeReadback.MeasureCoverage(rt, out coverage, out average) ? coverage : -1f;
|
||||
if (m_LastCoverage >= 0f)
|
||||
m_Preview.SetCoverage(m_LastCoverage, average);
|
||||
UpdateFaceOverlay();
|
||||
UpdateSizeReadout();
|
||||
if (string.IsNullOrEmpty(m_StatusMessage.text) || m_StatusMessage.text.StartsWith("导出"))
|
||||
SetStatus("已渲染");
|
||||
if (!log || m_LastCoverage < 0f)
|
||||
return;
|
||||
// 数字不摆在界面上——画没画出来看图就知道了,这里只留给排查时从 Console / Editor.log 里翻。
|
||||
// 只在百分比变了才写一行:拖滑块时画面参数一直在变,读数不变就不该刷屏
|
||||
int percent = Mathf.RoundToInt(m_LastCoverage * 100f);
|
||||
if (percent == m_LoggedCoverage)
|
||||
return;
|
||||
m_LoggedCoverage = percent;
|
||||
Debug.Log("[ShaderBake] 不透明 " + percent + "%");
|
||||
}
|
||||
|
||||
// ── 测试视图 ────────────────────────────────────────────
|
||||
|
||||
private void ShowDebugMenu()
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
AddDebugItem(menu, "无", DebugView.None);
|
||||
menu.AddSeparator(string.Empty);
|
||||
AddDebugItem(menu, "UV", DebugView.Uv);
|
||||
AddDebugItem(menu, "梯度", DebugView.Gradient);
|
||||
AddDebugItem(menu, "棋盘", DebugView.Checker);
|
||||
AddDebugItem(menu, "纯色", DebugView.SolidColor);
|
||||
if (m_DebugButton != null)
|
||||
menu.DropDown(m_DebugButton.worldBound);
|
||||
else
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
private void AddDebugItem(GenericMenu menu, string label, DebugView view)
|
||||
{
|
||||
menu.AddItem(new GUIContent(label), m_DebugView == view, OnDebugChosen, view);
|
||||
}
|
||||
|
||||
private void OnDebugChosen(object userData)
|
||||
{
|
||||
SetDebugView((DebugView)userData);
|
||||
}
|
||||
|
||||
private void SetDebugView(DebugView view)
|
||||
{
|
||||
if (view == m_DebugView)
|
||||
return;
|
||||
m_DebugView = view;
|
||||
// 材质里写着这一次要画哪种图,换视图就得重建
|
||||
ReleaseDebugMaterial();
|
||||
if (view == DebugView.None)
|
||||
{
|
||||
// 测试视图不看了,探针占着的显存也该还回来
|
||||
m_Override.Release();
|
||||
}
|
||||
UpdateDebugUi();
|
||||
DoRender();
|
||||
SavePrefs();
|
||||
}
|
||||
|
||||
private void UpdateSizeReadout()
|
||||
private void UpdateDebugUi()
|
||||
{
|
||||
if (m_DebugButton != null)
|
||||
m_DebugButton.text = m_DebugView == DebugView.None
|
||||
? "测试视图 ▾"
|
||||
: DebugViewName(m_DebugView) + " ▾";
|
||||
}
|
||||
|
||||
private static string DebugViewName(DebugView view)
|
||||
{
|
||||
switch (view)
|
||||
{
|
||||
case DebugView.Uv: return "UV";
|
||||
case DebugView.Gradient: return "梯度";
|
||||
case DebugView.Checker: return "棋盘";
|
||||
case DebugView.SolidColor: return "纯色";
|
||||
default: return "无";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试视图的材质常驻,按当前视图建一次反复用——每秒重画几十次的路子上,
|
||||
/// 每次都新建再 DestroyImmediate 一张材质本身就是卡顿来源。换视图时才重建。
|
||||
/// </summary>
|
||||
private bool EnsureDebugMaterial()
|
||||
{
|
||||
if (m_DebugMaterial != null)
|
||||
return true;
|
||||
|
||||
if (m_DebugView == DebugView.SolidColor)
|
||||
return EnsureSolidDebugMaterial();
|
||||
|
||||
// 先按名字找:这张 shader 在 Editor 目录里,编辑器下 Shader.Find 认得到;
|
||||
// 找不到再按资产路径捞一次,覆盖包被放进 Assets/ 的安装方式
|
||||
Shader shader = Shader.Find(kDebugViewShader);
|
||||
if (shader == null)
|
||||
shader = LoadAsset<Shader>(kDebugViewShaderPath, "ShaderBakeDebugView");
|
||||
if (shader == null)
|
||||
{
|
||||
Debug.LogWarning("[ShaderBake] 测试视图不可用:包内找不到 " + kDebugViewShader + "(ShaderBakeDebugView.shader 没被导入?)");
|
||||
SetStatus("测试视图不可用:包里找不到 " + kDebugViewShader);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_DebugMaterial = new Material(shader)
|
||||
{
|
||||
name = "ShaderBakeDebugView",
|
||||
hideFlags = HideFlags.DontSave
|
||||
};
|
||||
m_DebugMaterial.SetFloat("_Mode", (float)(int)m_DebugView);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool EnsureSolidDebugMaterial()
|
||||
{
|
||||
Shader solid = Shader.Find("Unlit/Color");
|
||||
if (solid == null)
|
||||
{
|
||||
Debug.LogWarning("[ShaderBake] 纯色探针不可用:这个工程里找不到 Unlit/Color");
|
||||
SetStatus("纯色探针不可用:找不到 Unlit/Color");
|
||||
return false;
|
||||
}
|
||||
m_DebugMaterial = new Material(solid)
|
||||
{
|
||||
name = "ShaderBakeSelfTest",
|
||||
hideFlags = HideFlags.DontSave
|
||||
};
|
||||
m_DebugMaterial.color = new Color(0.25f, 0.85f, 0.5f);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ReleaseDebugMaterial()
|
||||
{
|
||||
ShaderBakeRenderer.ReleaseTempObject(m_DebugMaterial, true);
|
||||
m_DebugMaterial = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按<b>同一套</b>面片 / 相机把测试图画一次。返回 false 表示探针不可用,调用方回落到真实结果。
|
||||
///
|
||||
/// <para>只换"看"的那张图:导出、材质属性表、写回原材质都不受影响,仍走真实材质。</para>
|
||||
/// </summary>
|
||||
private bool RenderDebugView(bool measureCoverage, bool fromHeartbeat)
|
||||
{
|
||||
if (!EnsureDebugMaterial())
|
||||
return false;
|
||||
|
||||
// 测试图要把 UV 换算回"每格 0~1",得知道当前的重复与偏移;这两项随时可改,每次渲染都推一遍
|
||||
if (m_DebugView != DebugView.SolidColor)
|
||||
{
|
||||
m_DebugMaterial.SetVector("_UvTiling", m_Renderer.settings.surface.uvTiling);
|
||||
m_DebugMaterial.SetVector("_UvOffset", m_Renderer.settings.surface.uvOffset);
|
||||
}
|
||||
|
||||
double start = EditorApplication.timeSinceStartup;
|
||||
string error;
|
||||
RenderTexture rt = m_Override.RenderWithMaterial(m_Renderer.settings, m_DebugMaterial, out error);
|
||||
m_LastRenderMs = (EditorApplication.timeSinceStartup - start) * 1000.0;
|
||||
if (rt == null)
|
||||
{
|
||||
Debug.LogWarning("[ShaderBake] 测试视图渲染失败:" + error);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Preview.SetResult(rt, m_Renderer.settings.output.size);
|
||||
if (measureCoverage)
|
||||
MeasureCoverage(rt, !fromHeartbeat);
|
||||
if (!fromHeartbeat)
|
||||
UpdateFaceOverlay();
|
||||
UpdateSizeReadout(!fromHeartbeat);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <param name="immediate">
|
||||
/// 参数改动、换测试视图这类"画面刚变"的时刻要立刻反映;
|
||||
/// 心跳则走 5Hz 节流——数字每帧变一次等于每帧都让状态栏重排一遍
|
||||
/// </param>
|
||||
private void UpdateSizeReadout(bool immediate)
|
||||
{
|
||||
double now = EditorApplication.timeSinceStartup;
|
||||
if (!immediate && now < m_NextStatusUpdate)
|
||||
return;
|
||||
m_NextStatusUpdate = now + 0.2;
|
||||
|
||||
if (m_StatusSize != null)
|
||||
m_StatusSize.text = m_Renderer.settings.output.width + "×" + m_Renderer.settings.output.height;
|
||||
if (m_StatusTime != null)
|
||||
m_StatusTime.text = m_LastRenderMs < 0.0 ? "-" : m_LastRenderMs.ToString("0.0") + " ms";
|
||||
UpdateMeshReadout();
|
||||
}
|
||||
|
||||
private void UpdateMeshReadout()
|
||||
{
|
||||
// 顶点数只在状态栏出现:它决定细分够不够用,但不值得占一行界面
|
||||
Mesh mesh = m_Renderer != null ? m_Renderer.geometry : null;
|
||||
if (mesh == null || m_StatusMessage == null)
|
||||
return;
|
||||
if (m_StatusMessage.text.StartsWith("导出") || m_StatusMessage.text.StartsWith("参数已改"))
|
||||
return;
|
||||
m_StatusMessage.text = "已渲染 · " + mesh.vertexCount + " 顶点" + CoverageHint();
|
||||
}
|
||||
|
||||
/// <summary> 状态栏的覆盖率后缀:把"看着像没渲染"拆成"没画出来"和"画出来但是透明的" </summary>
|
||||
private string CoverageHint()
|
||||
{
|
||||
if (m_LastCoverage < 0f)
|
||||
return string.Empty;
|
||||
if (m_LastCoverage <= 0.001f)
|
||||
return " · 全透明,一个像素都没画出";
|
||||
return " · 不透明 " + Mathf.RoundToInt(m_LastCoverage * 100f) + "%";
|
||||
{
|
||||
string time = m_LastRenderMs < 0.0 ? "-" : m_LastRenderMs.ToString("0.0") + " ms";
|
||||
// 只在实时预览开着时报帧率:关掉之后那个数是上一次的,摆着会误导
|
||||
if (m_LiveFrameMs > 0.5f && m_AutoRefreshToggle != null && m_AutoRefreshToggle.value)
|
||||
time += " · " + Mathf.RoundToInt(1000f / m_LiveFrameMs) + " fps";
|
||||
m_StatusTime.text = time;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetStatus(string message)
|
||||
@@ -1211,6 +1504,11 @@ namespace XericUI.ShaderBake.Editor
|
||||
{
|
||||
m_Renderer.settings = ShaderBakeSettings.FromJson(EditorPrefs.GetString(kPrefSettings, string.Empty));
|
||||
|
||||
// 旧存档的"框住"框的是整个网格还带 15% 余量,画面里留了一圈空白。
|
||||
// 约定改成刚好铺满之后,旧配置开窗时重框一次;新存档带着版本号,不会再被动
|
||||
if (m_Renderer.settings.camera.fitRevision < ShaderBakeCameraSettings.kCurrentFitRevision)
|
||||
m_Renderer.FitCameraToGeometry();
|
||||
|
||||
if (m_AutoRefreshToggle != null)
|
||||
m_AutoRefreshToggle.SetValueWithoutNotify(EditorPrefs.GetBool(kPrefAutoRefresh, true));
|
||||
if (m_CheckerToggle != null)
|
||||
@@ -1219,6 +1517,9 @@ namespace XericUI.ShaderBake.Editor
|
||||
m_CheckerToggle.SetValueWithoutNotify(checker);
|
||||
if (m_Preview != null) m_Preview.SetCheckerVisible(checker);
|
||||
}
|
||||
// 开机默认关:这是排查用的视图,不该下次打开窗口还挡着真实结果
|
||||
m_DebugView = (DebugView)EditorPrefs.GetInt(kPrefDebugView, (int)DebugView.None);
|
||||
UpdateDebugUi();
|
||||
if (m_DetailPane != null)
|
||||
m_DetailPane.style.width = EditorPrefs.GetFloat(kPrefDetailWidth, kDefaultDetailWidth);
|
||||
|
||||
@@ -1248,6 +1549,7 @@ namespace XericUI.ShaderBake.Editor
|
||||
EditorPrefs.SetBool(kPrefAutoRefresh, m_AutoRefreshToggle.value);
|
||||
if (m_CheckerToggle != null)
|
||||
EditorPrefs.SetBool(kPrefChecker, m_CheckerToggle.value);
|
||||
EditorPrefs.SetInt(kPrefDebugView, (int)m_DebugView);
|
||||
if (m_DetailPane != null && m_DetailPane.resolvedStyle.width > 1f)
|
||||
EditorPrefs.SetFloat(kPrefDetailWidth, m_DetailPane.resolvedStyle.width);
|
||||
EditorPrefs.SetString(kPrefSource, SourceAssetPath() ?? string.Empty);
|
||||
|
||||
@@ -96,6 +96,34 @@
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* 分格线浮在图上:1px 白线 + 每格一个 UV 编号,都用百分比定位,缩放/滚动不用重排 */
|
||||
.grid-overlay {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: none;
|
||||
/* 贴边的编号宁可被裁掉,也不该糊到图上之外 */
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.grid-line {
|
||||
position: absolute;
|
||||
background-color: rgba(255, 255, 255, 0.38);
|
||||
}
|
||||
|
||||
.grid-cell-label {
|
||||
position: absolute;
|
||||
font-size: 10px;
|
||||
/* 白字压在半透明黑底上:浅色贴图上白字会糊掉,垫一层才读得出来 */
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
background-color: rgba(0, 0, 0, 0.38);
|
||||
padding: 0 4px;
|
||||
border-radius: 2px;
|
||||
-unity-text-align: middle-left;
|
||||
}
|
||||
|
||||
.preview-readout {
|
||||
position: absolute;
|
||||
left: 8px;
|
||||
@@ -143,19 +171,27 @@
|
||||
.section {
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-color: rgb(52, 52, 52);
|
||||
padding-top: 4px;
|
||||
padding-top: 2px;
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
|
||||
.section-head {
|
||||
/* 折叠头:Foldout 自带的三角就是状态指示,整条都能点,悬停给一点底色 */
|
||||
.section > .unity-foldout__toggle {
|
||||
font-size: 12px;
|
||||
margin-left: 6px;
|
||||
margin-bottom: 2px;
|
||||
color: rgb(225, 225, 225);
|
||||
margin-left: 2px;
|
||||
margin-bottom: 2px;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
padding-left: 8px;
|
||||
.section > .unity-foldout__toggle:hover {
|
||||
background-color: rgba(255, 255, 255, 0.07);
|
||||
}
|
||||
|
||||
/* 内容左右留边:子项不该贴着三角和面板边 */
|
||||
.section > .unity-foldout__content {
|
||||
padding-left: 10px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
@@ -292,11 +328,15 @@
|
||||
|
||||
.prop-slider {
|
||||
flex-grow: 1;
|
||||
min-width: 0;
|
||||
/* 主题里的滑块默认不收缩:不显式压回 1,它会占满整行并把右边的数值框挤出面板 */
|
||||
flex-shrink: 1;
|
||||
min-width: 40px;
|
||||
}
|
||||
|
||||
.prop-range-value {
|
||||
width: 58px;
|
||||
min-width: 58px;
|
||||
max-width: 58px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<x:ToolbarButton name="zoom-actual" text="1:1" />
|
||||
<x:ToolbarButton name="zoom-in" text="+" class="tool-narrow" />
|
||||
<x:ToolbarToggle name="show-checker" text="透明底" />
|
||||
<x:ToolbarButton name="debug-view" text="测试视图 ▾" />
|
||||
<x:ToolbarSpacer class="toolbar-gap" />
|
||||
<x:ToolbarButton name="reset-settings" text="重置参数" />
|
||||
</x:Toolbar>
|
||||
@@ -38,6 +39,8 @@
|
||||
<ui:VisualElement name="preview-frame" class="preview-frame">
|
||||
<ui:Image name="preview-checker" class="preview-checker" />
|
||||
<ui:Image name="preview-image" class="preview-image" />
|
||||
<!-- 分格线与每格的 UV 编号:位置按百分比算,缩放时不用重排 -->
|
||||
<ui:VisualElement name="grid-overlay" class="grid-overlay" />
|
||||
<!-- 选中面片的高亮:位置按百分比算,缩放时不用重排 -->
|
||||
<ui:VisualElement name="face-overlay" class="face-overlay">
|
||||
<ui:Label name="face-overlay-label" class="face-overlay-label" text="UV (0,0)" />
|
||||
@@ -55,9 +58,7 @@
|
||||
<ui:VisualElement name="detail-content" class="detail-content">
|
||||
|
||||
<!-- 输入源 -->
|
||||
<ui:VisualElement name="sec-source" class="section">
|
||||
<ui:Toggle name="sec-source-head" label="输入源" value="true" class="section-head" />
|
||||
<ui:VisualElement name="sec-source-body" class="section-body">
|
||||
<ui:Foldout name="sec-source" text="输入源" value="true" class="section">
|
||||
<x:ObjectField name="src-shader" label="Shader" class="field-full" />
|
||||
<x:ObjectField name="src-material" label="Material" class="field-full" />
|
||||
<ui:Label name="src-note" class="field-note" text="未指定" />
|
||||
@@ -65,13 +66,10 @@
|
||||
<ui:Button name="src-apply" text="写回原材质" class="field-half" />
|
||||
<ui:Button name="src-revert" text="丢弃改动" class="field-half" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:Foldout>
|
||||
|
||||
<!-- 输出目标 -->
|
||||
<ui:VisualElement name="sec-output" class="section">
|
||||
<ui:Toggle name="sec-output-head" label="输出" value="true" class="section-head" />
|
||||
<ui:VisualElement name="sec-output-body" class="section-body">
|
||||
<ui:Foldout name="sec-output" text="输出" value="true" class="section">
|
||||
<ui:VisualElement class="field-row">
|
||||
<ui:DropdownField name="out-preset" label="预设" class="field-half" />
|
||||
<ui:Button name="out-fit-aspect" text="匹配面片比例" class="field-half" />
|
||||
@@ -89,13 +87,10 @@
|
||||
<ui:Toggle name="out-hdr" label="HDR" class="field-toggle" />
|
||||
<ui:Toggle name="out-srgb" label="sRGB 存储" class="field-toggle" />
|
||||
<ui:Toggle name="out-flip" label="翻转 Y" class="field-toggle" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:Foldout>
|
||||
|
||||
<!-- 面片 -->
|
||||
<ui:VisualElement name="sec-surface" class="section">
|
||||
<ui:Toggle name="sec-surface-head" label="面片" value="true" class="section-head" />
|
||||
<ui:VisualElement name="sec-surface-body" class="section-body">
|
||||
<ui:Foldout name="sec-surface" text="面片" value="true" class="section">
|
||||
<xer:EnumField name="surf-kind" label="种类" class="field-full" />
|
||||
<ui:VisualElement class="field-row">
|
||||
<xer:FloatField name="surf-size-x" label="宽" class="field-half" />
|
||||
@@ -106,7 +101,7 @@
|
||||
<xer:IntegerField name="surf-seg-y" label="细分Y" class="field-half" />
|
||||
</ui:VisualElement>
|
||||
|
||||
<ui:Label class="field-note" text="面片网格(一格一张 UV 区域,向左/下扩展编号递减)" />
|
||||
<ui:Label class="field-note" text="面片网格" />
|
||||
<ui:Label name="grid-info" class="field-note" text="1 × 1" />
|
||||
<ui:VisualElement class="field-row">
|
||||
<ui:Button name="grid-left" text="←加列" class="field-quarter" />
|
||||
@@ -115,10 +110,11 @@
|
||||
<ui:Button name="grid-up" text="↑加行" class="field-quarter" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement class="field-row">
|
||||
<ui:Button name="grid-reset" text="恢复 1×1" class="field-half" />
|
||||
<ui:Button name="face-zero" text="选中面归零" class="field-half" />
|
||||
<ui:Button name="grid-reset" text="恢复 1×1" class="field-third" />
|
||||
<ui:Button name="face-zero" text="选中面归零" class="field-third" />
|
||||
<ui:Button name="face-fit" text="选中格铺满" class="field-third" />
|
||||
</ui:VisualElement>
|
||||
<ui:Label name="face-info" class="field-note" text="在左侧浏览图里点选面片" />
|
||||
<ui:Label name="face-info" class="field-note" text="点选面片" />
|
||||
<ui:VisualElement class="field-row">
|
||||
<xer:IntegerField name="face-uv-x" label="UV X" class="field-half" />
|
||||
<xer:IntegerField name="face-uv-y" label="UV Y" class="field-half" />
|
||||
@@ -165,13 +161,10 @@
|
||||
<ui:Button name="surf-flip-u" text="U镜像" class="field-third" />
|
||||
<ui:Button name="surf-flip-v" text="V镜像" class="field-third" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:Foldout>
|
||||
|
||||
<!-- 离屏相机 -->
|
||||
<ui:VisualElement name="sec-camera" class="section">
|
||||
<ui:Toggle name="sec-camera-head" label="相机" value="true" class="section-head" />
|
||||
<ui:VisualElement name="sec-camera-body" class="section-body">
|
||||
<ui:Foldout name="sec-camera" text="相机" value="true" class="section">
|
||||
<ui:Toggle name="cam-ortho" label="正交" class="field-toggle" />
|
||||
<xer:FloatField name="cam-ortho-size" label="正交半高" class="field-full" />
|
||||
<xer:FloatField name="cam-fov" label="视野角" class="field-full" />
|
||||
@@ -195,33 +188,24 @@
|
||||
<ui:Button name="cam-fit" text="框住面片" class="field-half" />
|
||||
<ui:Button name="cam-selftest" text="管线自检" class="field-half" />
|
||||
</ui:VisualElement>
|
||||
<ui:Label name="selftest-note" class="field-note"
|
||||
text="自检:用不依赖贴图与光照的内置纯色 shader 按同一套矩阵画一次,用来分清是渲染管线的问题还是被测 shader 本身的问题" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
<ui:Label name="selftest-note" class="field-note" text="自检" />
|
||||
</ui:Foldout>
|
||||
|
||||
<!-- 全局参数:离屏渲染没有相机流程,光照/环境这类引擎全局量要自己补 -->
|
||||
<ui:VisualElement name="sec-globals" class="section">
|
||||
<ui:Toggle name="sec-globals-head" label="全局参数(光照 / 环境)" value="false" class="section-head" />
|
||||
<ui:VisualElement name="sec-globals-body" class="section-body">
|
||||
<ui:Label name="globals-note" class="field-note"
|
||||
text="引擎在相机流程里才写入的全局量(光照方向、环境光、反射探针)这里默认缺失;勾选的条目在渲染时注入,渲染完立即还原" />
|
||||
<ui:Foldout name="sec-globals" text="全局参数(光照 / 环境)" value="false" class="section">
|
||||
<ui:Label name="globals-note" class="field-note" text="渲染时注入,渲染后还原" />
|
||||
<ui:VisualElement class="field-row">
|
||||
<ui:Button name="globals-detect" text="扫描 Shader" class="field-half" />
|
||||
<ui:Button name="globals-presets" text="加入常用预设" class="field-half" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="globals-rows" class="props-rows" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:Foldout>
|
||||
|
||||
<!-- 材质属性表:行来自 BakeShaderPropertyRow.uxml -->
|
||||
<ui:VisualElement name="sec-props" class="section">
|
||||
<ui:Toggle name="sec-props-head" label="材质属性" value="true" class="section-head" />
|
||||
<ui:VisualElement name="sec-props-body" class="section-body">
|
||||
<ui:Foldout name="sec-props" text="材质属性" value="true" class="section">
|
||||
<ui:VisualElement name="props-rows" class="props-rows" />
|
||||
<ui:Label name="props-note" class="field-note" text="未指定 shader" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
</ui:Foldout>
|
||||
|
||||
</ui:VisualElement>
|
||||
</ui:ScrollView>
|
||||
@@ -229,7 +213,7 @@
|
||||
|
||||
<!-- ── 底部状态栏 ── -->
|
||||
<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" />
|
||||
<ui:Label name="status-source" class="status-readout" text="-" />
|
||||
<ui:Label name="status-size" class="status-readout" text="-" />
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
// 测试视图:把"这一格面片在画面里到底占多大、铺了哪段 UV"变成一眼能读的颜色。
|
||||
// 三种图都只吃顶点 uv0,不吃贴图、不吃光照、不吃时间,所以画面为空或变形只有几何与 UV 两种原因。
|
||||
Shader "Hidden/XericUI/ShaderBake/Debug View"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Mode ("视图(0=UV 1=梯度 2=棋盘)", Float) = 0
|
||||
_LineThickness ("整数边界线宽", Range(1, 400)) = 90
|
||||
_UvTiling ("UV 重复次数", Vector) = (1, 1, 0, 0)
|
||||
_UvOffset ("UV 偏移", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "ForceSupported" = "True" }
|
||||
|
||||
// 剔除方向交给 Cull Off:这些视图要回答的是几何与 UV,
|
||||
// 不该再被正面约定影响一次,否则空画面时两条原因会搅在一起
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
Lighting Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
float _Mode;
|
||||
float _LineThickness;
|
||||
float4 _UvTiling;
|
||||
float4 _UvOffset;
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
fixed3 HueToRgb(float hue)
|
||||
{
|
||||
// 格编号可以是负的,先 floor 取小数保证 hue 落在 0~1,否则色相会随符号跳变
|
||||
hue = hue - floor(hue);
|
||||
float3 rgb = saturate(abs(hue * 6.0 + float3(0.0, 4.0, 2.0)) - 3.0);
|
||||
return rgb;
|
||||
}
|
||||
|
||||
// 每个整数格给一个稳定色相,相邻格不撞色,混在一起也能数出这是第几格
|
||||
fixed3 CellHue(float2 cell)
|
||||
{
|
||||
return HueToRgb(cell.x * 0.618033 + cell.y * 0.381966);
|
||||
}
|
||||
|
||||
// 按<b>绝对 UV</b> 压暗整数边界:重复次数大于 1 时格中间也会有一条,
|
||||
// 这样"这一格跨了几个 UV 单位"数得出来,而不是被静悄悄地截断
|
||||
float EdgeMask(float2 uv)
|
||||
{
|
||||
// 变量别叫 line:HLSL 把它当保留字,fxc 直接报"unexpected token 'line'"
|
||||
float2 toInt = abs(frac(uv + 0.5) - 0.5);
|
||||
float edge = min(toInt.x, toInt.y);
|
||||
return lerp(0.3, 1.0, saturate(edge * _LineThickness));
|
||||
}
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.uv0;
|
||||
return o;
|
||||
}
|
||||
|
||||
// UV 视图:红 = U,绿 = V。角点即 UV,一格四角该是 黑(0,0) 红(1,0) 绿(0,1) 黄(1,1)。
|
||||
// (0,0) 必须是纯黑——掺了每格色相就分不出哪一头是原点
|
||||
fixed4 UvView(float2 f, float2 uv)
|
||||
{
|
||||
fixed3 col = fixed3(f.x, f.y, 0.0);
|
||||
return fixed4(col * EdgeMask(uv), 1.0);
|
||||
}
|
||||
|
||||
// 梯度视图:两条灰度尺。主体沿 U 由黑到白,顶部窄带沿 V 由黑到白,
|
||||
// 每 0.1 一档压暗。量的是一格铺满之后刻度在画面上跨了多少像素——
|
||||
// 尺子只占画面中间一小段,就说明相机框的是整个网格而不是这一格
|
||||
fixed4 GradientView(float2 f, float2 uv)
|
||||
{
|
||||
float ruler = lerp(f.x, f.y, step(0.86, f.y));
|
||||
float tenth = frac(ruler * 10.0);
|
||||
float tick = min(tenth, 1.0 - tenth);
|
||||
float gray = ruler * lerp(0.35, 1.0, saturate(tick * 40.0));
|
||||
gray *= EdgeMask(uv);
|
||||
return fixed4(gray, gray, gray, 1.0);
|
||||
}
|
||||
|
||||
// 棋盘视图:半 UV 一格的棋盘 + 每格一个色相 + 左下角红、右上角蓝。
|
||||
// 方块变矩形=横竖缩放不等,变平行四边形=斜切或透视,两角换位置=U 或 V 被镜像
|
||||
fixed4 CheckerView(float2 cell, float2 f, float2 uv)
|
||||
{
|
||||
float2 q = floor(f * 2.0);
|
||||
float check = fmod(q.x + q.y, 2.0);
|
||||
fixed3 col = CellHue(cell) * (0.2 + 0.8 * check);
|
||||
|
||||
// 角标放在格内靠边的一小块,压过棋盘本身
|
||||
float bottomLeft = max(f.x, f.y);
|
||||
float topRight = max(1.0 - f.x, 1.0 - f.y);
|
||||
col = lerp(col, fixed3(1.0, 0.16, 0.16), saturate((0.15 - bottomLeft) * 30.0));
|
||||
col = lerp(col, fixed3(0.16, 0.4, 1.0), saturate((0.15 - topRight) * 30.0));
|
||||
return fixed4(col * EdgeMask(uv), 1.0);
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
// 先把 UV 换算成"每格 0~1":重复次数不为 1 时直接 frac(uv) 会在每个整数处重置,
|
||||
// 一格明明跨 0~2 却显示成两段;除以重复次数才是一条连续递增的尺子
|
||||
float2 local = (i.uv - _UvOffset.xy) / max(_UvTiling.xy, 0.0001);
|
||||
float2 cell = floor(local);
|
||||
float2 f = local - cell;
|
||||
|
||||
if (_Mode < 0.5)
|
||||
return UvView(f, i.uv);
|
||||
if (_Mode < 1.5)
|
||||
return GradientView(f, i.uv);
|
||||
return CheckerView(cell, f, i.uv);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback Off
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b69a9a69ca9a6930caa8808a0c91f009
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericUI.ShaderBake.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 用一张"覆盖材质"按<b>同一套</b>面片 / 相机再渲一次的探针。
|
||||
///
|
||||
/// <para>两处用得上,问的是同一个问题的两面:</para>
|
||||
/// <list type="bullet">
|
||||
/// <item><description>管线自检 —— 内置纯色 shader,回答"画不出来该怪管线还是怪被测 shader"</description></item>
|
||||
/// <item><description>测试视图 —— UV / 梯度 / 棋盘,回答"这一格占画面多大、铺了哪段 UV"</description></item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para><b>settings 是共享引用,不是副本</b>:探针必须和被测对象同参数,否则比较没有意义。
|
||||
/// 材质<b>不归这里所有</b>,由调用方建、由调用方销毁——测试视图那张要设 _Mode,会反复用。</para>
|
||||
///
|
||||
/// <para>探针是<b>常驻</b>的:RT 与网格按签名缓存,持续刷新(实时预览开着时每秒几十次)如果
|
||||
/// 每次都重建一遍探针,卡顿就来自这里。</para>
|
||||
/// </summary>
|
||||
internal sealed class ShaderBakeOverrideRenderer
|
||||
{
|
||||
private ShaderBakeRenderer m_Probe;
|
||||
|
||||
/// <summary>
|
||||
/// 探针自己那份网格。参数是共享的,所以顶点数与真实渲染一致——但真实渲染那次未必已经建过网格,
|
||||
/// 测试视图的读数得能从探针这边拿到,否则状态栏的顶点数会空着。
|
||||
/// </summary>
|
||||
public Mesh geometry
|
||||
{
|
||||
get { return m_Probe != null ? m_Probe.geometry : null; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用给定材质按同一套参数重画一次。失败返回 null 并把原因写进 <paramref name="error"/>。
|
||||
/// </summary>
|
||||
public RenderTexture RenderWithMaterial(ShaderBakeSettings settings, Material material, out string error)
|
||||
{
|
||||
error = string.Empty;
|
||||
if (settings == null || material == null)
|
||||
{
|
||||
error = material == null ? "探针材质还没建起来" : "没有参数可渲";
|
||||
return null;
|
||||
}
|
||||
|
||||
if (m_Probe == null)
|
||||
m_Probe = new ShaderBakeRenderer { settings = settings };
|
||||
m_Probe.material = material;
|
||||
|
||||
// 探针 shader 只有一个 pass,用户填的 pass 下标是给被测 shader 的,照抄过来只会画成空画面,
|
||||
// 于是"pass 选错"被误诊成"管线坏了"。这里只借 settings 用一次,出来就还原。
|
||||
int subjectPass = settings.output.shaderPass;
|
||||
settings.output.shaderPass = 0;
|
||||
RenderTexture rt;
|
||||
try
|
||||
{
|
||||
rt = m_Probe.Render();
|
||||
if (rt == null)
|
||||
error = m_Probe.lastError;
|
||||
}
|
||||
finally
|
||||
{
|
||||
settings.output.shaderPass = subjectPass;
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
/// <summary> 收掉探针,连带它那张 RT 与网格。关窗口时调用 </summary>
|
||||
public void Release()
|
||||
{
|
||||
if (m_Probe == null)
|
||||
return;
|
||||
// 探针自己回收那张 RT,所以只走它一条路,别两边各销毁一次
|
||||
m_Probe.Dispose(true);
|
||||
m_Probe = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c4b2f19ae0d48f5b3c16d9e0a4f2b57
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
@@ -22,6 +23,14 @@ namespace XericUI.ShaderBake.Editor
|
||||
private readonly Label m_Readout;
|
||||
private readonly VisualElement m_FaceOverlay;
|
||||
private readonly Label m_FaceOverlayLabel;
|
||||
private readonly VisualElement m_GridOverlay;
|
||||
|
||||
// 分格层:线的条数只随行列数变,编号只随格子数变,所以按数量复用,不每帧重建
|
||||
private readonly List<VisualElement> m_GridVerticals = new List<VisualElement>();
|
||||
private readonly List<VisualElement> m_GridHorizontals = new List<VisualElement>();
|
||||
private readonly List<Label> m_GridLabels = new List<Label>();
|
||||
private int m_GridColumns = -1;
|
||||
private int m_GridRows = -1;
|
||||
|
||||
/// <summary> 在图上点了一下(不是拖拽)。参数是 0~1、左上为原点的坐标 </summary>
|
||||
public event Action<Vector2> faceClicked;
|
||||
@@ -30,6 +39,10 @@ namespace XericUI.ShaderBake.Editor
|
||||
private int m_CheckerWidth;
|
||||
private int m_CheckerHeight;
|
||||
private bool m_CheckerVisible;
|
||||
/// <summary> 上一次挂上去的那张图;引用没变就只重画,不重设样式 </summary>
|
||||
private Texture m_Content;
|
||||
private int m_AppliedWidth = -1;
|
||||
private int m_AppliedHeight = -1;
|
||||
private Vector2Int m_PixelSize = Vector2Int.zero;
|
||||
private float m_Zoom = 1f;
|
||||
private bool m_AutoFit = true;
|
||||
@@ -38,10 +51,6 @@ namespace XericUI.ShaderBake.Editor
|
||||
private Vector2 m_DragStart;
|
||||
private Vector2 m_ScrollStart;
|
||||
|
||||
/// <summary> 上一次渲染的不透明像素占比,-1 = 还没测过 </summary>
|
||||
private float m_CoverageRatio = -1f;
|
||||
private Color m_CoverageColor = Color.clear;
|
||||
|
||||
/// <summary> 当前缩放倍率(1 = 一个像素对应屏幕一个点) </summary>
|
||||
public float zoom { get { return m_Zoom; } }
|
||||
|
||||
@@ -60,6 +69,9 @@ namespace XericUI.ShaderBake.Editor
|
||||
m_FaceOverlayLabel = root.Q<Label>("face-overlay-label");
|
||||
if (m_FaceOverlay != null)
|
||||
m_FaceOverlay.pickingMode = PickingMode.Ignore;
|
||||
m_GridOverlay = root.Q<VisualElement>("grid-overlay");
|
||||
if (m_GridOverlay != null)
|
||||
m_GridOverlay.pickingMode = PickingMode.Ignore;
|
||||
|
||||
if (m_Viewport == null || m_Frame == null || m_Image == null)
|
||||
throw new InvalidOperationException("BakeShaderWindow.uxml 缺少预览区节点");
|
||||
@@ -74,11 +86,22 @@ namespace XericUI.ShaderBake.Editor
|
||||
/// <summary> 挂上这次渲染的结果。传 null 表示"没有结果",只清读数。 </summary>
|
||||
public void SetResult(Texture content, Vector2Int pixelSize)
|
||||
{
|
||||
// 实时预览每秒重画几十次,但画进的是同一张 RT:内容每帧都在变,背景引用没变。
|
||||
// 这时只要一次重画,不必再走一遍样式解析 + 重新适配尺寸 + 重写读数
|
||||
bool sameContent = ReferenceEquals(content, m_Content) && pixelSize == m_PixelSize;
|
||||
m_Content = content;
|
||||
m_PixelSize = pixelSize;
|
||||
if (sameContent)
|
||||
{
|
||||
m_Image.MarkDirtyRepaint();
|
||||
return;
|
||||
}
|
||||
|
||||
m_Image.style.backgroundImage = ToBackground(content);
|
||||
if (m_AutoFit)
|
||||
FitToView();
|
||||
ApplySize();
|
||||
else
|
||||
ApplySize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -103,7 +126,11 @@ namespace XericUI.ShaderBake.Editor
|
||||
return;
|
||||
m_Checker.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
if (visible)
|
||||
{
|
||||
// 尺寸没变时 ApplySize 会跳过写样式,这里要强制走一遍,否则棋盘纹理不会被建出来
|
||||
m_AppliedWidth = m_AppliedHeight = -1;
|
||||
ApplySize();
|
||||
}
|
||||
}
|
||||
|
||||
public void ZoomIn() { SetZoom(m_Zoom * 1.25f); }
|
||||
@@ -138,24 +165,149 @@ namespace XericUI.ShaderBake.Editor
|
||||
m_FaceOverlay.style.width = Length.Percent(Mathf.Max(max.x - min.x, 0.002f) * 100f);
|
||||
m_FaceOverlay.style.height = Length.Percent(Mathf.Max(max.y - min.y, 0.002f) * 100f);
|
||||
if (m_FaceOverlayLabel != null)
|
||||
{
|
||||
// 分了格的时候每格都有自己的编号标签,选中框只留框,免得同一格里两行字叠着
|
||||
m_FaceOverlayLabel.style.display = string.IsNullOrEmpty(label) ? DisplayStyle.None : DisplayStyle.Flex;
|
||||
m_FaceOverlayLabel.text = label;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> 一格在预览图里的位置(0~1,左上为原点)和它该显示的 UV 编号 </summary>
|
||||
public struct FaceCellRect
|
||||
{
|
||||
public Vector2 min;
|
||||
public Vector2 max;
|
||||
public string label;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 报告这次结果里有多少像素不是全透明。看图时最先要确认的就是"到底画没画出来",
|
||||
/// 而棋盘格背景会让"没画"和"画了个透明的"看起来完全一样。
|
||||
/// 画分格线和每格的 UV 编号,回答"这条线右边/下边那一片是 UV 几"。
|
||||
///
|
||||
/// <para>只有一格时不画:这时右侧面片区已经写着 UV,再叠一层只会挡画面。
|
||||
/// 位置全用百分比,所以缩放、拖动滚动条都不用重算。</para>
|
||||
/// </summary>
|
||||
public void SetCoverage(float opaqueRatio, Color averageColor)
|
||||
public void SetFaceGrid(IList<FaceCellRect> cells, int columns, int rows)
|
||||
{
|
||||
m_CoverageRatio = opaqueRatio;
|
||||
m_CoverageColor = averageColor;
|
||||
UpdateReadout();
|
||||
if (m_GridOverlay == null)
|
||||
return;
|
||||
if (cells == null || cells.Count < 2)
|
||||
{
|
||||
m_GridOverlay.style.display = DisplayStyle.None;
|
||||
return;
|
||||
}
|
||||
|
||||
m_GridOverlay.style.display = DisplayStyle.Flex;
|
||||
EnsureGridLines(columns, rows);
|
||||
|
||||
float left = float.MaxValue, top = float.MaxValue;
|
||||
float right = float.MinValue, bottom = float.MinValue;
|
||||
for (int i = 0; i < cells.Count; i++)
|
||||
{
|
||||
left = Mathf.Min(left, cells[i].min.x);
|
||||
top = Mathf.Min(top, cells[i].min.y);
|
||||
right = Mathf.Max(right, cells[i].max.x);
|
||||
bottom = Mathf.Max(bottom, cells[i].max.y);
|
||||
}
|
||||
left = Mathf.Clamp01(left);
|
||||
top = Mathf.Clamp01(top);
|
||||
right = Mathf.Clamp01(right);
|
||||
bottom = Mathf.Clamp01(bottom);
|
||||
|
||||
// 线按整个网格的范围等分。格是投影后的四边形,这里用的是它的视口包围盒,
|
||||
// 正交正视时两者完全重合;斜看时线会略微跑到格边外,但仍然对得上编号
|
||||
for (int i = 0; i < m_GridVerticals.Count; i++)
|
||||
{
|
||||
VisualElement line = m_GridVerticals[i];
|
||||
line.style.left = Length.Percent(Mathf.Lerp(left, right, (float)i / Mathf.Max(columns, 1)) * 100f);
|
||||
line.style.top = Length.Percent(top * 100f);
|
||||
line.style.width = 1f;
|
||||
line.style.height = Length.Percent((bottom - top) * 100f);
|
||||
}
|
||||
for (int j = 0; j < m_GridHorizontals.Count; j++)
|
||||
{
|
||||
VisualElement line = m_GridHorizontals[j];
|
||||
line.style.left = Length.Percent(left * 100f);
|
||||
line.style.top = Length.Percent(Mathf.Lerp(top, bottom, (float)j / Mathf.Max(rows, 1)) * 100f);
|
||||
line.style.width = Length.Percent((right - left) * 100f);
|
||||
line.style.height = 1f;
|
||||
}
|
||||
|
||||
EnsureGridLabels(cells.Count);
|
||||
// 一格在屏幕上还不到一个编号宽/高时,编号只会互相压着,索性不画。
|
||||
// 布局还没算出来(宽度为 0)时不拦,等下一次重画再按真实尺寸决定
|
||||
float frameWidth = m_Frame != null ? m_Frame.resolvedStyle.width : 0f;
|
||||
float frameHeight = m_Frame != null ? m_Frame.resolvedStyle.height : 0f;
|
||||
bool canMeasure = frameWidth > 1f && frameHeight > 1f;
|
||||
for (int i = 0; i < m_GridLabels.Count; i++)
|
||||
{
|
||||
Label label = m_GridLabels[i];
|
||||
bool used = i < cells.Count;
|
||||
if (used && canMeasure)
|
||||
{
|
||||
float cellWidth = (cells[i].max.x - cells[i].min.x) * frameWidth;
|
||||
float cellHeight = (cells[i].max.y - cells[i].min.y) * frameHeight;
|
||||
used = cellWidth >= 36f && cellHeight >= 16f;
|
||||
}
|
||||
label.style.display = used ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
if (!used)
|
||||
continue;
|
||||
label.text = cells[i].label;
|
||||
label.style.left = Length.Percent(Mathf.Clamp01(cells[i].min.x) * 100f);
|
||||
label.style.top = Length.Percent(Mathf.Clamp01(cells[i].min.y) * 100f);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureGridLines(int columns, int rows)
|
||||
{
|
||||
if (m_GridColumns == columns && m_GridRows == rows)
|
||||
return;
|
||||
m_GridColumns = columns;
|
||||
m_GridRows = rows;
|
||||
|
||||
for (int i = 0; i < m_GridVerticals.Count; i++)
|
||||
m_GridVerticals[i].RemoveFromHierarchy();
|
||||
for (int i = 0; i < m_GridHorizontals.Count; i++)
|
||||
m_GridHorizontals[i].RemoveFromHierarchy();
|
||||
m_GridVerticals.Clear();
|
||||
m_GridHorizontals.Clear();
|
||||
|
||||
// 列数 + 1 条竖线、行数 + 1 条横线:把外框也算进去,否则最外一圈没有边
|
||||
for (int i = 0; i <= columns; i++)
|
||||
m_GridVerticals.Add(CreateGridLine());
|
||||
for (int j = 0; j <= rows; j++)
|
||||
m_GridHorizontals.Add(CreateGridLine());
|
||||
|
||||
// 新加的线在最后,会把已有的编号压住;改完行列数把编号重新提到最上层
|
||||
for (int i = 0; i < m_GridLabels.Count; i++)
|
||||
m_GridLabels[i].BringToFront();
|
||||
}
|
||||
|
||||
private VisualElement CreateGridLine()
|
||||
{
|
||||
var line = new VisualElement { pickingMode = PickingMode.Ignore };
|
||||
line.AddToClassList("grid-line");
|
||||
m_GridOverlay.Add(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
private void EnsureGridLabels(int count)
|
||||
{
|
||||
while (m_GridLabels.Count < count)
|
||||
{
|
||||
var label = new Label { pickingMode = PickingMode.Ignore };
|
||||
label.AddToClassList("grid-cell-label");
|
||||
// 后加的在上面:编号要压在线之上,不能被 1px 的线切过
|
||||
m_GridOverlay.Add(label);
|
||||
m_GridLabels.Add(label);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_PixelSize = Vector2Int.zero;
|
||||
m_CoverageRatio = -1f;
|
||||
// 清掉记录,下一次 SetResult 才会真的重设背景,而不是当"同一张图"直接重画
|
||||
m_Content = null;
|
||||
m_AppliedWidth = m_AppliedHeight = -1;
|
||||
m_Image.style.backgroundImage = new StyleBackground(StyleKeyword.None);
|
||||
UpdateReadout();
|
||||
}
|
||||
@@ -181,15 +333,22 @@ namespace XericUI.ShaderBake.Editor
|
||||
{
|
||||
m_Frame.style.width = 0f;
|
||||
m_Frame.style.height = 0f;
|
||||
m_AppliedWidth = m_AppliedHeight = -1;
|
||||
UpdateReadout();
|
||||
return;
|
||||
}
|
||||
int width = Mathf.Max(1, Mathf.RoundToInt(m_PixelSize.x * m_Zoom));
|
||||
int height = Mathf.Max(1, Mathf.RoundToInt(m_PixelSize.y * m_Zoom));
|
||||
m_Frame.style.width = width;
|
||||
m_Frame.style.height = height;
|
||||
if (m_CheckerVisible)
|
||||
EnsureChecker(width, height);
|
||||
// 尺寸没变就别再写一遍:写样式会让整个预览做一次布局,心跳时这是白花的
|
||||
if (width != m_AppliedWidth || height != m_AppliedHeight)
|
||||
{
|
||||
m_AppliedWidth = width;
|
||||
m_AppliedHeight = height;
|
||||
m_Frame.style.width = width;
|
||||
m_Frame.style.height = height;
|
||||
if (m_CheckerVisible)
|
||||
EnsureChecker(width, height);
|
||||
}
|
||||
UpdateReadout();
|
||||
}
|
||||
|
||||
@@ -202,22 +361,11 @@ namespace XericUI.ShaderBake.Editor
|
||||
m_Readout.text = "无结果";
|
||||
return;
|
||||
}
|
||||
m_Readout.text = m_PixelSize.x + " × " + m_PixelSize.y + " px " +
|
||||
(m_Zoom * 100f).ToString("0.#") + "%" + CoverageText();
|
||||
// 全透明是"这次什么都没画出来"的信号,值得比别的读数更抢眼一点
|
||||
m_Readout.style.color = new StyleColor(m_PixelSize.x > 0 && m_CoverageRatio <= 0.001f
|
||||
? new Color(0.98f, 0.51f, 0.41f)
|
||||
: new Color(0.86f, 0.86f, 0.86f));
|
||||
}
|
||||
|
||||
/// <summary> 覆盖率后缀;没测过就不占字数 </summary>
|
||||
private string CoverageText()
|
||||
{
|
||||
if (m_CoverageRatio < 0f)
|
||||
return string.Empty;
|
||||
if (m_CoverageRatio <= 0.001f)
|
||||
return " 全透明(没画出像素)";
|
||||
return " 不透明 " + Mathf.RoundToInt(m_CoverageRatio * 100f) + "%";
|
||||
string text = m_PixelSize.x + " × " + m_PixelSize.y + " px " +
|
||||
(m_Zoom * 100f).ToString("0.#") + "%";
|
||||
// 文字没变就不写:Label 换文字要重新排版,心跳时这个字符串通常是一样的
|
||||
if (m_Readout.text != text)
|
||||
m_Readout.text = text;
|
||||
}
|
||||
|
||||
private void OnViewportGeometry(GeometryChangedEvent evt)
|
||||
|
||||
@@ -126,6 +126,7 @@ namespace XericUI.ShaderBake.Editor
|
||||
try
|
||||
{
|
||||
FillFromMaterial(row);
|
||||
Reapply(row);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -134,6 +135,53 @@ namespace XericUI.ShaderBake.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把值原样再写一遍材质。
|
||||
///
|
||||
/// <para>值本身没变,但"写一次"和"只是存在材质里"对显卡不是一回事:
|
||||
/// 刚换过 shader(或 shader 刚重新编译完)时,材质里记的值和 GPU 上的绑定可能对不上,
|
||||
/// 表现就是界面上明明写着 1,shader 里却是 0,非要手动改一下参数才生效。</para>
|
||||
///
|
||||
/// <para>勾选类属性(<c>[Toggle]</c>/<c>[KeywordEnum]</c>)还要顺手同步关键字——
|
||||
/// 关键字没开的时候,shader 里那段分支根本不会走,同样表现为"没反应"。</para>
|
||||
/// </summary>
|
||||
private void Reapply(Row row)
|
||||
{
|
||||
if (m_Material == null || !m_Material.HasProperty(row.propName))
|
||||
return;
|
||||
|
||||
switch (row.propType)
|
||||
{
|
||||
case ShaderPropertyType.Color:
|
||||
m_Material.SetColor(row.propName, m_Material.GetColor(row.propName));
|
||||
break;
|
||||
case ShaderPropertyType.Vector:
|
||||
m_Material.SetVector(row.propName, m_Material.GetVector(row.propName));
|
||||
break;
|
||||
case ShaderPropertyType.Texture:
|
||||
m_Material.SetTexture(row.propName, m_Material.GetTexture(row.propName));
|
||||
break;
|
||||
case ShaderPropertyType.Int:
|
||||
int intValue = m_Material.GetInt(row.propName);
|
||||
m_Material.SetInt(row.propName, intValue);
|
||||
SyncKeyword(row, intValue != 0);
|
||||
break;
|
||||
default:
|
||||
float value = m_Material.GetFloat(row.propName);
|
||||
m_Material.SetFloat(row.propName, value);
|
||||
SyncKeyword(row, !Mathf.Approximately(value, 0f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncKeyword(Row row, bool on)
|
||||
{
|
||||
if (row.keyword == null)
|
||||
return;
|
||||
if (on) m_Material.EnableKeyword(row.keyword);
|
||||
else m_Material.DisableKeyword(row.keyword);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
m_Rows.Clear();
|
||||
@@ -241,8 +289,10 @@ namespace XericUI.ShaderBake.Editor
|
||||
switch (type)
|
||||
{
|
||||
case ShaderPropertyType.Range:
|
||||
row.rangeMin = ShaderUtil.GetRangeLimits(shader, propIndex, 0);
|
||||
row.rangeMax = ShaderUtil.GetRangeLimits(shader, propIndex, 1);
|
||||
// 0/1/2 依次是 默认值 / 最小值 / 最大值——按 0、1 当最小、最大取,
|
||||
// 滑块区间会变成 0..默认值,手柄永远停在右端,和右边的数值对不上
|
||||
row.rangeMin = ShaderUtil.GetRangeLimits(shader, propIndex, 1);
|
||||
row.rangeMax = ShaderUtil.GetRangeLimits(shader, propIndex, 2);
|
||||
Show(row.rangeGroup);
|
||||
WireSlider(row);
|
||||
WireRangeValue(row);
|
||||
|
||||
Reference in New Issue
Block a user