Why does my shader increases my CPU usage (1% -> 15%)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
oats_2d
Prole
Posts: 1
Joined: Fri May 27, 2016 4:27 am

Why does my shader increases my CPU usage (1% -> 15%)

Post by oats_2d »

Hi.

I'm new to GLSL, so I suspect I've done something silly here. I have a very basic shader.

Code: Select all

vec4 effect(vec4 color, sampler2D texture, vec2 texture_coords, vec2 screen_coords) {
    int blur_size = 16;
    float x_pixel_size = 1.0 / 800.0;
    float y_pixel_size = 1.0 / 600.0;
    vec4 sum;
    for (int i = -blur_size; i < blur_size; i++) {
        for (int k = -blur_size; k < blur_size; k++) {
            vec2 offset_pos = texture_coords + vec2(i * x_pixel_size, k * y_pixel_size);
            sum += texture2D(texture, offset_pos);
        }
    }
    return sum;
}
When I use the shader, however, my CPU usage increases many times over the normal usage for the game. My understanding is that the shader should run on the GPU, so why does this happen?

I draw to a canvas then render the canvas using the shader.

Code: Select all

	love.graphics.setCanvas(canvas)
	love.graphics.clear()
	local objects = collision_sim.objects
	for i = 1, #objects do
		local object = objects[i]
		if object.is_colliding then
			love.graphics.setColor(220, 120, 120)
		else
			love.graphics.setColor(255, 255, 255)
		end
		love.graphics.rectangle(
			"fill",
			object.x,
			object.y,
			object.width,
			object.height
		)
	end
	love.graphics.setCanvas()
	love.graphics.setColor(255, 255, 255)
	love.graphics.setShader(cool_effect)
	love.graphics.draw(canvas)
	
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 63 guests