Multiple Shader and specifically a Moonshine obeservation

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
dogstar25
Prole
Posts: 3
Joined: Fri Aug 28, 2020 9:10 pm

Multiple Shader and specifically a Moonshine obeservation

Post by dogstar25 »

Hi,

I was doing some quick and simple performance type testing with Love to see if I wanted to move forward with it. I was playing around with shaders and in particular, the Moonshine lua code.

My test simulates 10,000 objects being drawn on each loop. The performance looks great when I place my drawing code within the moonshine effects shader function, but if I have my loop outside,(which think is more likely for an actual game) it comes to a standstill. I can see that Moonshine is chaining together 1 or more shaders and is using buffers and canvases in the background. My question is...In love2d shader world, is it expected that I draw all of my gameObjects that require a particular shader within their own loop? If so, this would obviously affect the design of the gameObject storage structure. Here's my code. The "outside" loop is commented out for now. Even the 20 iterations brings the program down to 10 FPS. Otherwise, the 10,000 loop stays at 60fps. Thanks for any insight.

Code: Select all

local moonshine = require 'moonshine'

function love.load()

	
	success = love.window.setFullscreen(true)

	effect = moonshine(moonshine.effects.glow)
			.chain(moonshine.effects.godsray)

	ring = love.graphics.newImage("ring.png")


end

function love.update()

	if love.keyboard.isDown("space") then
        love.event.push('quit')
    end

end

function love.draw()

	fps = love.timer.getFPS()


	-- for i=1,20 do
		effect(function()
			for i=1,10000 do
				love.graphics.setColor(.2, .2, .7, 1)
				number = love.math.random(1,1000);
				love.graphics.draw(ring, number,number,math.rad(0), 1,1)
			end
		end)
	-- end

	love.graphics.print(fps, 2, 2)

end

User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Multiple Shader and specifically a Moonshine obeservation

Post by pgimeno »

Hi dogstar25, welcome to the forums.

Switching Löve canvases (which are basically a user-frendly interface to GL FBO's) is a costly operation because it forces sequential processing of GL commands. This has a serious performance impact because OpenGL's speed comes mainly from the ability to process commands in parallel.

Moonshine is switching canvases in order to process effects. If you can figure out a way of reducing canvas switching to a minimum without using Moonshine, just using "raw" Löve shaders and maybe your own canvases, perhaps you can get away with not having to draw all the objects that use the same shader at once. Using Moonshine, the only way is drawing them together.

Either way, my guess is that speed will be optimal if you draw as many similar objects together as possible, so it's good to aim for that, no matter if you use Moonshine or not.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Multiple Shader and specifically a Moonshine obeservation

Post by slime »

20 * 10000 is 200,000 individual calls to love.graphics.draw. Most of them will be batched together automatically by LÖVE (since only the color and transformation state change), but even so that's a lot of work being done each frame, with little purpose. Did you mean for your code to do that?
dogstar25
Prole
Posts: 3
Joined: Fri Aug 28, 2020 9:10 pm

Re: Multiple Shader and specifically a Moonshine obeservation

Post by dogstar25 »

@slime, For my test, when I uncomment the 1 to 20 loop , I comment out the 1 to 10000 loop, so it only does the draw 20 times. Even at only 20, moonshine is bogging it down to 15 FPS. I'm just trying different tests to see what the performance looks like. Other than this moonshine issue, I'm super-surprised at the love2d performance. My other game dev is all c++, using SDL2 which is fast, but c++ has gotten sooo crazy complex.

@pgimeno Thanks, I think that answers my question.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Multiple Shader and specifically a Moonshine obeservation

Post by slime »

Ah, in that case I'd expect most of the performance drop to be caused by the specific effects you're using being rendered to screen_width * screen_height number of pixels pixels at least 20 times (a GPU bottleneck, and more than 20 times if the effects are doing more than one full-screen pass). Depending on the effects, it may be possible to optimize that sort of thing significantly.

Canvas switching might also be a factor, but I'd expect the above to have more of an impact.
Post Reply

Who is online

Users browsing this forum: xxl and 69 guests