I implemented a gaussian blur shader and now I’m concerned with the performance. When profiling I see that the part that costs the most is ‘engine’ so I guess there is a lot of overhead when rendering. I’m not sure how easy it is to understand my code but the basic idea is that I render everything that is going to be blured to a rendertexture. I then use that texture as input for the blur shader and draw twice (horizontal and vertical) to a new rendertexture that is downsampled for better performance. And in the end I render everything to a GUI box that covers the screen.
So my question is if anyone have an idea on how to optimize this or what is causing the bad performance.
if blur then
render.disable_render_target(self.screen_target)
-- Horizontal pass
-- Enable
render.enable_render_target(self.blur_target)
render.enable_texture(0, self.screen_target, render.BUFFER_COLOR_BIT)
-- Draw
local constants = render.constant_buffer()
constants.sample_area = vmath.vector4(BLUR_VALUE * 1.0, 0, 0, 0)
render.draw(self.blur_pred, constants)
-- Disable
render.disable_render_target(self.blur_target)
render.disable_texture(0, self.screen_target)
-- Vertical Pass
-- Enable
render.enable_render_target(self.screen_target)
render.enable_texture(0, self.blur_target, render.BUFFER_COLOR_BIT)
-- Draw
constants = render.constant_buffer()
constants.sample_area = vmath.vector4(0, BLUR_VALUE * 1.0, 0, 0)
render.draw(self.blur_pred, constants)
-- Disable
render.disable_render_target(self.screen_target)
render.disable_texture(0, self.blur_target)
-- Enable
render.enable_material("gui")
render.enable_texture(0, self.screen_target, render.BUFFER_COLOR_BIT)
-- Draw
render.draw(self.blur_pred)
-- Disable
render.disable_material("gui")
render.disable_texture(0, self.screen_target)
end