# C#: Materials and shaders

Source: https://tweens.gd/csharp/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 `using Godot;` and `using tweens.gd;` in a Node method, 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. A node ends playback when it leaves the tree; the tree keeps it running until shutdown:

```csharp
material.TweenRoughness(0.2, 1, mesh);      // Ends when mesh leaves the tree.
material.TweenRoughness(0.2, 1, GetTree()); // 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/csharp/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:

```csharp
var unique = (StandardMaterial3D)shared.Duplicate();
mesh.MaterialOverride = unique;
unique.TweenAlbedoColor(Colors.Red, 1, 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;`:

```csharp
shaderMaterial.TweenShaderParameter("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

```csharp
mesh.CreateTween().TweenMethod(
    Callable.From((float value) => mesh.SetInstanceShaderParameter("pulse", value)),
    0.25f, 1f, 0.5);
```

tweens.gd

```csharp
mesh.TweenInstanceShaderParameter("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 faults playback, 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/csharp/nodes/materials/)Supported types, validation, defaults, and restoring overrides.
