CubeMapTexture QML Type

定义用于 3D 场景的立方体贴图纹理。更多

Import Statement: import QtQuick3D
Inherits:

Texture

详细说明

CubeMapTexture 是一种表示立方体贴图纹理的纹理。立方体贴图纹理有 6 个面(X+, X-, Y+, Y-, Z+, Z-),其中每个面都是独立的 2D 图像。CubeMapTexture 允许custom materialspost-processing effects 在着色器中使用立方体贴图纹理。立方体贴图还可用于定义场景环境的skybox

CustomMaterial {
    property TextureInput customTexture: TextureInput {
        texture: CubeMapTexture {
            source: "cubemap.ktx"
        }
    }
    fragmentShader: "shader.frag"
}

在这里,shader.frag 的实现可以假设customTexture 是采样器统一的 GLSL 类型 asamplerCube 。这意味着texture() GLSL 函数将vec3 作为该采样器的纹理坐标。如果我们使用Texture ,类型就会是sampler2D

void MAIN()
{
    vec4 c = texture(customTexture, NORMAL);
    BASE_COLOR = vec4(c.rgb, 1.0);
}

从带有立方体贴图的容器中获取纹理只会加载面 0 (X+),并生成 2D 纹理。而从同一资产中获取 CubeMapTexture 会加载所有 6 个面,并生成立方体贴图纹理。

CubeMapTexture 继承了 Texture 的所有属性。重要的区别在于source 必须指向包含立方体贴图的图像文件或图像文件列表。在实践中,单个文件指的是包含 6 张面孔图像的KTX容器。

从 6 张单独的图像中获取 CubeMapTexture 有两种不同的方法。一种是以 X+、X-、Y+、Y-、Z+、Z- 为顺序的分号分隔文件名列表:

CubeMapTexture {
    source: "maps/right.jpg;maps/left.jpg;maps/top.jpg;maps/bottom.jpg;maps/front.jpg;maps/back.jpg"
}

或包含"%p "占位符的字符串,其中"%p "将被 "posx"、"negx"、"posy"、"negy"、"posz "和 "negz "字符串替换,以生成六个文件名:

CubeMapTexture {
    source: "maps/sky_%p.png"
    // equivalent to:
    // source: "maps/sky_posx.png;maps/sky_negx.png;maps/sky_posy.png;maps/sky_negy.png;maps/sky_posz.png;maps/sky_negz.png"
}

注: CubeMapTexture 目前不支持通过sourceItemtextureData 等其他方式获取图像数据。

另请参见 Texture,CustomMaterial, 和Effect

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.