ShaderMaterial
Inherits:Material<Resource<RefCounted<Object
A material defined by a customShader program and the values of its shader parameters.
Description
A material that uses a customShader 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.
MultipleShaderMaterials can use the same shader and configure different values for the shader uniforms.
Note: For performance reasons, theResource.changed signal is only emitted when theResource.resource_name changes. Only in editor, it is also emitted forshader changes.
Tutorials
Properties
Methods
set_shader_parameter(param:StringName, value:Variant) |
Property Descriptions
Shaderget_shader()
TheShader program used to render this material.
Method Descriptions
Variantget_shader_parameter(param:StringName)const🔗
Returns the current value set for this material of a uniform in the shader.
voidset_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 thisShaderMaterial. To prevent this, use per-instance uniforms withGeometryInstance3D.set_instance_shader_parameter() or duplicate theShaderMaterial resource usingResource.duplicate(). Per-instance uniforms allow for better shader reuse and are therefore faster, so they should be preferred over duplicating theShaderMaterial when possible.