Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Cubemap

继承: ImageTextureLayered < TextureLayered < Texture < Resource < RefCounted < Object

代表立方体面的六个正方形纹理。通常用作天空盒。

描述

立方体贴图由 6 个纹理组成,按层组织,通常用于在 3D 渲染中充当反射(见 ReflectionProbe)。使用立方体贴图可以使物体看起来像是在反射周围的环境。这通常比其他反射方法提供更好的性能。

该资源通常作为自定义着色器中的 uniform 使用。少数核心 Godot 方法会用到 Cubemap 资源。

要自己创建这样的纹理文件,请使用 Godot 编辑器的导入预设重新导入图像文件。要使用代码创建 Cubemap,请对 Cubemap 类的实例调用 ImageTextureLayered.create_from_images()

预期的图像顺序是 X+、X-、Y+、Y-、Z+、Z-(Godot 的坐标系统中 Y+ 是“上”、Z- 是“前”)。你可以从下列模板中挑选一个作为基础:

注意:Godot 不支持在 PanoramaSkyMaterial 中使用立方体贴图。要将立方体贴图用作天空盒,请使用 转换为 ShaderMaterial 资源下拉选项将默认的 PanoramaSkyMaterial 转换为 ShaderMaterial,然后将其代码替换为:

shader_type sky;

uniform samplerCube source_panorama : filter_linear, source_color, hint_default_black;
uniform float exposure : hint_range(0, 128) = 1.0;

void sky() {
    // 如果立方体贴图是从其他引擎导入的,可能需要通过将下面的
    // 某一个 `EYEDIR` 分量替换为 `-EYEDIR` 来进行翻转。
    vec3 eyedir = vec3(EYEDIR.x, EYEDIR.y, EYEDIR.z);
    COLOR = texture(source_panorama, eyedir).rgb * exposure;
}

替换着色器代码并保存后,请在检查器中 ShaderMaterial 的 Shader Parameters 部分指定导入的立方体贴图资源。

另外,你可以使用 这个工具将立方体贴图转换为等距矩形天空图,这样就可以像往常一样使用 PanoramaSkyMaterial 了。

方法

Resource

create_placeholder() const


方法说明

Resource create_placeholder() const 🔗

创建该资源的占位符版本(PlaceholderCubemap)。