Luven - Minimalist light engine

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
ChicoGameDev
Citizen
Posts: 71
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Luven - Minimalist light engine

Post by ChicoGameDev »

Hi,

Yes since there is no graphic card it hurts ! I test now Luven on my MacBook Air and I feel the slow.

Thanks a lot for your example ! Very inspiring, but I wonder, actually I can manage light powers dynamically and give the user the possibility to add flickering lights that Luven manage for them.

How could this be achievable with your example ? And I read about the fact that canvas switching was not so good for performance either. What could you tell me on that ?


Many many thanks for your insights.


Regards
Lionel Leeser

Luven : https://github.com/halsten-dev/Luven

--

Always keep Game Dev as a passion.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Luven - Minimalist light engine

Post by grump »

ChicoGameDev wrote: Sun Feb 24, 2019 8:42 am I can manage light powers dynamically and give the user the possibility to add flickering lights that Luven manage for them.

How could this be achievable with your example ?
It's just a quick sketch, designed to be simple and run fast. How you render the lights is up to you: static textures are fast and allow for hundreds of light sources, fully dynamic is slow and requires powerful hardware when using more than a few lights. You could cache different light source types in a Canvas, that way it only slows down when a light's parameters change (which you want to avoid).

Flickering can be achieved by modulating the color when drawing a light. Light power can be approximated with brightness modulation and scaling. Finding a compromise between quality and speed is key.
And I read about the fact that canvas switching was not so good for performance either.
A few switches are inevitable for any non-trivial rendering. It's still a lot faster and more flexible than your approach. By rendering to a lightmap, you have also decoupled lighting from the rest of the graphics, gaining flexibility and allowing the use of the shaders for other effects.
Nelvin
Party member
Posts: 124
Joined: Mon Sep 12, 2016 7:52 am
Location: Germany

Re: Luven - Minimalist light engine

Post by Nelvin »

The biggest optimization for the canvas approach is a lower resolution canvas for the lightmap - it's probably rendered over the final display using filtering anyway, so you may get away with way lower resolutions than your actual display, saving huge amounts of bandwidth on the GPU.
User avatar
ChicoGameDev
Citizen
Posts: 71
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Luven - Minimalist light engine

Post by ChicoGameDev »

Thanks grump,

I'll work on a new update and this will probably be better for everybody !
Nelvin wrote: Sun Feb 24, 2019 9:27 am The biggest optimization for the canvas approach is a lower resolution canvas for the lightmap - it's probably rendered over the final display using filtering anyway, so you may get away with way lower resolutions than your actual display, saving huge amounts of bandwidth on the GPU.
You mean having a canvas of the size of the camera ?

Thanks for participating !


Regards
Lionel Leeser

Luven : https://github.com/halsten-dev/Luven

--

Always keep Game Dev as a passion.
Nelvin
Party member
Posts: 124
Joined: Mon Sep 12, 2016 7:52 am
Location: Germany

Re: Luven - Minimalist light engine

Post by Nelvin »

What I meant was a canvas of a size that's enough for your requirements, whatever that means depends on the game.

I've just added the changes to grumps sample to show what I mean.

Code: Select all

local lg = love.graphics

local gradient = love.image.newImageData(128, 128)
gradient:mapPixel(function(x, y)
    local c = 1 - math.sqrt((64 - x) ^ 2 + (64 - y) ^ 2) / 64
    return c, c, c, 1
end)
local light = lg.newImage(gradient)

local lightMapScale = 0.1
local width, height = love.window.getMode()

local lightMap = lg.newCanvas( width * lightMapScale, height * lightMapScale)
local background = lg.newImage('Background.png')


function love.draw()
    lg.setCanvas(lightMap)
    lg.setBlendMode('add')
    lg.clear(.2, .2, .2)
    lg.scale( lightMapScale )
    for i = 1, 32 do
        local x = 336 + 400 * math.sin(love.timer.getTime() * .4 + i) + 200 * math.cos(i)
        local y = 236 + 300 * math.sin(love.timer.getTime() - i) + 100 * math.sin(x * .01)
        lg.draw(light, x, y)
    end
    lg.scale( 1/lightMapScale )

    lg.setCanvas()
    lg.draw(background, 0, 0, 0, .5, .5)
    lg.setBlendMode('multiply', 'premultiplied')
    lg.draw(lightMap, 0, 0, 0, 1/lightMapScale, 1/lightMapScale )
    lg.setBlendMode('alpha')
    lg.print(love.timer.getFPS())
