unity udim
The Unity Labs team is experimenting with bringing film-quality assets, designed for maximum fidelity but non-realtime rendering, into the 60+ FPS world with Unity. Since film and TV formats and pipelines (such as Ptex, USD & UDIM) are not widely supported in realtime engines, working with these assets requires new techniques and tools. Beyond the obvious issues with the size and density of these assets, there can often be a large number of materials and texture files involved with a single asset (such as the case with UDIM), which we’ll need to easily interact with and modify. To streamline this workflow, we’ve created a new Multi-material Editor to help manage and interact with all these materials.
Unity Labs团队正在尝试将具有电影品质的资产(旨在实现最大保真度但非实时渲染)引入Unity 60+ FPS世界。 由于实时引擎未广泛支持电影和电视格式以及管道(例如Ptex,USD和UDIM),因此使用这些资产需要新的技术和工具。 除了这些资产的大小和密度的明显问题之外,单个资产通常还涉及大量的材质和纹理文件(例如UDIM),我们需要轻松地与之交互和修改。 为了简化此工作流程,我们创建了一个新的“多材料编辑器”以帮助管理所有这些材料并与之交互。
UDIM and other multi-tiled UV mapping techniques are not a new file type, but a pipeline for UVing and a set of conventions for naming source texture files. These multi-tiled UV mapping techniques can increase the number of materials beyond what is reasonable to simultaneously edit and keep in sync with the current material inspector, and multi-selecting materials every time is not very practical.
UDIM和其他多平铺UV贴图技术不是新的文件类型,而是用于UVing的管道和用于命名源纹理文件的一组约定。 这些多平铺UV贴图技术可以增加材料的数量,使其超出合理范围,无法同时编辑并与当前的材料检查器保持同步,并且每次都多次选择材料不是很实际。
In the Multi-material Editor, we assume that the individual tiles have their own material assignment from the source asset, which is the most common pipeline. If that’s not the case in your pipeline, you could use a custom mesh importer to break the mesh up into individual submeshes with corresponding materials at asset import time.
在“多材质编辑器”中,我们假设各个图块都具有来自源资产的材料分配,这是最常见的管道。 如果管道中不是这种情况,则可以使用自定义网格导入器在资产导入时将网格划分为带有相应材质的单个子网格。
入门 (Getting Started)
Download the Multi-material Editor. To install, simply create a project in Unity 5.5 or newer. Then add this repo in the assets folder of your project. There are 2 new scriptable object types that can be accessed by right clicking in the project view in the Create menu.
下载多材料编辑器。 要安装,只需在Unity 5.5或更高版本中创建一个项目。 然后将此回购添加到项目的资产文件夹中。 可以通过在“创建”菜单中的项目视图中右键单击来访问2种新的可编写脚本的对象类型。
Material Texture Settings is under Create > Multi Material > Material Texture Settings and can be used to assign textures to UDIM materials. The custom inspector is able to apply the texture setting to selected materials and assumes the material and texture are named according to UDIM conventions. Texture Name is the material property name of the texture field and Search Dir is the directory that contains the textures for that material property. Multi Material Data is under Create > Multi Material > Multi Material Data and holds an array of Materials for use in Multi Material Component or you can directly modify the materials from the scriptable object’s inspector. The Multi-material Component can be added to a game object to control the Shared Materials array in the object’s renderer. If a Multi Material Data is created from the render, or assigned from the project, that data can be modified here. This can be useful if you have multiple objects that share a group of materials that need to be modified at once.
“材质纹理设置”位于“创建”>“多种材质”>“材质纹理设置”下,可用于将纹理分配给UDIM材质。 定制检查器能够将纹理设置应用于选定的材质,并假定根据UDIM约定对材质和纹理进行命名。 “纹理名称”是纹理字段的材料属性名称,“搜索目录”是包含该材料属性的纹理的目录。 “多材料数据”位于“创建”>“多材料”>“多材料数据”下,并包含用于“多材料组件”的一系列材料,或者您可以直接从可编写脚本的对象的检查器中修改材料。 可以将多材质组件添加到游戏对象,以控制对象渲染器中的“共享材质”数组。 如果从渲染创建或从项目分配了“多种材质数据”,则可以在此处修改该数据。 如果您有多个对象共享一组需要立即修改的材料,这将很有用。
关于工具 (About the Tool)
We need the tool to allow us to interact with multiple materials on an object or across objects as if they were only one material, except for the case of texture assignment. To allow the most options, we split the material data out into its own class so it could be created and serialized on a component based on the object’s renderer, or saved as an asset in a scriptable object, to be shared across multiple objects. We then built a custom inspector for viewing all the materials within this single custom inspector using a separate custom drawer class. This uses the standard material inspector, but also supports any custom material inspectors you may be using.
我们需要该工具来允许我们与一个对象或多个对象上的多种材质进行交互,就好像它们只是一种材质一样(纹理分配的情况除外)。 为了提供最多的选择,我们将材料数据分成自己的类,以便可以在基于对象渲染器的组件上创建和序列化材料数据,或者将其另存为可编写脚本对象中的资产,以在多个对象之间共享。 然后,我们构建了一个定制检查器,以使用单独的定制抽屉类查看该单个定制检查器中的所有材料。 这使用标准的材料检查器,但也支持您可能使用的任何自定义材料检查器。
Materials, and the Unity Standard Shader in particular, use custom UI with logic built into the inspector, so we are unable to just use the standard Property Drawers for a material’s serialized properties. This means that to interact with a material in a meaningful way we need to use the Material Editor Inspector within our custom inspector. It is possible to insert the drawing of an editor (with its public GUI methods) inside of another editor or EditorWindow if we create and manage that inserted editor. In the Multi-material Editor, the MaterialArrayDrawers class lets us do just that with the Material Editor as seen in the MultiMaterialEditor and MultiMaterialDataEditor. The coding pattern used for this editor can also be used in other cases where you want to draw an inspector within another editor, which can be useful if you want to draw a custom inspector for a Scriptable Object directly in a component that uses that object.
材质(尤其是Unity Standard Shader)使用自定义UI,并将其内置到检查器中,因此我们不能仅将标准的“ 属性抽屉”用于材质的序列化属性。 这意味着要以有意义的方式与物料交互,我们需要在自定义检查器中使用“物料编辑器”检查器。 如果我们创建和管理插入的编辑器,则可以将一个编辑器的图形(及其公共GUI方法)插入另一个编辑器或EditorWindow中。 在Multi-material Editor中,MaterialArrayDrawers类使我们能够使用在MultiMaterialEditor和MultiMaterialDataEditor中看到的Material Editor来做到这一点。 在要在另一个编辑器中绘制检查器的其他情况下,也可以使用此编辑器使用的编码模式,如果要在使用该对象的组件中直接为可编写脚本的对象绘制自定义检查器,此方法很有用。
There are some important things to keep in mind both for performance and interaction limitations in the Material Editor when trying to draw it inside another editor’s OnInspectorGUI. First, the header GUI can change the layout and rect context you set in the inspector. Also if the header contains any controls (for example, the shader menu), you cannot detect changes in that control with BeginChangeCheck and EndChangeCheck. This means we are not able to sync the changes on the shader selection when they happen. To keep the shaders in sync, we recreate the material header as close as possible with DrawMaterialHeaderMaterialView(). Note the isVisibleField where we have to reflect into the material editor to show the body of the editor, and ShaderPopup, where we try to replicate internal editor drawing styles but are not able to display the Unity internal shaders unless they are already loaded.
尝试在另一个编辑器的OnInspectorGUI内绘制材质编辑器时,需要牢记性能和交互限制方面的一些重要事项。 首先,标题GUI可以更改您在检查器中设置的布局和矩形上下文。 同样,如果标题包含任何控件(例如,着色器菜单),则无法使用BeginChangeCheck和EndChangeCheck来检测该控件中的更改。 这意味着当着色器选择发生更改时,我们将无法对其进行同步。 为了使着色器保持同步,我们使用DrawMaterialHeaderMaterialView()尽可能近地重新创建材质头。 请注意isVisibleField和ShaderPopup,我们必须在其中反映材质编辑器以显示编辑器的主体,在ShaderPopup中,我们尝试复制内部编辑器图形样式,但除非已加载,否则无法显示Unity内部着色器。
Second, since we are drawing the whole Material Editor’s OnInspectorGUI(), we do not know what property drawer has changed, just that something in the OnInspectorGUI() block changed. This means there are potential changes anywhere in the material that could need to be synced to the other materials. If we continuously sync all the properties of even a small array of materials with an interactive control like a color picker, we can significantly impact performance.
其次,由于我们正在绘制整个材质编辑器的OnInspectorGUI(),因此我们不知道什么属性抽屉已更改,仅是OnInspectorGUI()块中的某些内容已更改。 这意味着材料中任何地方都有可能需要与其他材料同步的潜在更改。 如果我们使用诸如拾色器之类的交互式控件连续地同步甚至一小部分材料的所有属性,我们都将极大地影响性能。
Therefore for best performance when syncing materials, we need a way to only change the properties that have been modified. We do a quick compare between the actively modified material and the first different material in our Multi-material, and only cache those serialized properties that are different—except textures—between the two materials. Then we only apply those cached changes to all of the other materials. Unfortunately, you can get some false positives if you have materials that are greatly different, or it can miss the change if it happens to match the compared material. As a workaround, we have added a Sync to Material button on the active material which copies all the properties across the Multi Material.
因此,为了在同步材料时获得最佳性能,我们需要一种仅更改已修改属性的方法。 我们在主动修改的材质和“多材质”中的第一个不同材质之间进行了快速比较,并且只缓存了这两种材质之间除纹理以外的序列化属性。 然后,我们仅将那些缓存的更改应用于所有其他材料。 不幸的是,如果您的材料差异很大,您可能会得到一些误报,或者,如果恰好与比较的材料匹配,它可能会错过更改。 解决方法是,我们在活动材质上添加了“同步到材质”按钮,该按钮可在“多种材质”中复制所有属性。
The Multi-material and its editors show how you can customize Unity’s UI for specific workflows you may want or need on your project. Some future areas to explore are building some more generic drawers to display multiple editors inside another component’s inspector, filtering Serialized Properties you want to sync (eg. not just ignoring textures), and handling animated materials and/or runtime-scripted interaction with the Multi-material.
多种材料及其编辑器显示了如何为项目中可能需要或需要的特定工作流自定义Unity的UI。 未来需要探索的领域是建立更多通用的抽屉,以在另一个组件的检查器中显示多个编辑器,过滤要同步的序列化属性(例如,不仅忽略纹理),并处理动画材料和/或与Multi结合的运行时脚本交互-材料。
unity udim