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

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Chroteus
Citizen
Posts: 89
Joined: Wed Mar 20, 2013 7:30 pm

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

Post by Chroteus »

WetDesertRock wrote: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 :)
This works nicely, thanks for your effort :)
I wonder, though, what about scaling? Seems like a bug.
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.4.3]

Post by Ranguna259 »

Scaling has a bug and this only works for geometry, since priorBlue is taking some vacation or somothing like that (he hasn't posted here in a while) we won't have a fixe unless someone looks into the code. I would but I haven't followed the progress of this project in a while so I'm unfamiliar with the code now..

EDIT: Found PriorBlue's pixel shadow shader, here it is, I don't know if it has translation or scalling problems but it works.
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
IndieLöver
Prole
Posts: 29
Joined: Mon Jun 10, 2013 8:49 am

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

Post by IndieLöver »

I have a few questions regarding your *awesome* shadow library.

Image
(Screenie from the example project)
1.Can I make the green rectangle get shadowed by the purple one? In my project I need to make the level's walls block the player's vision, while the walls that are seen still get drawn. Is this possible with your shadow engine?
2.Can the lighting be used to affect the game in some way, say, enemies that disappear when they are hit by light.
3.Also, Is there are full documentation about this shadow engine?


ps. I just learned how to post images in forums!

Thanks,
IndieLöver
User avatar
IndieLöver
Prole
Posts: 29
Joined: Mon Jun 10, 2013 8:49 am

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

Post by IndieLöver »

I would request something like this:
Image

An option to make the object not casting a shadow on the place it occupies.
That way the shadow casting walls could be drawn before shadows, but they would get shaded only by other walls.

Also, sorry about my english, I didn't put much thought into my grammar when posting this.. :roll:
Needless to say, english ain't my first language.
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.4.3]

Post by Ranguna259 »

IndieLöver wrote: 1.Can I make the green rectangle get shadowed by the purple one? In my project I need to make the level's walls block the player's vision, while the walls that are seen still get drawn. Is this possible with your shadow engine?
2.Can the lighting be used to affect the game in some way, say, enemies that disappear when they are hit by light.
3.Also, Is there are full documentation about this shadow engine?
IndieLöver wrote: 1.Can I make the green rectangle get shadowed by the purple one? In my project I need to make the level's walls block the player's vision, while the walls that are seen still get drawn. Is this possible with your shadow engine?
You'll need to use this.
IndieLöver wrote: 2.Can the lighting be used to affect the game in some way, say, enemies that disappear when they are hit by light.
It can but that is not part of the engine, you'll need to code this yourself.
IndieLöver wrote: 3.Also, Is there are full documentation about this shadow engine?
Yes.
IndieLöver wrote:I would request something like this:
Image

An option to make the object not casting a shadow on the place it occupies.
That way the shadow casting walls could be drawn before shadows, but they would get shaded only by other walls.

Also, sorry about my english, I didn't put much thought into my grammar when posting this.. :roll:
Needless to say, english ain't my first language.
You can use canvas for this, capture what is in the place it occupies into a canvas, cast the shadow, draw the canvas.
You can also use love.graphics.setStencil
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
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

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

Post by ArchAngel075 »

Greetings, im busy working on a game that benefits so much from this engine, but i was hoping if you have any advice on checking if a image or object is in any light of x intensity? At the moment I'm looking to use raycasts but it does not take in account the bending of light when it passes through slits, or the amount of light(intensity)
InsomniaNY
Prole
Posts: 4
Joined: Sat Aug 09, 2014 8:58 pm

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

Post by InsomniaNY »

First off, this is awesome!

I'm new to Love2D, so I apologize if this is a noob question, but I didn't see it addressed...

Is there a way to have a directional light point toward the mouse? I don't mean the position of the light, but rather the direction of an angled light - for example, if I wanted to have a character holding a flashlight, I'd have the light emanate from him or her and then have it point at my mouse....sort of like a raytrace between character (point A) and mouse (point B).

Using mouse.getX obviously doesn't work (though it does make for some funky controls) and I can't figure out if there's some type of formula that would allow me to accomplish it because I don't know how the direction is actually determined. For example, I found that "4.75" pointed the light straight to the right.

Thanks!
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

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

Post by ArchAngel075 »

