Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

NoiseTexture2D

继承: Texture2D < Texture < Resource < RefCounted < Object

Noise 对象生成的噪声所填充的 2D 纹理。

描述

使用 FastNoiseLite 库或其他噪声生成器来填充所需大小的纹理数据。NoiseTexture2D 还能生成法线贴图纹理。

该类在内部使用 Thread 生成纹理数据,因此如果生成过程尚未完成,Texture2D.get_image 可能会返回 null。在这种情况下,需要等待纹理生成后再访问图像和生成的字节数据:

var texture = NoiseTexture2D.new()
texture.noise = FastNoiseLite.new()
await texture.changed
var image = texture.get_image()
var data = image.get_data()

属性

bool

as_normal_map

false

float

bump_strength

8.0

Gradient

color_ramp

bool

generate_mipmaps

true

int

height

512

bool

in_3d_space

false

bool

invert

false

Noise

noise

bool

normalize

true

bool

resource_local_to_scene

false (overrides Resource)

bool

seamless

false

float

seamless_blend_skirt

0.1

int

width

512


属性说明

bool as_normal_map = false

  • void set_as_normal_map ( bool value )

  • bool is_normal_map ( )

如果为 true,产生的纹理包含一个由原始噪声创建的法线贴图,解释为凹凸贴图。


float bump_strength = 8.0

  • void set_bump_strength ( float value )

  • float get_bump_strength ( )

该纹理中使用的凹凸贴图的强度。更高的值会使凹凸贴图看起来更大,而更低的值会使它们看起来更柔和。


Gradient color_ramp

Gradient,用于将每个像素的亮度映射到一个颜色值。


bool generate_mipmaps = true

  • void set_generate_mipmaps ( bool value )

  • bool is_generating_mipmaps ( )

决定是否为该纹理生成 mipmap。启用该属性可减少纹理锯齿,但会增加约 33% 的内存占用,生成噪声纹理也可能需要更长的时间。

注意:使用该 NoiseTexture2D 的材质需要启用 mipmap 过滤才能让 generate_mipmaps 生效。


int height = 512

  • void set_height ( int value )

  • int get_height ( )

生成的纹理的高度(单位为像素)。


bool in_3d_space = false

  • void set_in_3d_space ( bool value )

  • bool is_in_3d_space ( )

决定是否在 3D 空间中计算噪声图像。可能会导致对比度降低。


bool invert = false

  • void set_invert ( bool value )

  • bool get_invert ( )

如果为 true,则反转该噪声纹理。白变黑,黑变白。


Noise noise

  • void set_noise ( Noise value )

  • Noise get_noise ( )

Noise 对象的实例。


bool normalize = true

  • void set_normalize ( bool value )

  • bool is_normalized ( )

如果为 true,来自噪声发生器的噪声图像,将被归一化到范围 0.01.0

关闭归一化会影响对比度,并允许生成非重复的可平铺噪声纹理。


bool seamless = false

  • void set_seamless ( bool value )

  • bool get_seamless ( )

如果为 true,则从 Noise 资源请求无缝纹理。

注意:与非无缝噪声相比,无缝噪声纹理可能需要更长的时间来生成,并且/或者可能具有较低的对比度,具体取决于所使用的 Noise 资源。这是因为一些实现使用更高的维度来生成无缝噪声。

注意:默认的 FastNoiseLite 实现在生成无缝纹理时使用回退路径。如果使用的 widthheight 小于默认值,你可能需要通过增大 seamless_blend_skirt 来让无缝混合更高效。


float seamless_blend_skirt = 0.1

  • void set_seamless_blend_skirt ( float value )

  • float get_seamless_blend_skirt ( )

用于无缝纹理生成的默认/回退实现。它决定接缝混合的距离。较高的值可能会导致较少的细节和对比度。详情见 Noise

注意:如果使用的 widthheight 小于默认值,你可能需要通过增大 seamless_blend_skirt 来让无缝混合更高效。


int width = 512

  • void set_width ( int value )

  • int get_width ( )

生成的纹理的宽度(单位为像素)。