Huge 3D Dungeon Updates

I’ve been meaning to make a 3D dungeon (think Quake) for some time, and I finally did it, and wrote it up here.

What amazed me how fast it runs. The map (pic here) has 29 rooms, some very large, and many corridors, and is nearly 1 million pixels square. Including the walls, ceiling and floor, Codea has nearly 5 million pixels to draw, and there is flickering lighting as well. Even if it knows to ignore stuff that won’t be seen, that’s a lot of processing.

But I am getting speeds of 50-55 frames per second on my iPad 3, which I think is amazing.

I updated the code to provide an onscreen map when you toggle the yellow dot, with a small yellow dot showing the player location. Also, a left or right double tap turns you 90 degrees (useful when everything is at right angles)

I can’t get it to work, even if I put an image that is from codea directly. Thanks for the help anyway @Ignatz

you don’t put the images in a dungeon subfolder, you just put them straight into the Dropbox folder that you see from Codea, because that’s where the program looks for them

I don’t know where exactly to find the images

search the code for “LOCATION OF IMAGES REQUIRED”, the link is on the next line

This link will show you the images. Unfortunately Dropbox seems to show the pictures but hide their names.

The link below may be better, because it shows the name next to each image

(I’ve substituted this link in the code)

I got the images, I syced my drop box. It won’t give me an option to choose the dungeon folder in Dropbox. I don’t get it

read my ebook!

Below is a link to the code.

You need four images as well, see the link near the top of the Map tab. Just copy them into your linked Dropbox folder, and sync.

(A couple of the images come in 2 sizes. Use the @2x versions if you have a retina iPad - or else just copy all of them, Codea will figure it out).

I describe the tiling shader here (it does involve setting special texture mappings)

Let me know if anything isn’t clear, or if you have comments and suggestions.

Oh, that reminds me. How do you start a new shader files.

Yeah, I guess your right. I’d still like to know when it will be posted. But I will study more on shaders. I understand how to make 3D cubes

@Progrmr235 - not so fast, you need a lot more than this. However, I have written an ebook on 3D in Codea, and another on shaders (which I suggest you read in that order), which you will find linked at the top of this page

(which also links to many, many posts on 3D and shaders).

3D is amazing - enjoy, but be prepared to struggle with it. I commonly run a program and see nothing because I’m facing in the wrong direction or something. #-o

@ignatz I would find this really useful for learning 3D in codea. When do you think you’ll post the code? P.s. Also what bugs does the code have that you want to clean up?

@ignatz, I want to run your dungeon on my iPad, can’t get it to work. Keeps saying line 198: tex a nil value. How do I fix that. P.s. I’m taking your advice and reading the ebook, I just want to see this program

@Progrmr235 - it’s probably because you haven’t downloaded the images to your linked Dropbox account (you also need to go into your Dropbox folder inside Codea, and press the sync button, then you should see the images come up in the list there).

I’ll clean up the code a bit and post it. You are welcome to use any part of it.

I am not doing any culling, although I did expect to have to have to do it. I was going to just draw the room the player is in, plus the neighbouring corridors, which meant having a lookup table of neighbors for every room and corridor, but after finding the whole thing ran so fast, I didn’t need to bother.

I think the speed is largely down to the tiling shader, which dramatically cuts the number of mesh triangles - eg the floor and ceiling, each spanning over 900,000 pixels, each consist of just two triangles! The whole scene is nearly 5 million pixels but only has 1,350 vertices. This matters because speed seems to degrade linearly with the number of triangles. And the tiling shader is just the standard shader with one line changed. IMHO, that is the most powerful line of code I have ever seen in Codea (thank you, spacemonkey!).

If you go to the next step, as I said previously, it involves creating characters. 3D animation is extremely difficult, because it means creating and importing 3D objects which have more than one version of the pieces that animate. I can import .obj files created in Maya or Blender, but I haven’t tried animated models yet.

However, it is maybe possible to cheat and use static 2D “billboards” that turn to always face the player - like the statues in my video - and for example, ghosts can be made to float so they don’t need any walking animation. I already tried this here.

If you are going to shoot, you also face the difficulty of pointing, because once OpenGL has drawn the screen, it is just a mess of pixels, and, unlike any other language, I know, Codea has no way of telling you what object you just touched, or pointed at. There are at least two solutions to this, LoopSpace has elegant mathematics that work for regularly shaped objects, and I have a much less elegant hack that works for any object at all, by stealing one frame and drawing a coded version of the scene on it.

Sorry to ramble on, but 3D is both endlessly fascinating and (for me at least) hugely difficult and challenging.

@Ignatz - I’m impressed by your FPS speed. Are you doing any polygon culling outside the viewing frustum or other level of detail optimisation? I guess these are the other things to consider (if your not doing this already!) if your going to add other 3d stuff to the dungeon to keep your FPS as high as possible. ( Basically, just processing and drawing only what you can ‘see’ through the camera)

Some amazing stuff there Ignatz! Here I am making simple 2d games and you are making 3d worlds! I wasn’t even aware that codea could do stuff like that. Would love to see the code also.

Looks amazing - any chance of a video?

I tried using Codea’s video recorder, no dice as I expected. Then I tried the Reflector app, which has always worked before, but it messes up shadows. So I downloaded a demo of AirServer, and that did the trick. Watch in HD.

I only did three rooms, it would take half an hour to do the whole map.

NB the shaky navigation is entirely down to my bad driving!.