# GDScript: Materials and shaders

Source: https://tweens.gd/gdscript/materials/

Animate a material to change every node that uses it. Use an instance uniform when each node needs its own shader value.

Examples use the global `Tweens` class in a node script, with targets inside the scene tree. `mesh` is a `MeshInstance3D` using the materials shown.

## Choose an owner

A material isn’t in the scene tree, so its tweens take an owner as the third argument. A node ends playback when it leaves the tree; the tree keeps it running until shutdown:

```gdscript
var smooth := Tweens.material_roughness(0.2, 1.0)
Tweens.play(material, smooth, mesh)       # Ends when mesh leaves the tree.
Tweens.play(material, smooth, get_tree()) # Ends when the tree shuts down.
```

The tween keeps animating this material, even if the mesh switches to another one.

## Material properties

The [material catalog](https://tweens.gd/gdscript/nodes/materials/) covers albedo, roughness, emission, UVs, and more on `BaseMaterial3D`. Every node using a material shows its tweens, so to animate one node alone, duplicate the material once during setup:

```gdscript
var unique: StandardMaterial3D = shared.duplicate()
mesh.material_override = unique
Tweens.play(unique, Tweens.material_albedo_color(Color.RED, 1.0), mesh)
```

Enable the feature first

Tweens change values, not material flags. Fading alpha needs transparency enabled; emission and normal maps need their own flags.

## Shader uniforms

For a shader declaring `uniform float dissolve = 0.25;`:

```gdscript
Tweens.play(shader_material, Tweens.shader_parameter(&"dissolve", 1.0, 0.5), mesh)
```

This changes the uniform for every node using the material. Names are case-sensitive, and the endpoint’s type must match the uniform: `1.0` for a float, `1` for an int, `Color` for a color, and the matching vector type for a vector.

## Instance uniforms

For a shader declaring `instance uniform float pulse = 0.25;`:

Godot's Tween

```gdscript
mesh.create_tween().tween_method(
    func(value: float) -> void: mesh.set_instance_shader_parameter(&"pulse", value),
    0.25, 1.0, 0.5)
```

tweens.gd

```gdscript
Tweens.play(mesh, Tweens.instance_shader_parameter(&"pulse", 1.0, 0.5))
```

Only this node’s value changes, even when it shares the material. The tween starts from the current value or the shader’s default, where Godot’s version needs it written out.

Keep bindings stable

Editing or replacing a bound shader ends playback with `FAILED`, and so does swapping the material under an instance uniform. Start a new tween after the change. Reading a shader’s default value needs a working renderer.

[Material and uniform reference](https://tweens.gd/gdscript/nodes/materials/)Supported types, validation, defaults, and restoring overrides.
