Rendertextures performance

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

In the profiler you see the engine waiting for rendering so it might be the shader that is expensive.

As an experiment, switch to a simpler shader.

1 Like

As a general hint, you need to eliminate different parts to see where the bottleneck is. As sicher said, start with using a very simple shader. Be careful of the precision used for anything “many”, e.g. the fragment shader of the fullscreen passes. Then you can disable things like blending to see how that affects perf.

1 Like