Shadow demo

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Shadow demo

Post by Ref »

Shadows in 2D? Oxymoron?
Thought I'd just try to simulate shadows from first principles.
Expected a bigger hit in fps from such a simple approach (line projection) but turns out not to be as bad as 'fill' or 'text'.
Probably not too good for a lot of objects as it uses trig functions (atan2,sin,cos).
Enjoy!
Attachments
shadow2.love
Added new object & moved shadow to library
(2.68 KiB) Downloaded 269 times
shadow.love
Simple polygon shadow script
(1.55 KiB) Downloaded 273 times
Last edited by Ref on Thu Jan 10, 2013 10:19 pm, edited 1 time in total.
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: Shadow demo

Post by 10$man »

Looks nice and runs at a solid 960 FPS on my PC :D

Also, as the height gets closer to the object, the shadow should get smaller.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Shadow demo

Post by Ref »

Probably right about height.
Still, pretty boring demo.
Was wondering how to create a shadow for a hollow polygon.
Recalled someone asking about how to create a hollow square that got a number of responses.
Didn't see how any of the suggested approaches would be easy to create a shadow for but than the light dawned - really simple.
Can just use the same shadow function with a simple poly drawing.
Care to guess how?
(Hit 'f' key in the attached demo to see how I did it.)
fps still good.
Now the hard part - how to do something useful this this.
Attachments
hollow_poly_shadow.love
Simple polygon shadow function
(1.72 KiB) Downloaded 170 times
Last edited by Ref on Thu Jan 10, 2013 10:13 pm, edited 2 times in total.
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Re: Shadow demo

Post by Ubermann »

Pretty interesting IMO.

~60 FPS in my box.

I guess if it works in Android.
If you were not using any OS specific thing, I don't know any reason why it wouldn't work in Android.
Let me try it and will give you feedback.
Last edited by Ubermann on Tue Jan 08, 2013 4:25 pm, edited 1 time in total.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Shadow demo

Post by Ref »

Just a straight forward Love approach with nothing special.
Hopefully system independent?????
Suspect your lower frame rate is due to vsync as I get ~600 fps on my donkey.
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Re: Shadow demo

Post by Ubermann »

It rather works on Android.
This is what i get for the square example:
njRZW.png
njRZW.png (6.27 KiB) Viewed 225 times

And this is what I get for the hollow example:
FOZ14.png
FOZ14.png (7.01 KiB) Viewed 225 times
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Shadow demo

Post by Ref »

Very interesting!
Evidently, love.graphics.polygon has a problem for you.
Updated version of script with added figure in original posting but has nothing to do with your problem.
If you can draw a figure using love.graphics.polygon( 'fill', polygon ), you can create a shadow for it
using shadow.polygon( polygon, light ) where light = { x = #, y = #, height = # }.
Question:
Does

Code: Select all

polygon = { 100,100, 50,100, 50,50, 100,50 }
love.graphics.polygon( 'fill', polygon )
give you a nice little square?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Shadow demo

Post by Nixola »

I have to add a fifth vertex (100, 100) to the table to get a nice square on my LG Optimus L5
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Shadow demo

Post by Ref »

Does

Code: Select all

polygon = { 100,100, 50,100, 50,50, 100,50 }
love.graphics.polygon( 'line', polygon )
give you a closed figure?
(it does for me on window 7 and 'fill' gives me a closed filled figure.)

Ubermann's example seems to be adding the polygon's center coordinates as the last point.

I have no problems with this using Love 0.8 or lovejit.

The WIKI example doesn't use an additional point to close the polygon.

Anybody know what's going on here or have I miss something here (as usual)?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Shadow demo

Post by Nixola »

It's something in love-android, I think, the same code works fine here
Anyway it seems that it adds the center here too
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests