Skip to main content

Shader

Description:

  The Shader record is a singleton object used to compile Dora shaders at runtime.

Usage:

local Shader = require("Shader")
local ok, err = Shader:compile("vs_sprite.sc", "compiled/vs_sprite.bin", "Vertex")

compile

Type: Function.

Description:

  Compiles a shader source file and writes the compiled bytecode to the target file.

Signature:

compile: function(
self: Shader,
sourceFile: string,
targetFile: string,
stage: StageName
): boolean, string | nil

Parameters:

ParameterTypeDescription
sourceFilestringShader source file path.
targetFilestringOutput file path for the compiled shader bytecode. Use the .bin suffix.
stageStageNameShader stage name. One of "Vertex", "Fragment" or "Compute".

Returns:

Return TypeDescription
booleantrue if compilation succeeded, or false if compilation failed.
string | nilThe compilation error message, or nil if compilation succeeded.

compileAsync

Type: Function.

Description:

  Compiles a shader source file asynchronously and writes the compiled bytecode to the target file. This method should be run in a coroutine thread.

Signature:

compileAsync: function(
self: Shader,
sourceFile: string,
targetFile: string,
stage: StageName
): boolean, string | nil

Parameters:

ParameterTypeDescription
sourceFilestringShader source file path.
targetFilestringOutput file path for the compiled shader bytecode. Use the .bin suffix.
stageStageNameShader stage name. One of "Vertex", "Fragment" or "Compute".

Returns:

Return TypeDescription
booleantrue if compilation succeeded, or false if compilation failed.
string | nilThe compilation error message, or nil if compilation succeeded.