end

Scaling the lightmaps width/height to 10% in this sample still does not look that bad and the number of pixels of the canvas was reduced by 99%, i.e. the update of the lightmap itself consumes very little bandwidth on the GPU.
User avatar
ChicoGameDev
Citizen
Posts: 71
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Luven - Minimalist light engine

Post by ChicoGameDev »

Hi again,

That's great, thanks for sharing !

Have a nice day :D !


Regards
Lionel Leeser

Luven : https://github.com/halsten-dev/Luven

--

Always keep Game Dev as a passion.
Yeahyay
Prole
Posts: 7
Joined: Sat Feb 23, 2019 1:58 am
Contact:

Re: Luven - Minimalist light engine

Post by Yeahyay »

ChicoGameDev wrote: Sat Feb 23, 2019 5:29 am
Yeahyay wrote: Sat Feb 23, 2019 2:04 am Would you be able to implement cone lights as well?
Hum, it would be useful only on 2d side-scroller no ? Could you please elaborate a little bit ?
The light would have a controllable width with a max value essentially being a normal light. This would allow for directional lighting such as flash lights.
User avatar
ChicoGameDev
Citizen
Posts: 71
Joined: Thu Feb 14, 2019 6:02 pm
Location: Switzerland
Contact:

Re: Luven - Minimalist light engine

Post by ChicoGameDev »

Hi,
Yeahyay wrote: Sun Feb 24, 2019 3:31 pm The light would have a controllable width with a max value essentially being a normal light. This would allow for directional lighting such as flash lights.
Maybe later yeah! Please feel free to make an feature request in the repo : https://github.com/chicogamedev/Luven/issues (So I keep a trace :rofl: )

I'm actually making great progress on optimization on the experimental branch, and it's my top priority for the moment.
Nelvin wrote: Sun Feb 24, 2019 11:56 am Scaling the lightmaps width/height to 10% in this sample still does not look that bad and the number of pixels of the canvas was reduced by 99%, i.e. the update of the lightmap itself consumes very little bandwidth on the GPU.
I tried to implement your idea of scaling but with, on top of that, a camera that have already scaling. I'm a bit lost in all those differents coordinates system... Have you something to tell me to help me making order in all that ?

Thanks in advance.


Regards
Lionel Leeser

Luven : https://github.com/halsten-dev/Luven

--

Always keep Game Dev as a passion.
Nelvin
Party member
Posts: 124
Joined: Mon Sep 12, 2016 7:52 am
Location: Germany

Re: Luven - Minimalist light engine

Post by Nelvin »

ChicoGameDev wrote: Sun Feb 24, 2019 7:28 pm
Nelvin wrote: Sun Feb 24, 2019 11:56 am Scaling the lightmaps width/height to 10% in this sample still does not look that bad and the number of pixels of the canvas was reduced by 99%, i.e. the update of the lightmap itself consumes very little bandwidth on the GPU.
I tried to implement your idea of scaling but with, on top of that, a camera that have already scaling. I'm a bit lost in all those differents coordinates system... Have you something to tell me to help me making order in all that ?
Hm, not sure - I don't use camera alike systems alot or transform objects at all (my project is using Löve 0.10.2).

But in the end, what's required would be to transform any light on the screen to just the scaled down canvas so I guess what you'd have to do is to add the scaling to your camera transform and use the resulting transform to render all the lights to the canvas, then pop the transform (including the one used by the camera) and render the lightmap scaled to the full screen.
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Luven - Minimalist light engine

Post by yetneverdone »

Hmmm since it has camera, what if don't render or process light when outside the camera boundaries?

Also, does it really have to integrate camera to lighting system? What if users use other full-featured camera?
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests