Game Engine Project (It Begins!)

See that? That's ¥156,789 down the drain.

I mean, that's my new computer and my new desk! (Also, if you look closely, you can see my space-saving strategy: my futon bed rolled out beneath the desk. I now sleep under my desk every night.)

Why did I spend ~$1,900? Because I'm crazy.  Because I have a plan!

I want to start writing my own game engine. I've recently been reading Jason Gregory's Game Engine Architecture book, and it made me want to have the experience of writing all these systems myself.

While it may take a few years, I'm going to start doing just that, in my spare time.  I wanted to write for code to run on a game console, but the closest thing I have is this iPad, so I bought a new mac computer. (My previous one is about 5 years old, the first Intel mac.) I also spent $100 on an iOS developer license, so now we're up over $2,000.

If you want to follow along with my progress, bookmark this link. I'll try to post on here somewhat frequently about how the project is going, but it will be slow, especially while I'm still taking masters classes part time in Japanese, and working full time.  But maybe in summer the pace will pick up a bit.

Quick update

I'm lazy and haven't updated in a while, but things have changed quite a bit so I wanted to at least mention them.  First, since I'm not writing a lot on the blog itself, I decided to at least present the stuff I am writing on this site.  So if you would kindly look to the right column, where I've now included a twooter feed (Twatter? Something like that.) I write crap and post links to pictures, and you read it.  Below that I've embedded my news stories that I like. These sections should be updated with more frequency than the blog, so please enjoy them!

And oh yeah, the internship at Bandai Namco Games ended, all the interns that applied (including myself) got full time job offers, and I'm living in Yokohama and working in Tokyo full time now, and it's awesome, my friends here are awesome, blahdy blah blah.  You know, minor details. 

Later I will update the resume, LinkedIn, Facebook... oh god nevermind, there's too much to update,  I quit.

Here's some pictures of my new apartment before I put anything in it:

Empty New Yokohama Apt

And here's a picture of where I work now, taken back in the summer:

Games

Oh boy, another week is gone, this internship is going by too quickly!  Halfway done now.  Things continue to be more productive at work, I feel like I'm contributing something now as opposed to being the newbie that is slowing everyone else down while they have to explain everything to him.  Communication is slowly improving.  There are a few people at work I can converse with decently now.  There's some people I have a really hard time with because of either their voice/manner of speaking or or the grammar they use, or both.  Oh well I'll figure it out.  I'd like to write more about the internship work, but I don't want to cross any confidentiality boundaries.

On Friday, I got kind of soaked going home from work because I still have not bought an umbrella.  We wanted to go out, but since it was kind of nasty out, we stayed in and watched this Gambling Apocalypse Kaiji movie, based on this manga/anime series of the same name.  I don't think me and Yan understood much, but Karen had read the manga or watched the anime before, so she explained it all to us.  It was pretty interesting.  Basically this guy has some debt to a yakuza like organization, and he has to gamble his way out of it, or spend his life as an indentured servant.  The way the main actor played the role was kind of annoying though, he just basically cried and complained the whole time.

Saturday night we were invited to our work friend Ogura's house again for dinner and drinks, but this time we planned ahead and paid for him.  We played the same drinking game we played last friday, and it was just as loud as before, but at least it wasn't in the hotel.

Sunday I had plans to meet my coworker Daigo from VV, who's working in Tokyo at Square Enix now.

Game Center

It was a Namco arcade I guess, so we played some Tekken, we all lost badly to Daigo.  Maybe he's related to this Daigo.

Then I went home and played a ton of Final Fantasy 13.  Man this game won't end.  I hope I can finish it soon, I really need to start playing something else!

Odaiba

Today the interns and some coworkers took a trip to Odaiba, an artificial island that is part of Tokyo.

It is the home of Fuji Television:

Odaiba Photos

We ate in this fancy shopping mall, had some pretty delicious chinese food:

After that we headed for this museum, but we ran into this big cosplay gathering before we got there.  Apparently you were supposed to pay to take pictures, but nobody stopped us:

At the museum, they had an Asimo robot, it was pretty cool, a little creepy how human-like it is:

After that, we played some pool and had okonomiyaki, and it was awesome.  Of course our senpais paid for more than their share of everything, because they are too nice.  

The rest of this week has been going pretty smoothly... I was pretty exhausted the beginning of the week, from not sleeping much on Saturday, and from staying up on Tuesday to watch the Japan world cup game, which they lost in penalty kicks, unfortunately.

On Friday, we went with the same people went to Odaiba with for Thai food, and then some of us also went out to do Karaoke, but everywhere was full since it was Friday night.  So we went to an izakaya instead.  After that we partied in my room for a few hours, playing some drinking games.  We were so loud, I'm wondering how long it's going to be before they kick us out of this hotel.

