您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

材料Materials

材料是定义如何渲染网格共享资源Materials are shared resources that define how meshes are rendered. 材料用于指定要应用的纹理、是否使对象透明以及如何计算照明。Materials are used to specify which textures to apply, whether to make objects transparent and how lighting will be calculated.

材料在模型转换期间自动创建,可在运行时访问。Materials are automatically created during model conversion and are accessible at runtime. 还可以通过代码创建自定义材料并替换现有材料。You can also create custom materials from code and replace existing ones. 如果要跨许多网格共享相同资料,此方案特别有意义。This scenario makes especially sense if you want to share the same material across many meshes. 由于对材料的修改在每个引用它的网格上可见,因此此方法可用于轻松应用更改。Since modifications of a material are visible on every mesh that references it, this method can be used to easily apply changes.

备注

某些用例(例如突出显示已选取的对象)可以通过修改材料来完成,但通过 HierarchicalStateOverrideComponent 实现会轻松得多。Some use cases, such as highlighting a picked object can be done by modifying materials, but are much easier achieved through the HierarchicalStateOverrideComponent.

材料类型Material types

Azure 远程渲染具有两种不同的材料类型:Azure Remote Rendering has two distinct material types:

  • PBR 材料用于应尽可能在物理方面正确渲染的曲面。PBR materials are used for surfaces that should be rendered as physically correct, as possible. 使用基于物理方式的渲染 (PBR) 为这些材料计算现实照明。Realistic lighting is computed for these materials using physically based rendering (PBR). 若要充分利用此材料类型,必须提供高质量输入数据,如粗糙度和法线贴图。To get the most out of this material type, it is important to provide high-quality input data, such as roughness and normal maps.

  • 颜色材料用于不需要额外照明的情况。Color materials are used for cases where no additional lighting is desired. 这些材料始终全亮,更易于设置。These materials are always full bright and are easier to set up. 颜色材料用于根本不应有照明或是已合并静态照明的数据,例如通过 photogrammetry 获取的模型。Color materials are used for data that should either have no lighting at all, or already incorporates static lighting, such as models obtained through photogrammetry.

网格与MeshComponent 材料分配Mesh vs. MeshComponent material assignment

网格具有一个或多个子网格。Meshes have one or more submeshes. 每个子网格都引用一个材料。Each submesh references one material. 可以更改材料以在网格上直接使用,也可以在 MeshComponent 上替代要用于子网格的材料。You can change the material to use either directly on the mesh, or you can override which material to use for a submesh on a MeshComponent.

直接在网格资源上修改材料时,此更改会影响该网格的所有实例。When you modify a material directly on the mesh resource, this change affects all instances of that mesh. 但在 MeshComponent 上更改它只会影响这一个网格实例。Changing it on the MeshComponent, however, only affects that one mesh instance. 更合适的方法取决于所需行为,但修改 MeshComponent 是更常见的方法。Which method is more appropriate depends on the desired behavior, but modifying a MeshComponent is the more common approach.

材料重复数据删除Material de-duplication

在转换过程中,多个具有相同属性和纹理的材料会自动进行重复数据删除,转变为单个材料。During conversion multiple materials with the same properties and textures are automatically de-duplicated into a single material. 可以在转换设置中禁用此功能,但建议使它保持打开状态以获得最佳性能。You can disable this feature in the conversion settings, but we recommend leaving it on for best performance.

Material 类Material classes

API 提供的所有材料都派生自基类 MaterialAll materials provided by the API derive from the base class Material. 可以通过 Material.MaterialSubType 或直接强制转换来查询其类型:Their type can be queried through Material.MaterialSubType or by casting them directly:

void SetMaterialColorToGreen(Material material)
{
    if (material.MaterialSubType == MaterialType.Color)
    {
        ColorMaterial colorMaterial = material as ColorMaterial;
        colorMaterial.AlbedoColor = new Color4(0, 1, 0, 1);
        return;
    }

    PbrMaterial pbrMat = material as PbrMaterial;
    if (pbrMat != null)
    {
        pbrMat.AlbedoColor = new Color4(0, 1, 0, 1);
        return;
    }
}
void SetMaterialColorToGreen(ApiHandle<Material> material)
{
    if (material->GetMaterialSubType() == MaterialType::Color)
    {
        ApiHandle<ColorMaterial> colorMaterial = material.as<ColorMaterial>();
        colorMaterial->SetAlbedoColor({ 0, 1, 0, 1 });
        return;
    }

    if (material->GetMaterialSubType() == MaterialType::Pbr)
    {
        ApiHandle<PbrMaterial> pbrMat = material.as<PbrMaterial>();
        pbrMat->SetAlbedoColor({ 0, 1, 0, 1 });
        return;
    }
}

API 文档API documentation

后续步骤Next steps