# Sandbox.Shader.CompileAsync

## Overload 1

```csharp
static System.Threading.Tasks.Task<Shader> CompileAsync(string source, System.Threading.CancellationToken token = null)
```

Compile shader source from a string into an anonymous shader, like an anonymous texture or material: nothing can
find it by name, it lives in memory, and it goes when nothing uses it. The source is Slang (a surface, raw module or
pass module, told by its content) or the old .shader text; a Slang one is kept under a name of its own instead. Use it with
[Sandbox.Material.FromShader](/api/Sandbox.Material/FromShader) or [Sandbox.Material.Create](/api/Sandbox.Material/Create). Each call makes
a new shader. Includes come from the engine's shaders and the game's. A dedicated server compiles it too, so
errors show up there, but returns null, the same as [Sandbox.Shader.Load](/api/Sandbox.Shader/Load).

### Parameters

- `source` (`string`): The whole Slang or .shader file
- `token` (`System.Threading.CancellationToken`), default `null`: Stops the compile

### Returns

`System.Threading.Tasks.Task<Shader>`

### Exceptions

- `Sandbox.ShaderCompileException`: The shader didn't compile

## Overload 2

```csharp
static System.Threading.Tasks.Task<Shader> CompileAsync(string name, string source, System.Threading.CancellationToken token = null)
```

Compile shader source from a string: Slang (a surface, raw module or pass module, told by its content) or the old
.shader text. The name identifies it, so compiling the same name again swaps the new
version in, and anything using the shader picks it up. Includes come from the engine's shaders and the game's.
Unchanged source isn't compiled again. A dedicated server compiles it too, so errors show up there, but returns
null, the same as [Sandbox.Shader.Load](/api/Sandbox.Shader/Load).

### Parameters

- `name` (`string`): What to call it, like "water" or "effects/water.shader"
- `source` (`string`): The whole Slang or .shader file
- `token` (`System.Threading.CancellationToken`), default `null`: Stops the compile

### Returns

`System.Threading.Tasks.Task<Shader>`

### Exceptions

- `Sandbox.ShaderCompileException`: The shader didn't compile

Declared in [Sandbox.Shader](/api/Sandbox.Shader).
Assembly: `Sandbox.Engine`.
