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.

ShaderMaterial

繼承: Material < Resource < RefCounted < Object

自訂 Shader 程式定義的材質及其著色器參數的值。

說明

使用自訂 Shader 程式算繪視覺專案(畫布專案、網格、天空、霧)或處理粒子的材質。與其他材質相比,ShaderMaterial 給予對產生的著色器程式碼進行更深入的控制。有關更多信息,請參閱下面的著色器檔案索引。

多個ShaderMaterial可以使用相同的著色器並為著色器製服配置不同的值。

注意:基於效能原因,僅當Resource.resource_name變更時才會發出Resource.changed訊號。僅在編輯器中,它也會針對 shader 變更發出。

教學

屬性

Shader

shader

方法

Variant

get_shader_parameter(param: StringName) const

void

set_shader_parameter(param: StringName, value: Variant)


屬性說明

Shader shader 🔗

用於算繪此材質的 Shader 程式。


方法說明

Variant get_shader_parameter(param: StringName) const 🔗

返回在著色器中此 uniform 材質的目前值。


void set_shader_parameter(param: StringName, value: Variant) 🔗

Changes the value set for this material of a uniform in the shader.

Note: param is case-sensitive and must match the name of the uniform in the code exactly (not the capitalized name in the inspector).

Note: Changes to the shader uniform will be effective on all instances using this ShaderMaterial. To prevent this, use per-instance uniforms with CanvasItem.set_instance_shader_parameter(), GeometryInstance3D.set_instance_shader_parameter() or duplicate the ShaderMaterial resource using Resource.duplicate(). Per-instance uniforms allow for better shader reuse and are therefore faster, so they should be preferred over duplicating the ShaderMaterial when possible.