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!
Shadow demo
Shadow demo
- 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.
Re: Shadow demo
Looks nice and runs at a solid 960 FPS on my PC
Also, as the height gets closer to the object, the shadow should get smaller.
Also, as the height gets closer to the object, the shadow should get smaller.
Re: Shadow demo
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.
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.
Re: Shadow demo
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.
~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.
Re: Shadow demo
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.
Hopefully system independent?????
Suspect your lower frame rate is due to vsync as I get ~600 fps on my donkey.
Re: Shadow demo
It rather works on Android.
This is what i get for the square example:
And this is what I get for the hollow example:
This is what i get for the square example:
And this is what I get for the hollow example:
Re: Shadow demo
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
give you a nice little square?
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 )
Re: Shadow demo
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
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Shadow demo
Does
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)?
Code: Select all
polygon = { 100,100, 50,100, 50,50, 100,50 }
love.graphics.polygon( 'line', polygon )
(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)?
Re: Shadow demo
It's something in love-android, I think, the same code works fine here
Anyway it seems that it adds the center here too
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
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Who is online
Users browsing this forum: No registered users and 47 guests