# engineSetShaderGlobal (Client)

> Sets a shader global, a value every shader reads. A new name creates the global.

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

## Syntax

```lua
bool engineSetShaderGlobal(string name, any value [, int priority = 0])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `name` | `string` | The global's name. Shaders read it in UPPER_SNAKE_CASE: `nightShare` becomes `NIGHT_SHARE`. |
| `value` | `any` | A number, a vector, a `tocolor` value for `vec3` and `vec4`, or a texture's name or an image for a texture. A global that already exists only takes its own type. |
| `priority` | `int` | When several resources set the same global, the highest priority wins; between equals, the newest. *(default: `0`)* |

## Returns

`true` when the value was set.

## Example

```lua
engineSetShaderGlobal("alarmPulse", 0)
local shader = engineCreateShader("shaders/alarm.shader")

addEventHandler("onClientPreRender", root, function()
    engineSetShaderGlobal("alarmPulse", math.abs(math.sin(getTickCount() / 300)))
end)
```

### Note

A global a pack locked, or a value of another type, is an error. A shader that reads a script's global compiles only if the global exists when the shader is created.

## See also

- [engineGetShaderGlobal (Client)](https://wiki.mymp.gg/en/engineGetShaderGlobal.md): Reads a shader global's current value.
- [engineResetShaderGlobal (Client)](https://wiki.mymp.gg/en/engineResetShaderGlobal.md): Drops the value this resource gave a shader global, so the global goes back to the next one's value.
- [engineGetShaderGlobals (Client)](https://wiki.mymp.gg/en/engineGetShaderGlobals.md): Lists every shader global, from packs and scripts.
- [engineCreateShader (Client)](https://wiki.mymp.gg/en/engineCreateShader.md): Creates a shader from a .shader file or from its source text. The shader compiles in the background.