how are you tracking your players position and facing angle?

say player is a table like so :

Code: Select all

local  player = {
 x = 1,
 y = 1,
}
now im going to assume you lock the camera to render over the player at all times, and that the player is centerd on the screen at 400,300
assume that the torch light is stored under a variable [torch].
now to make the light point at the mouse we simply do :

Code: Select all

local mouseP = {love.mouse.getPosition()}
local angleMouse_toPlayer = math.atan2( mouseP[2] - 300 , mouseP[1] - 400 ) --we use 300,400 as its where the player will render (@{y,x})
--now we set the light to just use the above angle!
torch.setDirection(angleMouse_toPlayer)
now also, if the player iss not at 400,300 at all times (centred) then we use world position but making sure to offset the mouse coordinates with camera offset :
assume the cameras offset is stored under variable [cameraOffset]

Code: Select all

local mouseP = {love.mouse.getPosition()}
local mouseP_offsetByCamera = {mouseP[1]+cameraOffset[1],mouseP[2]+cameraOffset[2]} 
-- this should offset the mouses local position to the "world" position.

local angleMouse_toPlayer = math.atan2( mouseP_offsetByCamera[2] - player.y , mouseP_offsetByCamera[1] - player.x )

torch.setDirection(angleMouse_toPlayer)

that should work, as its more or less what ive used in my own code, I included camera offset help too since it sort of got me stuck when i was working with a loose camera in the past.

Note that code above is untested in a actual project or environment and may not work as intended.
InsomniaNY
Prole
Posts: 4
Joined: Sat Aug 09, 2014 8:58 pm

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

Post by InsomniaNY »

ArchAngel075 wrote: now im going to assume you lock the camera to render over the player at all times, and that the player is centerd on the screen at 400,300
assume that the torch light is stored under a variable [torch].
now to make the light point at the mouse we simply do :

Code: Select all

local mouseP = {love.mouse.getPosition()}
local angleMouse_toPlayer = math.atan2( mouseP[2] - 300 , mouseP[1] - 400 ) --we use 300,400 as its where the player will render (@{y,x})
--now we set the light to just use the above angle!
torch.setDirection(angleMouse_toPlayer)
Thanks for the quick response!

Right now I'm messing with a platfomer that has a static window/camera (so not a side-scroller, but a single-screen-per-level type platformer).

So taking your code, I did the following:

Code: Select all

	lightMouse.setPosition(p.x, p.y)
	local mouseP = {love.mouse.getPosition()}
	local angleMouse_toPlayer = math.atan2( mouseP[2] - p.y , mouseP[1] - p.x)
	lightMouse.setDirection(angleMouse_toPlayer)
The light rotates around the player when I move the mouse, but it does not point at the mouse. I'm thinking maybe there's a difference between a top-down game and a platformer? I've never done a top-down game in any language...maybe I should find a tutorial for one so I can see what the math differences are between the two?

For example, when I move the mouse to the direct-right of my player, the angleMouse_toPlayer value is close to 0.0, which faces the light straight up. As I said before, facing the light to the right requires a "setDirection" value around 4.75 (-1.5 also works). Is there somewhere that explains what these values mean? Maybe then I can figure out what I need to do...they're just not making sense to me right now :(
InsomniaNY
Prole
Posts: 4
Joined: Sat Aug 09, 2014 8:58 pm

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

Post by InsomniaNY »

So I got it working, though I'm not exactly show why it works this way. Here's what I had to do to get it to work:

Code: Select all

	lightMouse.setPosition(p.x, p.y)
	mouseP = {love.mouse.getPosition()}
	angleMouse_toPlayer = math.atan2(mouseP[1] - p.x, mouseP[2] - p.y)
	lightMouse.setDirection(angleMouse_toPlayer + math.pi)
My origin point (0,0) is in the top-left corner, so I believe that's why I had to add pi to the direction, but I don't get why I had to flip the Y and X coordinates. I thought maybe LUA handles it differently than every other language, but it doesn't...it's supposed to by (y,x) in every documentation I find...so I'm perplexed. But like I said it works...perfectly. o.O

If it matters, I'm manually setting the window size like so:

Code: Select all

love.window.setMode(1152, 768)
I'm using 32x32 tiles, so those dimensions give me a 36x24 level.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest