Skip to Content
defold-typescript
Get startedGuidesAPILibraries
Defold

compute

Functions for interacting with compute programs.

Functions

compute.get_constants(path: Hash | string): material.ConstantInfo[]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")
end

Parameters

  • path: Hash | string — The path to the resource

Returns

compute.get_samplers(path: Hash | string): material.SamplerInfo[]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")
end

Parameters

  • path: Hash | string — The path to the resource

Returns

compute.get_textures(path: Hash | string): material.TextureInfo[]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")
end

Parameters

  • path: Hash | string — The path to the resource

Returns

compute.set_constants(path: Hash | string, constants: LuaMap<string | Hash, material.ConstantOptions> | Record<string, material.ConstantOptions>): 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 }
    })
end

Parameters

compute.set_samplers(path: Hash | string, samplers: LuaMap<string | Hash, material.SamplerOptions> | Record<string, material.SamplerOptions>): 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 }
    })
end

Parameters

compute.set_textures(path: Hash | string, textures: LuaMap<string | Hash, string | Hash> | Record<string, 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
    })
end

Parameters

  • path: Hash | string — The path to the resource
  • textures: LuaMap<string | Hash, string | Hash> | Record<string, string | Hash> — A table keyed by sampler name with texture resources as values.

On this page