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.

Shader

繼承: Resource < RefCounted < Object

被繼承: VisualShader

用 Godot 著色語言實作的著色器。

說明

用 Godot 著色語言實作的自訂著色器程式,使用 .gdshader 副檔名保存。

這個類由 ShaderMaterial 使用,能夠讓你編寫算繪可視專案或更新粒子資訊時的自定義行為。詳細解釋和用法請參考下列教學連結。

教學

屬性

String

code

""

方法

Texture

get_default_texture_parameter(name: StringName, index: int = 0) const

Mode

get_mode() const

Array

get_shader_uniform_list(get_groups: bool = false)

void

inspect_native_shader_code()

void

set_default_texture_parameter(name: StringName, texture: Texture, index: int = 0)


列舉

enum Mode: 🔗

Mode MODE_SPATIAL = 0

用於繪製所有 3D 物件的模式。

Mode MODE_CANVAS_ITEM = 1

用於繪製所有 2D 物件的模式。

Mode MODE_PARTICLES = 2

用於基於每個粒子計算粒子資訊的模式。不用於繪圖。

Mode MODE_SKY = 3

用於繪製天空的模式。僅適用於附加到 Sky 對象的著色器。

Mode MODE_FOG = 4

用於設定體積霧效果的顏色和密度的模式。

Mode MODE_TEXTURE_BLIT = 5

Mode used for drawing to DrawableTexture resources via blit calls.


屬性說明

String code = "" 🔗

返回使用者編寫的著色器程式碼,而不是內部使用的完整生成程式碼。


方法說明

Texture get_default_texture_parameter(name: StringName, index: int = 0) const 🔗

返回被設定為指定參數的預設值的紋理。

注意:name 必須與程式碼中的 uniform 名稱完全配對。

注意:如果使用取樣器陣列,則使用 index 存取指定的紋理。


Mode get_mode() const 🔗

返回著色器的著色器模式。


Array get_shader_uniform_list(get_groups: bool = false) 🔗

Returns the list of shader uniforms that can be assigned to a ShaderMaterial, for use with ShaderMaterial.set_shader_parameter() and ShaderMaterial.get_shader_parameter(). The parameters returned are contained in dictionaries in a similar format to the ones returned by Object.get_property_list().

If argument get_groups is true, parameter grouping hints are also included in the list.


void inspect_native_shader_code() 🔗

Only available when running in the editor. Opens a popup that visualizes the generated shader code, including all variants and internal shader code. See also Material.inspect_native_shader_code().


void set_default_texture_parameter(name: StringName, texture: Texture, index: int = 0) 🔗

設定要與紋理 uniform 一起使用的預設紋理。如果未在 ShaderMaterial 中設定紋理,則使用該預設值。

注意:name 必須與程式碼中的 uniform 名稱完全配對。

注意:如果使用取樣器陣列,則使用 index 存取指定的紋理。