core.shader.create_from_raw

Client

Creates a new shader instance directly from a GLSL source string


Syntax

local instance = core.shader.create_from_raw(
    raw,
    mode
)

Parameters

TypeNameDescription
stringrawRaw GLSL shader source code
core.shader.shader_modemodeRendering pipeline to target

Returns

TypeNameDescription
shaderinstanceCreated shader instance

Examples

Compile a canvas-item shader from an inline source string
local raw = [[
    void fragment() {
        COLOR = vec4(UV, 0.0, 1.0);
    }
]]

local entity = core.shader.create_from_raw(raw, core.shader.shader_mode.CANVAS_ITEM)

util.event.on("sandbox:draw", function()
    core.engine.draw_material(
        {0, 0}, 
        core.engine.get_resolution(), 
        entity
    )
end)
Compile a spatial shader from a raw source string
local raw = [[
    uniform float dissolve_amount : hint_range(0.0, 1.0) = 0.0;

    void fragment() {
        ALBEDO = vec3(dissolve_amount);
    }
]]

local entity = core.shader.create_from_raw(raw, core.shader.shader_mode.SPATIAL)

entity:set_param("dissolve_amount", 0.5)

On this page