declaration:
function define_rendertarget( dstvid, vidary, detachopt, scaleopt )
The function creates an offscreen rendertarget (FBO) that will be use the storage of dstvid for resolution, filtering and so on.
vidary is an indexed table of valid VIDs that will be attached to the renderpipe that will be associated with the FBO and the dstvid.
detachopt can be either RENDERTARGET_DETACH or RENDERTARGET_NODETACH and controls whether VIDs of viary should remain connected to whatever pipeline that controlled them beforehand as well, or if control should be handed over to the one of the rendertarget.
scaleopt can be either RENDERTARGET_SCALE or RENDERTARGET_NOSCALE meaning that the relative proportions of the FBO and the main display should be retained or not.
example use:
::lua
-- this function creates two intermediate surfaces that applies
-- horiz-vert separated gaussian blur along with regular texture filtering
function setupblur(targetw, targeth)
local blurshader_h = load_shader("shaders/fullscreen/default.vShader",
"shaders/fullscreen/gaussianH.fShader",
"blur_horiz", {});
local blurshader_v = load_shader("shaders/fullscreen/default.vShader",
"shaders/fullscreen/gaussianV.fShader",
"blur_vert", {});
local blurw = targetw * 0.4;
local blurh = targeth * 0.4;
shader_uniform(blurshader_h, "blur", "f", PERSIST, 1.0 / blurw);
shader_uniform(blurshader_v, "blur", "f", PERSIST, 1.0 / blurh);
shader_uniform(blurshader_h, "ampl", "f", PERSIST, 1.2);
shader_uniform(blurshader_v, "ampl", "f", PERSIST, 1.4);
local blur_hbuf = fill_surface(blurw, blurh, 1, 1, 1, blurw, blurh);
local blur_vbuf = fill_surface(targetw, targeth, 1, 1, 1, blurw, blurh);
image_shader(blur_hbuf, blurshader_h);
image_shader(blur_vbuf, blurshader_v);
show_image(blur_hbuf);
show_image(blur_vbuf);
return blur_hbuf, blur_vbuf;
end
local blurw, blurh = setupblur(VRESW, VRESH);
-- load an image, create a copy of it and attach as input to the first blur pass
source = load_image("fullscreen.png");
resize_image(source, VRESW, VRESH);
show_image(source);
define_rendertarget(blurw, {instance_image(source)}, RENDERTARGET_DETACH, RENDERTARGET_NOSCALE);
-- then apply the output from that one to a second blur pass
define_rendertarget(blurh, {blurw}, RENDERTARGET_DETACH, RENDERTARGET_NOSCALE);
-- and finally draw it as an overlay to the input image
blend_image(blurh, 0.99);
force_image_blend(blurh, BLEND_ADD);
order_image(blurh, max_current_image_order() + 1);
related functions:
[define_recordtarget]