RampantDespair
New Member
Is it possible to draw shapes and/or lines through a plugin?
Like simply drawing a line from X to Y on screen.
Like simply drawing a line from X to Y on screen.
-- Drawing 2 crossed lines, green color.
-- Modified by Suslik V (based on RGB Adjustment Tool filter v1.1 by khaver)
obs = obslua
SETTING_CENTERX = 'centerx'
SETTING_CENTERY = 'centery'
TEXT_CENTERX = 'Center X'
TEXT_CENTERY = 'Center Y'
source_info = {}
source_info.id = 'filter-draw-2-crossed-lines-example'
source_info.type = obs.OBS_SOURCE_TYPE_FILTER
source_info.output_flags = obs.OBS_SOURCE_VIDEO
function script_load(settings)
obs.obs_register_source(source_info)
end
function set_render_size(filter)
target = obs.obs_filter_get_target(filter.source)
local width, height
if target == nil then
width = 0
height = 0
else
width = obs.obs_source_get_base_width(target)
height = obs.obs_source_get_base_height(target)
end
filter.width = width
filter.height = height
end
source_info.get_name = function()
return "Draw 2 crossed lines"
end
source_info.create = function(settings, source)
local filter = {}
filter.width = 0
filter.height = 0
filter.source = source
set_render_size(filter)
obs.obs_enter_graphics()
filter.effect = obs.gs_effect_create(shader, nil, nil)
if filter.effect ~= nil then
filter.params = {}
filter.params.centerx = obs.gs_effect_get_param_by_name(filter.effect, 'centerx')
filter.params.centery = obs.gs_effect_get_param_by_name(filter.effect, 'centery')
filter.params.width = obs.gs_effect_get_param_by_name(filter.effect, 'width')
filter.params.height = obs.gs_effect_get_param_by_name(filter.effect, 'height')
end
obs.obs_leave_graphics()
if filter.effect == nil then
source_info.destroy(filter)
return nil
end
source_info.update(filter, settings)
return filter
end
source_info.destroy = function(filter)
if filter.effect ~= nil then
obs.obs_enter_graphics()
obs.gs_effect_destroy(filter.effect)
obs.obs_leave_graphics()
end
filter = nil
end
source_info.get_width = function(filter)
return filter.width
end
source_info.get_height = function(filter)
return filter.height
end
source_info.get_properties = function(settings)
props = obs.obs_properties_create()
obs.obs_properties_add_float_slider(props, SETTING_CENTERX, TEXT_CENTERX, 0.0, 1.0, 0.0001)
obs.obs_properties_add_float_slider(props, SETTING_CENTERY, TEXT_CENTERY, 0.0, 1.0, 0.0001)
return props
end
source_info.get_defaults = function(settings)
obs.obs_data_set_default_double(settings, SETTING_CENTERX, 0.5)
obs.obs_data_set_default_double(settings, SETTING_CENTERY, 0.5)
end
source_info.update = function(filter, settings)
filter.centerx = obs.obs_data_get_double(settings, SETTING_CENTERX)
filter.centery = obs.obs_data_get_double(settings, SETTING_CENTERY)
set_render_size(filter)
end
source_info.video_render = function(filter)
if not obs.obs_source_process_filter_begin(filter.source, obs.GS_RGBA, obs.OBS_ALLOW_DIRECT_RENDERING) then
return
end
obs.gs_effect_set_float(filter.params.centerx, filter.centerx)
obs.gs_effect_set_float(filter.params.centery, filter.centery)
obs.gs_effect_set_int(filter.params.width, filter.width)
obs.gs_effect_set_int(filter.params.height, filter.height)
obs.obs_source_process_filter_end(filter.source, filter.effect, filter.width, filter.height)
end
source_info.video_tick = function(filter, seconds)
set_render_size(filter)
end
-- Returns the description displayed in the Scripts window
function script_description()
return "Adds new Filter named '" .. source_info.get_name() .. "' that draws 2 crossed lines, green color."
end
shader = [[
// Drawing 2 crossed lines, green color.
// Modified by Suslik V (based on RGB Adjustment Tool filter v1.1 by khaver)
uniform float4x4 ViewProj;
uniform texture2d image;
uniform float centerx;
uniform float centery;
uniform int width;
uniform int height;
#define GREEN float3(0.0, 1.0, 0.0)
sampler_state textureSampler {
Filter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertDataIn {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct VertDataOut {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
VertDataOut VSDefault(VertDataIn v_in)
{
VertDataOut vert_out;
vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
vert_out.uv = v_in.uv;
return vert_out;
}
float4 PassThrough(VertDataOut v_in) : TARGET
{
float2 uv = v_in.uv;
float pix3X = (1.0 / width) * 2.0;
float pix3Y = (1.0 / height) * 2.0;
float4 orig = image.Sample(textureSampler, uv);
float2 mouse = float2(centerx, 1.0 - centery);
float3 lvls = orig.rgb;
if (mouse.x >= (uv.x - pix3X) && mouse.x <= (uv.x + pix3X)) {lvls = GREEN; orig.a = 1.0;}
if (mouse.y >= (uv.y - pix3Y) && mouse.y <= (uv.y + pix3Y)) {lvls = GREEN; orig.a = 1.0;}
return float4(lvls, orig.a);
}
technique Draw
{
pass
{
vertex_shader = VSDefault(v_in);
pixel_shader = PassThrough(v_in);
}
}
]]
Yes, you can draw shapes and lines using a plugin. This means you can create a feature that allows you to draw a line from one point to another on the screen.Is it possible to draw shapes and/or lines through a plugin?
Like simply drawing a line from X to Y on screen.