Texturemapped Raycasting Engine & 3D Object Rendering

Hey All,

A few weeks back now I posted a code example of a my Raycasting engine, ported to Corona. At the time it was simply flat filled walls. After playing around with sprite sheets recently, I revisited the raycasting demo and added texturemapped walls using them.

It takes a big frame rate hit. There is still some optimising around the sprite usage I’ve implemented which will boost the frame rate, but even so, I’m fairly certain sprites are not the answer for fast rendering of textured walls. But I’ve decided to share the code anyway.

There was also a bug in the texture offset calc which I’ve fixed in this update. Previously it always returned 64 (the size of the map cells). Otherwise the code remains largely unchanged outside the rendering class. I also added a mode button (top left) to switch between flat colour walls and texture mapping). The code has also been moved into several sub directories to clean it up a bit.

You can download the source here

I will add this to the Code Share page shortly.
Another example I posted recently (to the code share page) was a demo on rendering a 3D object.

I thought I would post it here also for anyone that doesn’t venture into the code share section of the site. You can toggle between various rendering modes using the buttons on the left.

Source for this demo can be found here

Any comments and feedback are welcome as always. [import]uid: 110262 topic_id: 23090 reply_id: 323090[/import]

This looks superb, can’t wait to download it and check it out!

Thanks for sharing this with the community :slight_smile: [import]uid: 52491 topic_id: 23090 reply_id: 92334[/import]

You’re welcome :slight_smile: Given you are on the ansca staff, you might have some good ideas on how to improve / optimise the renderer to boost the frame rate further.

I have also just updated the raycaster to v1.2, with better usage of sprites for rendering. This has given a boost to the frame rate, although it’s still lower than I would like. I also found I was calculating 1 extra scan line per frame, so have fixed that too. [import]uid: 110262 topic_id: 23090 reply_id: 92434[/import]

I am going to test this on my device tomorrow and remove your manual culling code and test it with the latest daily build that does automatic culling and I will report back with my results.

I played with your demo and added a skybox :stuck_out_tongue:

Would be cool to add some guys running around and a FPS gun :stuck_out_tongue: [import]uid: 84637 topic_id: 23090 reply_id: 92444[/import]

Awesome! Look forward to hearing about it :slight_smile:

Enemies and pickups are nothing more than ‘walls’ within the map. The engine is basically ready to handle that sort of thing, although it’s not tested, so possibly has a few bugs. My original version from pascal had walls with windows, doors and pick ups. I even included the secret type walls from Wolf3D where they sink back once activated. Getting those running shouldn’t take too much more effort. [import]uid: 110262 topic_id: 23090 reply_id: 92465[/import]

Yep, I am also from the Wolf3d days :slight_smile:

I think after i do the performance test , we should continue this. It’s an exciting little test project for a retro gamer like me :smiley:

Edit : I also ported Wolf3D to the psp back in the day. [import]uid: 84637 topic_id: 23090 reply_id: 92466[/import]

Hi Danny,

Excellent - you would already know a lot about raycasting then! I think we should talk more. I’m certainly interested in continuing it as a project. You can reach me on my gmail account andrewburch79 (gmail.com), or via my site andrew.burch (@) newhighscore.net.

My original version also had textured ceilings and floors, but at this point I think it’s not viable under Corona. But then it’s also just another challenge to take on :wink: [import]uid: 110262 topic_id: 23090 reply_id: 92470[/import]

Jesder, just an FYI… Don’t use a subfolder named “resources” as it breaks code signing when compiling for device.

“assets” or “files” will suffice instead [import]uid: 84637 topic_id: 23090 reply_id: 92556[/import]

Thanks for the tip, I will keep that in mind.

I will update the zip content in case someone else is interested in compiling it for a device. [import]uid: 110262 topic_id: 23090 reply_id: 92559[/import]

I’ve made a few minor optimizations but we are no where near were i would like performance to be yet.

I will email you my changes and you can review
[import]uid: 84637 topic_id: 23090 reply_id: 92560[/import]

Wow this looks really cool. Cant wait to try it.

-M.Y. Developers [import]uid: 55057 topic_id: 23090 reply_id: 92566[/import]

Danny has brought to my attention that having a folder called “resources” will break the compile for a device - I plan to update this later today and upload the fixed source zip file.

Edit: This has now been updated - the folder was renamed to assets :slight_smile: [import]uid: 110262 topic_id: 23090 reply_id: 92659[/import]

I’m not sure how the corona engine works under the hood but i was wondering if it might be faster to use a sprite map consisting of 1 pixel of every needed color (perhaps limit yourself to 8 bits of color at first). Every time it changes it would just need to shift the “frame” to the proper color.

Again, I’m not sure if this would speed it up or slow it down but it’s potentially worth thinking about. [import]uid: 112257 topic_id: 23090 reply_id: 94582[/import]

I haven’t had a chance to download this and see for myself in depth (I only skimmed the source), but judging from what I see in the screenshots and what you described—this look awesome! Keep up the great work…

I’m not sure if this would help you (and I only skimmed the source so I don’t know), but I did notice you used display.newRect() in your renderer.lua file (maybe elsewhere). Generally, vector shapes in Corona do not perform as well as images, because you don’t get any kind of caching abilities (and the latest daily builds gave us some nice tune-ups in terms of graphics performance).

With that said, your spritemap+colors idea might be a good thing to try out :slight_smile: [import]uid: 52430 topic_id: 23090 reply_id: 94603[/import]

Now this is nice work.

See my 3D textured tunnel http://developer.anscamobile.com/forum/2011/05/08/corona-doing-3d-tunnel-source-code

I used php to convert textures into rgb arrays. Probably went a bit overboard and it kills the processor, that maybe the overall 3d effect though. [import]uid: 5354 topic_id: 23090 reply_id: 101364[/import]