June 25, 2019, 02:26:45 am

## News:

Now with 20% more walruses

## [TI-Nspire] Lua3D Smooth Terrain Demonstration

Started by Tag365, March 31, 2016, 08:47:19 pm

0 Members and 1 Guest are viewing this topic.

#### Tag365

##### March 31, 2016, 08:47:19 pmLast Edit: April 24, 2016, 05:55:12 am by DJ Omnimaga
This is a Lua program demonstrating smooth voxel terrain on the TI-Nspire. Yes, you read it right, smooth voxel terrain on the TI-Nspire. You can modify and sculpt the terrain, but only inside the zone marked by white lines. You can also move and rotate the camera.

Here is a screenshot:

Lua3D Smooth Terrain Demonstration

#### Lionel Debroux

##### March 31, 2016, 08:49:41 pm #1
Looks quite good

And thanks for cross-posting here. I'm not staff, but believe me, you'll garner more attention on CodeWalrus (and TI-Planet)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TIEmu and TILP.

#### KermMart̕ian

##### March 31, 2016, 08:52:45 pm #2
Yes, Lionel advocated posting this here from SAX, since Cemetech purportedly has the least TI-Nspire activity in the community. You can find the original topic here, if you're looking for it. Awesome work, Tag365.

#### KermMart̕ian

##### March 31, 2016, 08:54:47 pm #4
Actually, it's just the two users from Cemetech that came over here to comment.

##### March 31, 2016, 08:56:15 pm #5
It looks very nice indeed

Reading the code very quickly, I suggest making some light modifications:
all the math.* functions you use can be localized, and since we want the best performance especially for such a program, it will be a bit better.
So, at the top of the file, for instance, do: local mathfloor, mathceil, mathmin, mathmax, mathabs = math.floor, math.ceil, math.min, math.max, math.abs
and use those everywhere instead (I see you've already used this technique for abs at some point, though)
Co-founder & co-administrator of TI-Planet and Inspired-Lua

#### Caleb Hansberry

##### March 31, 2016, 08:59:57 pm #6
That is real nice work!

##### March 31, 2016, 09:10:09 pm #7
That's fancy!
Does this qualify as a signature?

#### DJ Omnimaga

##### April 01, 2016, 02:41:22 am #8 Last Edit: April 01, 2016, 05:59:24 am by DJ Omnimaga
Quote from: KermMartian on March 31, 2016, 08:54:47 pm
Actually, it's just the two users from Cemetech that came over here to comment.
The CW users tend to be quiet outside IRC during weekday afternoons for some reasons  (which is ironic, considering most users live in Europe)

Quote from: Tag365 on March 31, 2016, 08:47:19 pm
This is a Lua program demonstrating smooth voxel terrain on the TI-Nspire. Yes, you read it right, smooth voxel terrain on the TI-Nspire. You can modify and sculpt the terrain, but only inside the zone marked by white lines. You can also move and rotate the camera.

Here is a screenshot:

Lua3D Smooth Terrain Demonstration
This looks really impressive, even more so by the fact it seems to be in Lua, which isn't known for its high speeds. I don't have time to test this right now, but I am wondering how is the frame rate like?

EDIT: Which OS does this require, by the way? Because on OS 3.6 I am getting an error on launch. It says in very large text fonts:

QuotePage 1.1 has encountered an error.

Line 2409:
attempt to call method
'setBackgroundColor' (a nil value)

#### Jim Bauwens

##### April 01, 2016, 09:49:31 am #9 Last Edit: April 01, 2016, 12:05:18 pm by Jim Bauwens
Interesting project!

I've tested it on my handheld, but sadly rendering per frame takes a couple of seconds. You probably tested on the computer or iPad software? Edit: I see that you mentioned this in your readme.

Looking at the code, you should try to avoid making tables to store data during rendering, as allocating data from the heap is an expensive operation. Of course, it does become more complex that way to store (for example) vector points, but you really do get a good speedup. The price being that your code gets larger and more messy. If you can avoid certain function calls, you should do that too.

#### Tag365

##### April 01, 2016, 02:39:46 pm #10 Last Edit: April 01, 2016, 02:52:31 pm by Tag365
Quote from: Jim Bauwens on April 01, 2016, 09:49:31 am
Interesting project!

I've tested it on my handheld, but sadly rendering per frame takes a couple of seconds. You probably tested on the computer or iPad software? Edit: I see that you mentioned this in your readme.

I wasn't expecting it to run fast at all on an actual handheld device.

On Touch Lua, the framework that the library was first implemented, it would also take seconds to draw a frame using a script like this with the huge amount of triangles being rendered to the screen. Though, that was caused by Touch Lua's drawing functions being slow to begin with and me running my scripts on an iPhone 4s (newer devices are much more powerful than that device). I recall being able to draw only about 9,000 triangles a second, and 20,000 rectangles a second (this was the best case scenario as I was running a benchmark script to get that info.), and drawing images lagging up my scripts.

On the Love framework running on my computer, my games would slow down to 30 fps when drawing around 3,110 filled and textured triangles (about 93,510 triangles a second). This is not really a lot (at least for the block building game I was making, the chunk rendering distance is very low), but it was a significant speed up from what it was on Touch Lua. Also, unlike Touch Lua it was also drawing textured triangles (something which I have tried on Touch Lua, but it was slow and it was not complete).

Quote from: Jim Bauwens on April 01, 2016, 09:49:31 am
Looking at the code, you should try to avoid making tables to store data during rendering, as allocating data from the heap is an expensive operation. Of course, it does become more complex that way to store (for example) vector points, but you really do get a good speedup. The price being that your code gets larger and more messy. If you can avoid certain function calls, you should do that too.

Ok, I will consider doing that. I will also see if doing similar optimizations will also increase rendering speed on other frameworks.
By the way, does moving local variable declarations outside a loop make the script run any faster?

#### DJ Omnimaga

##### April 01, 2016, 03:45:27 pm #11
It doesn't run at all on OS 3.6

#### Tag365

##### April 01, 2016, 03:56:45 pm #12
Quote from: DJ Omnimaga on April 01, 2016, 03:45:27 pm
It doesn't run at all on OS 3.6

Tell me what I need to fix to make it work correctly. Also I updated it so check that version to see if that works correctly.

#### DJ Omnimaga

##### April 01, 2016, 03:59:16 pm #13
Quote from: Tag365 on April 01, 2016, 03:56:45 pm
Quote from: DJ Omnimaga on April 01, 2016, 03:45:27 pm
It doesn't run at all on OS 3.6

Tell me what I need to fix to make it work correctly. Also I updated it so check that version to see if that works correctly.

Line 2409:
attempt to call method
'setBackgroundColor' (a nil value)

#### Tag365

##### April 01, 2016, 04:23:28 pm #14
I have fixed compatibility with apiLevel < 2.4. It should now work correctly.