Maybe we'll find out next week. But hopefully not.

Back in Japan

So I wasn't sure I'd ever get another chance to live in Japan, but here I am.

For those of you that are out of the loop, I recently accepted a summer internship for programming at Namco Bandai Games in Tokyo. I couldn't pass up the chance to get more Japanese practice and see what living in Tokyo, the most populous metropolis in the world, is like.

I got into Narita on Friday, and took a train down to Tokyo to check into my hotel in Shinagawa:

It's a pretty nice hotel, we're pretty spoiled I think, it's only 10 min from work too.  I met Ed from HR and another one of the interns, Karen, who already had moved in.

On Saturday, I got on the train and ended up in Asakusa:

Asakusa

Then the Japan World Cup game versus the Netherlands was that night, so I asked the front desk to find me a sports bar.  It was pretty packed, which was awesome, but Japan didn't score a goal unfortunately (though they won their next match in a big upset.

Sunday we went to Ginza and saw some weird stuff.

The streets were closed off and they put tables out for people to sit at.  This on had a litter of kittens and the mother.  I don't know why.

These people like to rock out.

Monday we started work.  The first day was mostly orientation and meeting people.  The second day they threw the interns a welcome party, and it was awesome.  Then afterward there was an after party at a local restaurant.  The lead programmer of Tekken 1, 2, 3, Tag and 4 treated us, he's awesome.

Work has been kind of tough, communication is really difficult.  I'm so bad at speaking and even worse at listening.  I really hope I can start learning faster in the next few weeks.

Friday, my team took me out for another welcome party, and it was pretty awesome too.  They are pretty interesting people, I like them a lot.  Saturday we went to Harajuku to see crazy people dance or dress up or something, but I guess we missed it.  It was still pretty packed:

Then I went to Akihabara to buy cables to hook up my ps3.  The hotel was only supposed to have crappy TVs, but they upgraded all the rooms to HDTVs on Monday for some reason.  I couldn't get Wii cables because apparently they are different for Japanese Wii's.

That night the interns and 3 of our American friends went out to Shibuya, drank at a couple all you can drink places, then I went with some of them to go to this place Club Atom.  I really never dance, but they were all going so I went, the place was packed on all 3 floors so no one could tell that my squirming in the crowd was any worse than anyone else's fortunately.  It was pretty fun, we stayed their until 3am, but it was after the last train, so we had to wait until 5AM to take the first one in the morning.

Sunday my friend from KIT Masa came, and we went to the Edo-Tokyo museum.  It was pretty neat, the special exhibit was insects though, it was for kids.  After that we went together with the other interns to a coworker Ogura's place, and he treated us to an awesome dinner, even Masa who he didn't know at all.

That's all for week 1, hopefully I can find the time to write again next week.

Ray Tracer

This quarter, I have to complete a capstone project for the Golisano College of Computing and Information Sciences Honors Program.  It's pretty much free reign for what I want to do with this project, and since I don't have any more time here to take Computer Graphics 2 from the CS department, I figured I would do the main project they do in that class, build a Ray TracerJoe Geigel from the CS department who frequently teaches CG2 and who specializes in computer graphics in general.  He lent me the book Ray Tracing from the Ground Up, and I'm using their skeleton code from their website.  The source for my project is up on Google Code, so feel free to browse the source.

Week 1:

This week I was mostly focusing on how the reverse ray tracing and hit object tests work.  I covered the first few chapters of the book, and I worked on getting the skeleton code from the book, which was originally written for linux, up and running under xCode in OS X.  It was worth it because he has a good setup for the class hierarchies, as well as the UI for the ray tracer.  The first basic image I ray traced was a simple one.  The scene has one sphere, and a simple test is done to see if the equation for the ray is ever equal to the equation for the circle.  If the ray hits the circle, the corresponding pixel is colored red.  If not, it's colored black.  The resulting image:

First Ray Trace

It doesn't look like much, but there's a lot more to come.

 

Week 2

Multiple objects (2 spheres and a plane)

 

Regular Multi-Sampling

 

Random Sampling

 

Jittered Sampling

 

Multi-Jittered, 25 samples/pixel

 

Perspective viewing

Perspective Viewing

 

With perspective viewing comes moveable camera

 

Thin lens camera simulates depth-of-field

 

Week 3

 

Depth of field with many circles, no plane

 

Fish eye lens, 2 spheres and a plane

 

Fish eye lens, many spheres

 

Spherical panoramic view, 2 spheres and a plane

 

Spherical panoramic view, 2 circles, a plane, and many spheres (upside down)

 

Week 4

Lights and materials

 

Two spheres and a plane with lights and materials.

 

Specular highlights

 

More complex scene with specular highlights

 

Hard shadows.

 

Ambient Occlusion (required me to up it to 256 samples)

 

Area Lights give softer shadows (also required 256 samples)

 

Fake Spherical Light produces the same soft shadows by simply jittering the position of a point light randomly.  This image looks noiser than the spherical light one, but at the same brightness level and samples, the actual area light would be more noisy.

At this point, render times were getting to be pretty long because of all the samples required. The above image took over 15 minutes to render.  So I decided to implement some of the time-saving methods.  First, I tried testing against bounding boxes before testing against collision with the spheres themselves, but overall this actually takes longer because it has to do 2 tests instead of 1.  But the work was not lost because I used the bounding boxes to place the objects into a regular grid, and the rays would traverse the grid and test against anything in each "bin" of the grid, and it knows that the first thing it hit is the closest with this approach.  So the more objects, the more savings with the grid.  With this regular grid it took 7 minutes to render the above image, more than a 2x savings.

 

Week 5

Honestly I didn't do any work this week because I got into the Little Big Planet beta.

 

Week 6

Added some new shapes this week

Three triangles, two are rotated via matrix multiplication.  Had to update my regular grid to accomodate rotated objects.  Instead of computing a new bounding box from the rotated object, we compute a new bounding box from the rotated original bounding box.  The bounding box ends up bigger than it needs to be this way, but it's much simpler to compute the new bounding box this way.

 

3 flat discs

 

3 Rectangles

 

Annuli

 

3 Open Cylinders

 

3 Torii

 

3 (originally) axis-aligned boxes, the green and yellow have been sheared in different directions.

 

Week 7

Implemented some part shapes this week

Part Cylinders

 

Convex part spheres

 

Beveled Cylinders created with open cylinders for the sides, torii for the bevel, and disks for the top.  Beveled objects are more realistic and give a good specular highlight.

 

Beveled boxes require 12 cylinders for the edges, 8 spheres for the corners, and 6 discs for the faces.

 

Rendering them without the faces gives a neat "wireframe" look, and you can see how the pieces make the whole.

 

Beveled Wedges are even more complex, with 8 cylinders, 8 spheres, 4 part torii, 2 part cylinders, 2 part rectangles, and 6 part annuli.

 

The wireframe shows gives an idea of how it's all constructed.

 

Archway rendered with beveled boxes and wedges as bricks.

 

Rosette made of beveled wedges.

 

Week 8

This week I worked on using some code written by Greg Turk from Leland Stanford Junior University to load triangle data from ,ply files.  The vertices and indices are then reassembled into triangles and normals are computed.

 

Model loaded from triangle data in a .ply file.  This model uses about 4,000 triangles.

 

This is the same 4,000 triangle model, but instead of using a constant normal for the entire surface, the normal for a given point is bilinearly interpolated between the three different points making up the triangle.  The result is a smoother look, but if you look close you notice areas where the incongruity between the normal and the actual geometry is apparent,

 

The Stanford Bunny with ~69,000 triangles with smooth shading.  Since the triangles are put into a regular grid that drastically reduces the number of hit tests required, the actual rendering of this only took a little over 16 minutes.  Since we use about 8x the number of boxes in our grid than objects in our scene, deciding which of ~550,000 boxes each of our 69,000 triangles bounding boxes lies inside becomes the new bottleneck.  Depending on the complexity, accuracy, and size of the rendered image, the loading of the model could take as long or longer than the actual ray tracing.

 

Reflective materials

 

Glossy reflection (more closely matches the matte materials)

 

 Week 9

Scene rendered with global illumination and one big environment light surrounding it.  Notice that using path-tracing results in color bleeding of the green floor onto the bottoms of the grey spheres.

 

Cornell Box rendered with global illumination.  The boxes in the middle are actually white, and any color is reflected off of the walls of the outer box.  This scene required 10,000 samples and 9hrs of rendering using the path tracing method with a maximum depth of 10.  I didn't have enough system resources to try 100,000 samples, we clearly need a better method.  More on that later. 

 

Transparent sphere in front of a reflective one.  The index of refraction for this sphere is higher than outside of it, like a glass sphere surrounded by air.

 

This sphere has a lower index of refraction than its surroundings, resulting in total internal reflection.  This is similar to an air bubble in water.

 

Transparent low-poly Standford Bunny model with smooth shading.

 

A more complex modeling of transparency (and reflection on transparent objects) involving fresnel equations gives the ability to display nested transparent objects as well as colored transparent materials.  This is 3 nested spheres, with an air bubble inbetween the innermost and the middle sphere.

 

Panes of glass

 

Texture mapped to a rectangular surface

 

Texture mapped to a cylindrical surface

 

Texture mapped to a spherical surface

 

Reflective spheres w/ light probe.  Light probes are formed by putting a reflective sphere in an environment and taking a picture of it.

 

The same light probe with a reflective low-poly smooth-shaded Stanford Bunny.