welcome guest
login or register

Adventures in 3D programming

In my teenage years when I was learning computer programming with the good old Commodore 64 assembler, a 2D tilemap engine was one of the standard techniques I often used. And later on, when I migrated to the PC world, a 2D tilemap engine was one of the first things I tried to code. At that time I even tried to learn some 8086 assembler to optimize the graphic routines. Over the years, using a 2D tilemap has become such an self-evident choice for me. Maybe something like a toaster for those who have one - when you feel like eating a toast, you put a few slices into the toaster and wait for them to be ready, without even thinking of using other methods available (like using an ordinary frying pan to heat up those slices of bread). Ah, and for those who aren't that familiar with games and graphics programming: a 2D tilemap is essentially what UnReal World looks like. Or, imagine having a board game, where you can each time build a new game world by placing square terrain pieces next to each other. That way we can easily build a rather large map.

When I started my new game project I thought to use the trusty 2D tilemap, so that I don't need to waste time tinkering with UI and graphics - you see, personally I love the game mechanics, the inner workings of the simulation running the game. And it is mainly and mostly those I want to develop with my new game. Also, for me this was kind of an work optimization idea; if you are building something big, it is often wise to utilize materials you already have, so that you don't need to buy or craft everything from a scratch. "Okay", I thought, "at least for the first version I can just use a slightly modified UnReal World tileset. That will save me a lot of time, as my fingers are itching to dive deeper into the actual coding, the proper coding, the coding of the game mechanics."

But then, at some point, based on some wise and constructive feedback I paused for a second thought. So, that time I said to myself: "This game is going to take place in the area called Savo, in Eastern Finland where I grew up. And characteristic of the Savonian landscape is those thousand lakes and then hills, wooded hills everywhere. Do you really think that a flat 2D tilemap is the best choice if you want to present a game world rich of hills?" I don't know what you think, but for me the answer became clear and obvious. I need to learn to make a 3D tilemap. Already back in the times of Commodore 64 I was experimenting with some simple 3D graphics, but naturally the whole technology has developed pretty much since those times. Nowadays we don't need to calculate everything manually, we just push a set of formatted data to the graphics card, and let the hardware-optimized enginery of the graphics processor to spit out a 3D scene rich of textures, lights and shadows. Maybe ten years ago I took a brief look at the modern coding in 3D, but at that time I didn't venture deeper.

Okay. I'd guess most of the game developers nowadays just adopt a game engine and start developing on top of that. But even in that case I'd first need to learn how to use the game engine of my choice. So I tend to feel that with same amount of time, energy and learning I can just learn to code an engine of my own. Or, at least - learning by coding is the best way for me to learn. Then, if some future year I want to start using a ready-made 3D game engine, it will be a lot easier since I'm already familiar with the way stuff works behind the scenes. But, I don't know - it is often my experience that any game engine comes with a certain set of limitations - and if I have a specific game idea in my mind, I don't want to waste my energies trying to figure out how to handle the situation if the limitations of the game engine seem to restrict my ideas. So, having to develop my own 3D tilemap engine gives me better understanding if limitations come from the hardware, or if they are because of the way the engine is programmed.

So, for the past weeks I've been studying vertexes and indices, shaders and textures and modelling. And, most of all - how to programmatically generate dynamic 3D meshes. Piece by piece it all starts to work, so I'm approaching the baseline I already had with my 2D skills and standard routines. (Read: A part of my brain feels that learning to code the graphics is eating away time from the actual game development. That I've spent weeks just to get to where I already was in the first place. But, I'd guess reaching that baseline in 3D actually is something different.) And, all in all, I must say that despite brief moments of frustration I've greatly enjoyed the process. It has been a lot like learning to develop a 2D tilemap engine in my teenage years. Putting together code, sometimes having to find the way with repeated loops of trial-and-error, and eventually seeing shiny new things appear on the screen. The joy of discovery, the joy of expanding horizons: "Wow! I didn't know I can do this!"

One challenge with 3D graphics is that when the user clicks on a point on the screen it isn't immediately obvious how that screen coordinate translates to the game world coordinates. With a 2D tilemap that is a rather straight-forward task, for you always know where one tile begins and the another ends. But 3D tiles with different elevations - they don't appear uniform on the screen, so a bit more of maths is required to figure out what tile the user wants to interact with when they click this or that coordinate on the screen. Luckily, I got that solved - or, at least I managed to code a function which works. Later on it could use some fine-tuning and optimization for speed, but at least with my desktop computer the tile picking algorithm takes less than a millisecond, so it isn't that bad. But my intention is to have the same code running on mobile devices as well, so I should prepare for some optimizations on those environments.

