# engineCreateShader (Client)

> Creates a shader from a `.shader` file or from its source text. The shader compiles in the background.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Materials and shaders
- **URL**: https://wiki.mymp.gg/en/engineCreateShader

## Syntax

```lua
shader|false engineCreateShader(string source [, string name = nil, table macros = nil])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `source` | `string` | The path of a `.shader` file in the resource, a file of another resource as `@resource/file.shader`, or the shader's source, which starts with `#type`. |
| `name` | `string` | The name materials find it by. Without it, it is `resource/file`; from source text or with macros, the name ends in a hash. *(default: `nil`)* |
| `macros` | `table` | A table of name → value (string, number or boolean) defined before compiling. Names are identifiers and cannot be names the engine defines. *(default: `nil`)* |

## Returns

The `shader` element, or `false` if the text is neither a `.shader` file nor shader source, or if it could not be read from another resource.

When compiling ends, `onClientAssetLoad` fires on the shader. Compile errors are listed by `engineGetShaderErrors`.

## Example

```lua
local shader = engineCreateShader("shaders/glow.shader", nil, { STRENGTH = 2 })

addEventHandler("onClientAssetLoad", shader, function(loaded)
    if not loaded then
        for _, message in ipairs(engineGetShaderErrors(shader)) do
            outputDebugString(message)
        end
    end
end)
```

### Note

Giving a name another shader of the same resource already has is an error.

## See also

- [engineGetShaderErrors (Client)](https://wiki.mymp.gg/en/engineGetShaderErrors.md): Lists the errors from the last compile of a shader made with engineCreateShader.
- [engineCreateMaterial (Client)](https://wiki.mymp.gg/en/engineCreateMaterial.md): Creates a material: a shader with parameter values, which then replaces or overlays the materials of models.
- [engineGetShaders (Client)](https://wiki.mymp.gg/en/engineGetShaders.md): Lists every loaded shader and preset, from packs and scripts.
- [onClientAssetLoad (Client)](https://wiki.mymp.gg/en/onClientAssetLoad.md): Fired once when an asset a script started loading in the background is ready, or has failed.
