compute
Functions for interacting with compute programs.
Functions
compute.get_constants(path: Hash | string): { name: Hash; type: number; value: Vector4 | Matrix4 }[]Ncompute.get_samplers(path: Hash | string): { name: Hash; u_wrap: number; v_wrap: number; min_filter: number; mag_filter: number; max_anisotropy: number }[]Ncompute.get_textures(path: Hash | string): { path: Hash; handle: Hash; width: number; height: number; depth: number; mipmaps: number; type: number; flags: number }[]Ncompute.set_constants(path: Hash | string, constants: Record<string, { type?: number; value?: Vector4 | Vector3 | Matrix4 | number | (Vector4 | Matrix4)[] }>): voidNcompute.set_samplers(path: Hash | string, samplers: Record<string, { u_wrap?: number; v_wrap?: number; min_filter?: number; mag_filter?: number; max_anisotropy?: number }>): voidNcompute.set_textures(path: Hash | string, textures: LuaMap<string, Hash> | Record<string, Hash>): voidN
compute.get_constants(path: Hash | string): { name: Hash; type: number; value: Vector4 | Matrix4 }[]N
- Since Defold 1.13.0
Returns a table of all the shader constants in the compute program.
const constants = compute.get_constants("/my_compute.computec");function init(self)
local constants = compute.get_constants("/my_compute.computec")
endParameters
path:Hash | string— The path to the resource
Returns
table:{ name: Hash; type: number; value: Vector4 | Matrix4 }[]— Information about the shader constants.
compute.get_samplers(path: Hash | string): { name: Hash; u_wrap: number; v_wrap: number; min_filter: number; mag_filter: number; max_anisotropy: number }[]N
- Since Defold 1.13.0
Returns a table of all the texture samplers in the compute program. This function will return all the texture samplers that are available, even the ones that have not been specified in the compute resource.
const samplers = compute.get_samplers("/my_compute.computec");function init(self)
local samplers = compute.get_samplers("/my_compute.computec")
endParameters
path:Hash | string— The path to the resource
Returns
table:{ name: Hash; u_wrap: number; v_wrap: number; min_filter: number; mag_filter: number; max_anisotropy: number }[]— Information about the texture samplers.
compute.get_textures(path: Hash | string): { path: Hash; handle: Hash; width: number; height: number; depth: number; mipmaps: number; type: number; flags: number }[]N
- Since Defold 1.13.0
Returns a table of all the textures from the compute program.
const textures = compute.get_textures("/my_compute.computec");function init(self)
local textures = compute.get_textures("/my_compute.computec")
endParameters
path:Hash | string— The path to the resource
Returns
table:{ path: Hash; handle: Hash; width: number; height: number; depth: number; mipmaps: number; type: number; flags: number }[]— Information about the compute textures.
compute.set_constants(path: Hash | string, constants: Record<string, { type?: number; value?: Vector4 | Vector3 | Matrix4 | number | (Vector4 | Matrix4)[] }>): voidN
- Since Defold 1.13.0
Sets shader constants in a compute program, if the constants exist.
// Set a shader constant in a compute program
export default defineScript({
init() {
return { my_view_proj: vmath.matrix4() };
},
update(self) {
// update the 'tint' constant
compute.set_constants("/my_compute.computec", {
tint: { value: vmath.vector4(1, 0, 0, 1) },
});
// change the type of the 'view_proj' constant to CONSTANT_TYPE_USER_MATRIX4 so the renderer can set our custom data
compute.set_constants("/my_compute.computec", {
view_proj: { value: self.my_view_proj, type: material.CONSTANT_TYPE_USER_MATRIX4 },
});
},
});function update(self)
-- update the 'tint' constant
compute.set_constants("/my_compute.computec", {
tint = { value = vmath.vector4(1, 0, 0, 1) }
})
-- change the type of the 'view_proj' constant to CONSTANT_TYPE_USER_MATRIX4 so the renderer can set our custom data
compute.set_constants("/my_compute.computec", {
view_proj = { value = self.my_view_proj, type = material.CONSTANT_TYPE_USER_MATRIX4 }
})
endParameters
path:Hash | string— The path to the resourceconstants:Record<string, { type?: number; value?: Vector4 | Vector3 | Matrix4 | number | (Vector4 | Matrix4)[] }>— Constant options keyed by constant name. Partial updates are supported.
compute.set_samplers(path: Hash | string, samplers: Record<string, { u_wrap?: number; v_wrap?: number; min_filter?: number; mag_filter?: number; max_anisotropy?: number }>): voidN
- Since Defold 1.13.0
Sets texture samplers in a compute program, if the samplers exist. Use this function to change the settings of texture samplers.
To set actual textures that should be bound to the samplers, use the compute.set_textures function instead.
compute.set_samplers("/my_compute.computec", { texture_sampler: { u_wrap: graphics.TEXTURE_WRAP_REPEAT, v_wrap: graphics.TEXTURE_WRAP_MIRRORED_REPEAT } });function init(self)
compute.set_samplers("/my_compute.computec", {
texture_sampler = { u_wrap = graphics.TEXTURE_WRAP_REPEAT, v_wrap = graphics.TEXTURE_WRAP_MIRRORED_REPEAT }
})
endParameters
path:Hash | string— The path to the resourcesamplers:Record<string, { u_wrap?: number; v_wrap?: number; min_filter?: number; mag_filter?: number; max_anisotropy?: number }>— Sampler options keyed by sampler name. Partial updates are supported.
compute.set_textures(path: Hash | string, textures: LuaMap<string, Hash> | Record<string, Hash>): voidN
- Since Defold 1.13.0
Sets textures in a compute program, if the samplers exist.
// Set a texture in a compute program from a resource
export default defineScript({
// Never call `go.property` yourself: the transpiler emits the chunk-scope
// registration from this field, and only this field types the property onto `self`.
properties: { my_texture: resource.texture() },
init(self) {
compute.set_textures("/my_compute.computec", {
my_texture: self.my_texture,
});
},
});go.property("my_texture", resource.texture())
function init(self)
compute.set_textures("/my_compute.computec", {
my_texture = self.my_texture
})
endParameters
path:Hash | string— The path to the resourcetextures:LuaMap<string, Hash> | Record<string, Hash>— A table keyed by sampler name with texture resources as values.