M MY Multiplayer: Wiki
Side
Kind

engineCreateShader

Client

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

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

Parameters

NameTypeDescription
sourcestringThe 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.
namestringThe 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
macrostableA 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

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)
NoteGiving a name another shader of the same resource already has is an error.

See also