Shader
core.shader.create_from_raw
ClientCreates a new shader instance directly from a GLSL source string
Syntax
local instance = core.shader.create_from_raw(
raw,
mode
)Parameters
| Type | Name | Description |
|---|---|---|
string | raw | Raw GLSL shader source code |
core.shader.shader_mode | mode | Rendering pipeline to target: • CANVAS_ITEM - 2D canvas shader• SPATIAL - 3D material shader• POST_PROCESS - full-screen effect over the rendered scene |
Returns
| Type | Name | Description |
|---|---|---|
shader | instance | Created shader instance |
Examples
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.display.get_resolution(),
entity
)
end)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)local raw = [[
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;
uniform float desaturation : hint_range(0.0, 1.0) = 0.5;
void vertex() {
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
}
void fragment() {
vec3 color = texture(screen_texture, SCREEN_UV).rgb;
float grey = dot(color, vec3(0.299, 0.587, 0.114));
ALBEDO = mix(color, vec3(grey), desaturation);
}
]]
local entity = core.shader.create_from_raw(raw, core.shader.shader_mode.POST_PROCESS)
util.event.on("sandbox:draw", function()
core.engine.draw_material({0, 0}, {0, 0}, entity)
end)