CubeMapTexture QML Type
定义用于3D场景的立方体贴图。更多...
| Import Statement: | import QtQuick3D |
| Inherits: |
详细描述
CubeMapTexture 是一种表示立方体贴图的 Texture 对象。 立方体贴图有 6 个面(X+、X-、Y+、Y-、Z+、Z-),每个面都是一张独立的 2D 图像。CubeMapTexture 允许在着色器中使用custom materials 和post-processing effects 处理立方体贴图。立方体贴图还可用于定义场景环境的skybox 。
CustomMaterial {
property TextureInput customTexture: TextureInput {
texture: CubeMapTexture {
source: "cubemap.ktx"
}
}
fragmentShader: "shader.frag"
}在此,假设customTexture 是一个采样器统一变量,其GLSL类型为samplerCube ,则可实现shader.frag。这意味着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 不支持通过其他方式(例如sourceItem 或textureData )获取 图像数据。
另请参阅 Texture 、CustomMaterial 以及Effect 。
© 2026 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.