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

纹理Textures

纹理是不可变共享资源Textures are an immutable shared resource. 纹理可从 blob 存储加载并直接应用于模型,如教程:更改环境和材料所示。Textures can be loaded from blob storage and applied to models directly, as demonstrated in Tutorial: Changing the environment and materials. 不过,通常情况下,纹理会成为转换的模型的一部分,在该模型中,纹理由其材料引用。Most commonly, though, textures will be part of a converted model, where they are referenced by its materials.

纹理类型Texture types

不同的纹理类型具有不同的用例:Different texture types have different use cases:

  • “2D 纹理”主要用于材料2D Textures are mainly used in materials.
  • “立方体贴图”可用于天空Cubemaps can be used for the sky.

支持的纹理格式Supported texture formats

为 ARR 指定的所有纹理都必须采用 DDS 格式All textures given to ARR have to be in DDS format. 最好使用纹理图和纹理压缩。Preferably with mipmaps and texture compression.

加载纹理Loading textures

加载纹理时,必须指定其预期类型。When loading a texture, you have to specify its expected type. 如果类型不匹配,纹理加载将失败。If the type mismatches, the texture load fails. 加载具有相同 URI 的纹理两次将返回相同的纹理对象,因为它是共享的资源Loading a texture with the same URI twice will return the same texture object, as it is a shared resource.

与加载模型类似,有两种用于在源 blob 存储中为纹理资产寻址的变体:Similar to loading models, there are two variants of addressing a texture asset in source blob storage:

  • 如果 Blob 存储已链接到帐户,则可直接通过 Blob 存储参数对纹理进行寻址。The texture can be addressed by blob storage parameters directly, in case the blob storage is linked to the account. 在本例中,相关的加载函数为具有参数 LoadTextureOptionsLoadTextureAsyncRelevant loading function in this case is LoadTextureAsync with parameter LoadTextureOptions.
  • 纹理资产可以通过其 SAS URI 寻址。The texture asset can be addressed by its SAS URI. 相关的加载函数为具有参数 LoadTextureFromSasOptionsLoadTextureFromSasAsyncRelevant loading function is LoadTextureFromSasAsync with parameter LoadTextureFromSasOptions. 加载内置纹理时也使用此变体。Use this variant also when loading built-in textures.

下面的示例代码演示如何加载纹理:The following sample code shows how to load a texture:

async void LoadMyTexture(RenderingSession session, string storageContainer, string blobName, string assetPath)
{
    try
    {
        LoadTextureOptions options = new LoadTextureOptions(storageContainer, blobName, assetPath, TextureType.Texture2D);
        Texture texture = await session.Connection.LoadTextureAsync(options);
    
        // use texture...
    }
    catch (RRException ex)
    {
    }
}
void LoadMyTexture(ApiHandle<RenderingSession> session, std::string storageContainer, std::string blobName, std::string assetPath)
{
    LoadTextureOptions params;
    params.TextureType = TextureType::Texture2D;
    params.Blob.StorageAccountName = std::move(storageContainer);
    params.Blob.BlobContainerName = std::move(blobName);
    params.Blob.AssetPath = std::move(assetPath);
    session->Connection()->LoadTextureAsync(params, [](Status status, ApiHandle<Texture> texture)
    {
        // use texture...
    });
}

请注意,在使用其 SAS 变体时,仅加载函数/参数不同。Note that in case of using its SAS variant only the loading function/parameter differs.

纹理类型和内容可能存在限制,具体取决于要使用的纹理。Depending on what the texture is supposed to be used for, there may be restrictions for the texture type and content. 例如,PBR 材料的粗糙度图必须为灰度。For example, the roughness map of a PBR material must be grayscale.

API 文档API documentation

后续步骤Next steps