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

Showcase your libraries, tools and other projects that help your fellow love users.
WetDesertRock
Citizen
Posts: 67
Joined: Fri Mar 07, 2014 8:16 pm

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

Post by WetDesertRock »

Finding issues when using this in conjunction with hump's camera. Any ways I can get this to work?

Code: Select all

require('light')
local loader = require("libraries/AdvTiledLoader.Loader")
Camera = require("libraries/hump.camera")

function love.load()
    loader.path = "maps/"
    map = loader.load("secondundo")
    lightWorld = love.light.newWorld()
    lightWorld.setAmbientColor(15, 15, 31)
	-- create light
    lightMouse = lightWorld.newLight(0, 0, 255, 127, 63, 300)
    lightMouse.setGlowStrength(.5)
    lightMouse.setRange(800)
	
    polyTest = lightWorld.newPolygon(100, 100, 400, 250,100, 100)
	
     cam = Camera(300,300)
end

function love.update(td)
    lightMouse.setPosition(cam:mousepos())
end

function love.draw()
    cam:attach()
    lightWorld.update()
    love.graphics.setColor(255, 255, 255)
    map:draw()
    lightWorld.drawShadow()
    love.graphics.setColor(63, 255, 127)
    love.graphics.line(100, 100, 400, 250)
    lightWorld.drawShine()
    cam:detach()
end
User avatar
PriorBlue
Prole
Posts: 43
Joined: Fri Feb 28, 2014 3:46 am
Location: Munich, Germany

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

Post by PriorBlue »

WetDesertRock wrote:Finding issues when using this in conjunction with hump's camera. Any ways I can get this to work?
I think the problem is the camera translation, so this should work:

Code: Select all

function love.draw()
    cam:attach()
    -- set the x, y position of the camera here
    lightWorld.setTranslation(cameraX, cameraY)
    lightWorld.update()
    love.graphics.setColor(255, 255, 255)
    map:draw()
    lightWorld.drawShadow()
    love.graphics.setColor(63, 255, 127)
    love.graphics.line(100, 100, 400, 250)
    lightWorld.drawShine()
    cam:detach()
end
@Snuux: löve is perfect for learning the pixel shader basics. At first, just try to program some color filters (like color to b/w or sephia). Than a bloom filter is a nice experience because you must combine different shaders and use different techniques. And at least you should try a few calculations with normal maps (but this is more necessary in 3D programming). The best way of learning for me was experimenting with other scripts.
WetDesertRock
Citizen
Posts: 67
Joined: Fri Mar 07, 2014 8:16 pm

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

Post by WetDesertRock »

What I found for this is that if I was going with my original 300,300 camera location, I'd have to do

Code: Select all

    lightWorld.setTranslation(-100,0)
to make everything line up.
Divide by -3 makes sense, so I tried doing it with the camera location at 200,200). The working numbers then became:

Code: Select all

    lightWorld.setTranslation(-200,-100)
From testing, screen width/height changes this for sure.
WetDesertRock
Citizen
Posts: 67
Joined: Fri Mar 07, 2014 8:16 pm

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

Post by WetDesertRock »

Found that the problem was with hump's translation. Probably not even a problem, just me misunderstanding. Anyways, this is a function that takes a hump camera and gets the reverse translation that the light engine needs. Works great for me.

Code: Select all

function getLightTranslation(c)
    local tx,ty = love.graphics.getWidth()/(2*c.scale), love.graphics.getHeight()/(2*c.scale)
    tx = tx-c.x
    ty = ty-c.y
    return -tx,-ty
end

Great job with it, thats for the tip :)
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

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

Post by ArchAngel075 »

How would one go about using the Engine to do also LoS?
Ie not only draw shadows etc but also track what isnt "seen" by the light? Else must one use another program or engine to achieve this ?
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

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

Post by Jeeper »

ArchAngel075 wrote:How would one go about using the Engine to do also LoS?
Ie not only draw shadows etc but also track what isnt "seen" by the light? Else must one use another program or engine to achieve this ?
If you draw the shadow on top of everything and have it be completely black, it will block out everything "not seen".
User avatar
PriorBlue
Prole
Posts: 43
Joined: Fri Feb 28, 2014 3:46 am
Location: Munich, Germany

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

Post by PriorBlue »

So, i added directional light functionality. You just have to create a light object and change the angle/direction.
(Press "L" in the demo)

Image

Code example:

Code: Select all

function love.load()
	-- set the angle of the light-cone to 45° (default: Pi * 2)
	light.setAngle(3.14 / 4.0)
	-- set the direction of the light-cone (default: 0)
	light.setDirection(3.14)
end
Last edited by PriorBlue on Sun Mar 16, 2014 9:10 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 [0.3.0]

Post by Ranguna259 »

Awesome, this is the first Light system I've seen that supports directional lightning and that works. We got endless possibilities in here.
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
PriorBlue
Prole
Posts: 43
Joined: Fri Feb 28, 2014 3:46 am
Location: Munich, Germany

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

Post by PriorBlue »

(Movable) refraction's and reflection's are added now. You can use them as glass or even water. (Press "0" to include a refraction box)

At the moment the effect is included as postshader, so it's only working when you write the entire scene in a canvas and set it before you draw the refraction/reflection channel (or use my postshader system :)).

Refraction:
Image

Refraction + Reflection:
Image

Code example:

Code: Select all

function love.load()
	-- set the global refraction strength to 16 (default: 8)
	lightWorld.setRefractionStrength(16.0)
	-- set the global reflection strength to 32 (default: 16)
	lightWorld.setReflectionStrength(32)
	-- set the global reflection visibility to 0.5 (default: 1.0)
	lightWorld.setReflectionVisibility(0.5)
	-- create a refraction from a normal map
	refraction = lightWorld.newRefraction(imgNormal, x, y)
	-- create a refraction from a height map and choose the strength (default: 1.0)
	refraction = lightWorld.newRefractionHeightMap(imgHeightMap, x, y, strength)
	-- move the normal map texture within the boundary
	refraction.setTileOffset(x, y)
end

function love.draw()
	-- set your canvas
	love.graphics.setCanvas(myCanvas)

	-- draw scene objects

	-- draw the reflection
	lightWorld.drawReflection()

	-- draw the refraction
	lightWorld.drawRefraction()

	-- draw Canvas
	love.graphics.setCanvas()
	love.graphics.draw(myCanvas)
end
I added functionality to the glow color channels.

Dynamic glow:
Image

Chromatic aberration effect:
Image

How to use the new glow:
color on diffuse image = Glow Color (+brightness)
red-channel = start brightness
green-channel = end brightness
blue-channel = delay

Examples:
Image
Last edited by PriorBlue on Wed Mar 19, 2014 10:14 pm, edited 2 times 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 [0.3.3]

Post by Ranguna259 »

Love all the new work, but can you make the refraction/reflection shader still ?
In it's current state it just lookes like water, to make it look like glass it needs to be fixed, can you do that ?
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.
Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests