Löve "Light vs. Shadow" Engine [0.4.3]

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
PriorBlue
Prole
Posts: 43
Joined: Fri Feb 28, 2014 3:46 am
Location: Munich, Germany

Löve "Light vs. Shadow" Engine [0.4.3]

Post by PriorBlue »

About:
Löve "Light vs. Shadow" is an engine for light and shadow calculations. It is easy to use, like the physic library in love2d. The work is not done yet, but here are the first results. The license is under MIT, so you can do what ever you want with this code.

Features:
  • polygon shadow calculation Preview
  • circle shadow calculation
  • image shadow calculation Preview
  • shadow blur
  • light color, range, smooth and glow Preview
  • ambient light
  • self shadowing on images with normal maps Preview
  • dynamic glow effect on images and circle/poly objects Preview Preview
  • generate flat or gradient normal maps Preview
  • convert height maps to normal maps Preview
  • generate a normal map directly from the image (usually gives poor results)
  • can now be used with camera translation (use: lightWorld.setTranslation(x, y))
  • shadow color and alpha (glass) Preview
  • directional light Preview
  • refractions + reflections Preview
  • chromatic aberration (press: c) Preview
  • material system (plastic, chrome, glass, magma etc.) Preview
  • several postshader effects (press: F10) Preview
  • Wiki
TODO:
  • image rotations (correct normal maps)
  • crystal reflection (chaotic)
Preview:


New features:


How to use example:

Code: Select all

require "light"

function love.load()
	-- create light world
	lightWorld = love.light.newWorld()
	lightWorld.setAmbientColor(15, 15, 31)

	-- create light
	lightMouse = lightWorld.newLight(0, 0, 255, 127, 63, 300)
	lightMouse.setGlowStrength(0.3)

	-- create shadow bodys
	circleTest = lightWorld.newCircle(256, 256, 32)
	rectangleTest = lightWorld.newRectangle(512, 512, 64, 64)
end

function love.update(dt)
	love.window.setTitle("Light vs. Shadow Engine (FPS:" .. love.timer.getFPS() .. ")")
	lightMouse.setPosition(love.mouse.getX(), love.mouse.getY())
end

function love.draw()
	-- update lightmap (doesn't need deltatime)
	lightWorld.update()

	-- draw background
	love.graphics.setColor(255, 255, 255)
	love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())

	-- draw lightmap shadows
	lightWorld.drawShadow()

	-- draw scene objects
	love.graphics.setColor(63, 255, 127)
	love.graphics.circle("fill", circleTest.getX(), circleTest.getY(), circleTest.getRadius())
	love.graphics.polygon("fill", rectangleTest.getPoints())

	-- draw lightmap shine
	lightWorld.drawShine()
end
Attachments
love2d_light_vs_shadow_engine_0.4.3.love
Latest Version
(411.02 KiB) Downloaded 3246 times
Last edited by PriorBlue on Tue Apr 08, 2014 5:55 pm, edited 21 times in total.
User avatar
OttoRobba
Party member
Posts: 104
Joined: Mon Jan 06, 2014 5:02 am
Location: Sao Paulo, Brazil

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by OttoRobba »

...

wow :ultrashocked:
User avatar
SiENcE
Party member
Posts: 806
Joined: Thu Jul 24, 2008 2:25 pm
Location: Berlin/Germany
Contact:

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by SiENcE »

Very great stuff! Thanks man. Nice inspirations.
User avatar
norubal
Party member
Posts: 137
Joined: Tue Jan 15, 2013 5:55 am

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by norubal »

Great, pretty and nice! :awesome:
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by Jeeper »

This is incredible, I have been intending to do something similar for a game that I am working on, and this will be a huge help!
Last edited by Jeeper on Fri Oct 01, 2021 3:17 pm, edited 1 time in total.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by Ranguna259 »

Awesome, it's much better to have a dedicated thread :megagrin: .
Moving on, I saw that the only argumanets available to newImage are "(world, image, x, y, width, height, offsetX, offsetY)", could you add rotation too ( I dunno what shearing factor is ) ? Since the shadow uses the per-pixel method you shouldn't have any problems on the shader part I think
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
WetDesertRock
Citizen
Posts: 67
Joined: Fri Mar 07, 2014 8:16 pm

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by WetDesertRock »

Looking into implementing this into the game I'm currently working on, and I have a couple questions. Forgive me if you've answered these on the other thread, feel free to redirect me there if the questions have been answered already there.

Is it possible to have a segment be a game object? Would I just use love.light.newPolygon(world, x1, y1, x2, y2) for the segment? Reason being that I have collision detection (and what will be shadow casting) based off of segments, and I want to know if I need to change that to use this library.
Also, are you going to do directional light sometime?
szensk
Party member
Posts: 155
Joined: Sat Jan 19, 2013 3:57 am

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by szensk »

Error
Cannot compile pixel shader code:
Line 2: error: Syntax error: "smooth" parse error

in function 'newShader'
light.lua:29: in function 'newWorld'
One must love AMD's error reporting.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by Ranguna259 »

WetDesertRock wrote: Is it possible to have a segment be a game object?
What do you mean segment ?
WetDesetRock wrote: Also, are you going to do directional light sometime?
Directional Light ?
szensk wrote:
Error
Cannot compile pixel shader code:
Line 2: error: Syntax error: "smooth" parse error

in function 'newShader'
light.lua:29: in function 'newWorld'
One must love AMD's error reporting.
Hmmm.. What do you think that is ? A problem with AMD shader compatibility or is something wrong with shader itself ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: Löve "Light vs. Shadow" Engine [Project Page]

Post by Jeeper »

Ranguna259 wrote:
WetDesertRock wrote: Is it possible to have a segment be a game object?
What do you mean segment ?
WetDesetRock wrote: Also, are you going to do directional light sometime?
Directional Light ?
szensk wrote:
Error
Cannot compile pixel shader code:
Line 2: error: Syntax error: "smooth" parse error

in function 'newShader'
light.lua:29: in function 'newWorld'
One must love AMD's error reporting.
Hmmm.. What do you think that is ? A problem with AMD shader compatibility or is something wrong with shader itself ?
No idea, me and my friend gets the same error. Both with AMD, while it works on nvidia.
Last edited by Jeeper on Fri Oct 01, 2021 3:15 pm, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests