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.


Inherits: Material < Resource < RefCounted < Object

A material defined by a custom Shader program and the values of its shader parameters.


A material that uses a custom Shader program to render visual items (canvas items, meshes, skies, fog), or to process particles. Compared to other materials, ShaderMaterial gives deeper control over the generated shader code. For more information, see the shaders documentation index below.

Multiple ShaderMaterials can use the same shader and configure different values for the shader uniforms.

Note: For performance reasons, the Resource.changed signal is only emitted when the Resource.resource_name changes. Only in editor, it is also emitted for shader changes.







get_shader_parameter ( StringName param ) const


set_shader_parameter ( StringName param, Variant value )

Property Descriptions

Shader shader

用于渲染此材质的 Shader 程序。

Method Descriptions

Variant get_shader_parameter ( StringName param ) const

返回在着色器中此 uniform 材质的当前值。

void set_shader_parameter ( StringName param, Variant value )

更改这个材质的着色器中为某个 uniform 设置的值。

注意:param 大小写敏感,必须完全匹配代码中 uniform 的名称(不是检查器中首字母大写后的名称)。

注意:对着色器 uniform 的修改会在使用这个 ShaderMaterial 的所有实例上生效。要防止这种行为,请通过 GeometryInstance3D.set_instance_shader_parameter 使用单实例 uniform,或者使用 Resource.duplicate 制作该 ShaderMaterial 的副本。单实例 uniform 可以更好地复用着色器,因此速度也更快,所以应该尽可能优先使用,而不是制作 ShaderMaterial 的副本。