Author Topic: fast 2D shadow engine in lua  (Read 4317 times)

0 Members and 1 Guest are viewing this topic.

Offline Jens_K

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 187
  • Rating: +52/-0
    • View Profile
fast 2D shadow engine in lua
« on: April 14, 2014, 11:34:20 am »
Hi, I've been working on this little shadow engine for the Nspire the last 2 days:
It dynamically calculates and renders the shadows of a variable number of objects, relative to the position of the light source and draws their illuminated sides.
With 6 objects, it runs smoothly with 12-16 frames per second on the handheld.


Controls:
- click to enable/disable mouse control
- press m to change the render mode
- press r to enable/disable the illuminated rims
- in the upper left corner, there's a little fps counter


Note: There are some bugs, if objects are too close to each other or if the light source is too close to an object (but I didn't encounter a crash yet)


I made this engine just for fun, I don't think I'll do something with it or improve it soon; so you can do anything you want with it (but giving credit would be nice ;) )
« Last Edit: April 14, 2014, 11:38:50 am by Jens_K »
Sorry for nonsense.

Projects:



Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: fast 2D shadow engine in lua
« Reply #1 on: April 14, 2014, 11:50:53 am »
Oh wow that looks real sexy ! :D
* Streetwalrus thinks you'd do great stuff if you programmed for Ndless ;)

Offline AnToX98

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 107
  • Rating: +10/-0
    • View Profile
Re: fast 2D shadow engine in lua
« Reply #2 on: April 14, 2014, 12:36:33 pm »
Looks super nice :D



My Lua projects :

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: fast 2D shadow engine in lua
« Reply #3 on: April 14, 2014, 06:22:08 pm »
Indeed, it sure looks very nice :)
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: fast 2D shadow engine in lua
« Reply #4 on: April 15, 2014, 01:22:40 pm »
Blinded by the Dark Nspire port soon? :D http://www.ticalc.org/archives/files/fileinfo/226/22637.html

This looks pretty nice. I wonder how fast is it on a real calc?
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Jens_K

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 187
  • Rating: +52/-0
    • View Profile
Re: fast 2D shadow engine in lua
« Reply #5 on: April 15, 2014, 01:48:21 pm »
Oh wow that looks real sexy ! :D
* Streetwalrus thinks you'd do great stuff if you programmed for Ndless ;)
Thanks, but I like lua! :-[  I'm kind of afraid of native programming; I have no experience with any C language yet... Are there some good tutorials out there?


Indeed, it sure looks very nice :)
Thanks! And thanks to your optimization tips, it runs great!  :)


Blinded by the Dark Nspire port soon? :D http://www.ticalc.org/archives/files/fileinfo/226/22637.html

This looks pretty nice. I wonder how fast is it on a real calc?
I don't know this game, but I looks like it would be possible to port with this engine! But you'd have to make a seperate algorithm to check if an object like an enemie is in the shadow or not; the engine only proviedes the vertices of the shadow polygons.
On my Nspire CX with OS 3.2 (don't ask me why I'm to lazy to update :P) it runs with ~14 FPS, which is pretty fast for Nspire lua ;)
Sorry for nonsense.

Projects:



Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: fast 2D shadow engine in lua
« Reply #6 on: April 15, 2014, 01:54:38 pm »
Seems quite nice. I bet it might be slower on 3.1, but thankfully, 3.6 can run Ndless so many people have switched. 14 FPS seems pretty fine IMHO (and higher would be problematic on the Click/Touchpad models anyway since motion blur would be too intense)
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: fast 2D shadow engine in lua
« Reply #7 on: April 15, 2014, 04:16:42 pm »
I don't know of any C tutorials in English, only French sorry. I'm sure someone else does. There is something to keep in mind, that you will not have event based programming in Ndless (unless you use particular libs which I doubt they would run on the Nspire).

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: fast 2D shadow engine in lua
« Reply #8 on: April 15, 2014, 06:26:27 pm »
@Jens :
I only quickly went through the code, but I believe that it can still be optimized. (Making math stuff in on.timer local, not redefining the gc-using function inside each on.paint call, etc.)
I'll go through it more in depth when I have some time, though, these days are pretty busy for me....
My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation