Shader:Create Synchronous

Compile the Vertex and Pixel source currently assigned to a Shader drawing. Call it after setting both strings; changing source text alone does not compile it.

Syntax
Luau
Shader:Create() -> ()

Parameters

Call this method with a Shader receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.

This function takes no arguments.

Returns

()

No values. Compilation failure raises an error.

Usage notes

Each source must contain 1 through 1,048,576 bytes and be self-contained. The compiler does not open filesystem includes or imports.

To work from saved fragments, read and combine them in Luau before assigning Vertex and Pixel. A filename in either property is treated as source text, not a path.

Limits

ResourceLimitWhat happens
Shader source1–1,048,576 bytes for each of Vertex and PixelBoth properties must contain source text before compilation. Empty or oversized source raises an error.
File access during compilationNo filesystem includes or importsCompilation cannot load source files from paths. Supply self-contained source strings; a dependency that needs a filesystem read makes compilation fail.

Your script may read a workspace file with readfile and assign its contents to Vertex or Pixel before calling Create. The shader compiler itself cannot follow filesystem dependencies inside those strings.

Example

Example
Luau
local shader = Drawing.new("Shader")
shader.Vertex = [[
struct VSOut { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; };
VSOut main(uint id : SV_VertexID) {
    float2 p[3] = { float2(-1, -1), float2(-1, 3), float2(3, -1) };
    float2 uv[3] = { float2(0, 1), float2(0, -1), float2(2, 1) };
    VSOut outValue;
    outValue.pos = float4(p[id], 0, 1);
    outValue.uv = uv[id];
    return outValue;
}]]
shader.Pixel = [[
float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD0) : SV_Target {
    return float4(uv.x, uv.y, 0.5, 1);
}]]
shader.Position = Vector2.new(40, 40)
shader.Size = Vector2.new(180, 100)
local ok, message = pcall(function() shader:Create() end)
if not ok then
    print("Shader error:", message)
    shader:Remove()
else
    task.delay(5, function() shader:Remove() end)
end
Kawaii documentation