Page 3 of 12

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

Posted: Mon Mar 10, 2014 12:12 am
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

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

Posted: Mon Mar 10, 2014 2:41 am
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.

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

Posted: Mon Mar 10, 2014 3:14 am
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.

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

Posted: Mon Mar 10, 2014 5:32 pm
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 :)

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

Posted: Sat Mar 15, 2014 7:17 am
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 ?

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

Posted: Sat Mar 15, 2014 2:27 pm
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".

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

Posted: Sun Mar 16, 2014 12:35 am
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

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

Posted: Sun Mar 16, 2014 11:51 am
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.

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

Posted: Sun Mar 16, 2014 9:57 pm
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

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

Posted: Wed Mar 19, 2014 8:55 pm
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 ?