Skip to content
coding.jackalope edited this page Jul 22, 2020 · 1 revision
Table of Contents

Overview

Slab offers API functions to apply a shader effect to any control. To enable a shader, PushShader must be called with a valid shader object. This shader object must be managed by the user. Slab does not manage any shader objects internally. Any controls created between the PushShader call and the PopShader call will have the currently pushed shader object on the stack applied to them. Slab will clear the shader stack at the end of a frame. Below is an example usage of applying a shader effect to a text control.

local Time = 0
local Code =
[[
extern number time;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
	vec4 TexColor = Texel(texture, texture_coords);
    return vec4((1.0+sin(time))/2.0, abs(cos(time)), abs(sin(time)), 1.0) * TexColor;
}
]]
local Shader = nil

function love.load(args)
	love.graphics.setBackgroundColor(0.4, 0.88, 1.0)
	Slab.Initialize(args)

	Shader = love.graphics.newShader(Code)
end

function love.update(dt)
	Slab.Update(dt)

	Time = Time + dt
	Shader:send("time", Time)

	Slab.BeginWindow('Shader', {Title = "Shader Example"})
	Slab.PushShader(Shader)
	Slab.Text("Shader Text")
	Slab.PopShader()
	Slab.Text("Regular Text")
	Slab.EndWindow()
end

function love.draw()
	Slab.Draw()
end

API

Below is a list of calls associated with the Shader API.

PushShader

Pushes a shader effect to be applied to any following controls before a call to PopShader. Any shader effect that is still active will be cleared at the end of Slab's draw call.

Parameter Type Description
Shader Object The shader object created with the love.graphics.newShader function. This object should be managed by the caller.

PopShader

Pops the currently active shader effect. Will enable the next active shader on the stack. If none exists, no shader is applied.

Clone this wiki locally