Shader

self:set_output

Client

Binds a shader output declared with VSDK_OUT to a rendertarget

Syntax

local status = self:set_output(
    name,
    rendertarget = nil
)

Every bound output costs one extra draw.

  • Declaring — outputs are declared in the shader with VSDK_OUT(name, value), see the Output Cheatsheet.
  • Canvas Item — the output is drawn into the rendertarget each time the shader is drawn.
  • Spatial — turns on 3D rendering for the rendertarget, up to 12 at once.
  • Unbinding — omit the rendertarget to stop drawing the output.
  • Unknown name — raises an error listing the outputs declared in the shader.

Parameters

TypeNameDescription
stringnameName of the output as declared with VSDK_OUT in the shader
rendertarget | nilrendertargetRendertarget the output is drawn into
Omit to unbind the output

Returns

TypeNameDescription
boolstatustrue on successful execution, false otherwise

Examples

Draw a canvas shader's second result into a rendertarget
local entity = core.shader.create_from_raw([[
    void fragment() {
        COLOR = vec4(0.0, 1.0, 0.0, 1.0);
        VSDK_OUT(mask, vec4(1.0, 0.0, 0.0, 1.0));
    }
]], core.shader.shader_mode.CANVAS_ITEM)

local mask = core.rendertarget.create({512, 512}, true)

entity:set_output("mask", mask)

util.event.on("sandbox:draw", function()
    core.engine.draw_material({0, 0}, {512, 512}, entity) -- green on screen, red in "mask"
end)
Render a mask of a model's surfaces from a spatial shader
core.model.load("character", "models/character.glb")

local model = core.model.create("character")
local entity = core.shader.create_from_raw([[
    void fragment() {
        ALBEDO = vec3(0.0, 1.0, 0.0);
        VSDK_OUT(mask, vec4(1.0, 0.0, 0.0, 1.0));
    }
]], core.shader.shader_mode.SPATIAL)

local mask = core.rendertarget.create(core.display.get_resolution(), true)

entity:set_output("mask", mask)
entity:apply_to_material(model, "*", "*")

On this page