Well, then an another challenge is that the graphics card processor can't quite handle as vast areas as we can easily make with a simple 2D tilemap engine. The whole game world simply can't be converted into a single huge 3D object. Instead, we need to split the big game world into smaller chunks, and then display those chunks neatly next to each other so that what meets the eye of the gamer is a seamless 3D world. At the moment of writing this I'm working on this - it seems that the seams could use some polish still. Technically speaking; I think I got the vertex Y-coordinate values (almost) matched where the chunks meet - but calculating the vertex normals still fails, making the terrain shadows appear buggy at the chunk seam. I purposefully choose to post a screenshot of a crude in-development version. Don't worry; I do have a version where the chunks are bigger and the hills are more smooth and nice. But for debugging purposes I temporarily reduced the chunk size, so I can easily run through the seams to see where it fails. (Also, at the moment I don't even attempt to smoothen the shorelines. That should be a relatively simple task, and I'll do that once the terrain chunks work the way they should.)

Now, in case some of you - read readers - happen to feel that I've been wasting my time with 3D graphics, as you'd be perfectly happy with a 2D tilemap, I must say that I do understand and appreciate that point of view. For a moment I was thinking if I should just use simple light-and-shadow effects on a 2D tilemap to tell the player which is a southern side of the hill, and which is the shadowy northern side. Sure, that would work, and it would've taken me just a day or two of coding to add such functionality to the standard 2D tilemap engine. So, after all, I think the bottom line is: I've greatly enjoyed my adventures in learning 3D programming. For me that joy in itself has been justification enough to spent time learning new techniques. And I hope this will open brand new avenues for our future indie game projects.

I'd like to finish with a quick mention on the other aspects of my life. As, earlier I wrote that my monthly income has been falling below my monthly costs. That is still more or less the case. And at the moment I deal with that using the tried-and-true starving artist tactics, together with equally traditional countryside ways. Remember I once told about harvesting storm-felled trees from neighbours' forest, and how most of those logs got sawn into timber. I have now been utilizing that timber for my building projects (more about them later on). One summer evening when I was busying around with a building project I noticed an ATV approaching. It was an elder fisher-lady from a nearby house, together with her close neighbour. The other neighbour booked a time for a massage for her aching shoulders. And the fisher-lady asked if I happen to have any spare 2*4 pieces of timber. I went through my stacks of sawn timber and sorted out the amount of 2*4 pieces she was asking for. The following day they came with a trailer to fetch the timber. And the lady asked what does the timber cost, and I suggested the timber costs fish. The exact amount of fish was left for the lady herself to decide. That has turned out to be a good deal; since then I've been receiving fish deliveries every second month or so. I like the idea that the payment comes in smaller packets over a longer time period - it is of more use that way. So, today's main dish was potatoes from my own garden, and a zander, slowly cooked in my wood-burning stove. For breakfast it was buckwheat porridge (cooked out of left-over buckwheat I once got from the nearby mill), together with the lingonberries I picked in the autumn. Food costs for today: 0 €.

EDIT: A day later; I added another screenshot. All the seams seem fixed now. To test the tile picking I was trying to pinpoint a small islet in the distance. Seems like I accidentally moved the mouse just when the screencapture timer fired, so we have a water tile picked instead. Oh well =)

Still got some problems with the seams of the terrain chunks.
Still got some problems with the seams of the terrain chunks.
I was trying to pick that one tile island but missed by a tile =)
I was trying to pick that one tile island but missed by a tile =)
tags: 
diary
homesteading
programming
up
328 users have voted.

Comments

I think 3D is nice but it’s much more complex and requires a lot more time and effort than 2D so, considering your income situation, are you sure this choice is worth the risk of delaying the delivery of the final product? It wouldn’t be wiser to have something playable as soon as possible in order to test your idea on the market? I’m genuinely asking

That's a good question and I appreciate that. You are wording my original thoughts, I started with pretty much that idea. But at some point I was hesitant, as I thought that to "test the idea on the market" is probably going to require polished production quality graphics (be them 2D or 3D), and that will anyway take time. So I took some extra time to experiment with 3D to see if that would be a plausible option.

But, if instead of "the market" we think of a smaller bunch of UnReal World players, then I genuinely think we could launch with something playable but with work-in-progress graphics.

And then a small note on the psychological side: Yes, initially I felt that I've been thinking about this for so long, that now I finally need to make it happen as soon as possible - instead of getting my own projects delayed and delayed because of me being busy with odd jobs to sustain myself. But once I survived through the weeks of uncertainty, I found myself peacefully back in my "I'll survive, things will work out"-mode. And with a deeper sense of inner peace I felt that "Okay, I've been planning this for so long, that better not ruin it now by rushing too much too quickly." This is the inner shift which happened in my mind. So, with this kind of approach I have allowed me some time testing and experimenting.

Later on this week I'll be strictly back to the "something playable as soon as possible"-mode, and depending on how that goes we will have more solid news in mid-January or so.

Looking good! And I can certainly relate to your keenness for switching gears to a new type of technology. It can open some locks creativity-wise and learning new stuff is fun anyway. Isn't that one of the best parts of game dev anyway, combining technology and creativity?

I would offer a counterpoint to Loppa's comment above, just for the sake of seeking balance. If you start worrying about the market too much, if you pay too much attention to an imagined wide audience especially at this early point, then you might lose something else. To exaggerate a bit: be an artist, not a royalty-seeking marketer! :)

Take care!

Great story in the end with the monthly fish packets :)

Pages

Add new comment

CAPTCHA
Please reply with a single word.
Fill in the blank.