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:
(http://vignette3.wikia.nocookie.net/touchlua/images/b/ba/TI-Nspire_Lua_3D_Smooth_Terrain.png/revision/latest?cb=20160331203651)
(http://vignette2.wikia.nocookie.net/touchlua/images/8/89/TI-Nspire_Lua_3D_Smooth_Terrain_2.png/revision/latest?cb=20160331203743)
Download:
(https://www.cemetech.net/img/icon/dl.gif) Lua3D Smooth Terrain Demonstration (http://www.cemetech.net/programs/index.php?mode=file&id=1448)
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) ;)
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 (https://www.cemetech.net/forum/viewtopic.php?t=12641&highlight=), if you're looking for it. Awesome work, Tag365.
This thread got a reply very fast, this forum must be very popular. I fixed the download link as well.
Actually, it's just the two users from Cemetech that came over here to comment. :D
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 :P (I see you've already used this technique for abs at some point, though)
That is real nice work!
That's fancy! :thumbsup:
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. :D
The CW users tend to be quiet outside IRC during weekday afternoons for some reasons (which is ironic, considering most users live in Europe) :P
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:
(http://vignette3.wikia.nocookie.net/touchlua/images/b/ba/TI-Nspire_Lua_3D_Smooth_Terrain.png/revision/latest?cb=20160331203651)
(http://vignette2.wikia.nocookie.net/touchlua/images/8/89/TI-Nspire_Lua_3D_Smooth_Terrain_2.png/revision/latest?cb=20160331203743)
Download:
(https://www.cemetech.net/img/icon/dl.gif) Lua3D Smooth Terrain Demonstration (http://www.cemetech.net/programs/index.php?mode=file&id=1448)
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.
Please contact the author with the following informations.
Line 2409:
attempt to call method
'setBackgroundColor' (a nil value)
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.
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?
It doesn't run at all on OS 3.6 :(
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.
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)
I have fixed compatibility with apiLevel < 2.4. It should now work correctly.
Ok cool. I'll try the new version when I am back home. :)
Quote from: Tag365 on April 01, 2016, 02:39:46 PM
By the way, does moving local variable declarations outside a loop make the script run any faster?
I do not think that you will get a noticeable effect out of that.
Also, there are some nice Lua profiling tools out there, I've been using LuaProfiler to optimize a raytracer engine and the output is very useful. Possible you can use one at PC side.
One thing that helped with 3D in the past on the Nspire was switching to fixed points or integers instead of floating points. This is partly why Crafti runs over 3 times faster than Ncraft despite having not only textures, but also greater rendering distance. But I don't know if those are available in Nspire Lua.
Ha, that looks reeeally cool :D Hope you can find a way to speed it up a bit hahaha.
Quote from: DJ Omnimaga on April 03, 2016, 05:34:44 PM
One thing that helped with 3D in the past on the Nspire was switching to fixed points or integers instead of floating points. This is partly why Crafti runs over 3 times faster than Ncraft despite having not only textures, but also greater rendering distance. But I don't know if those are available in Nspire Lua.
In Lua number type is a compile time option, and most versions are built to use floats/doubles. So sadly there is no way to force pure integer usage (as far as I know).
Ah, too bad. I wish this was possible in Basic and Lua. Maybe the render distance and quality could be reduced to increase the frame rate? But I wonder how much quality reduction would be required in order to reach 3 FPS?