Monday, December 27, 2010

Holiday Update

Now that it is the holidays and I am not at work for a whole week I have no excuse to not update this blog with the work I have done on the ray tracer. The updates since the last time I posted have not been huge visually but they have been helpful in keeping me working on this project, which at times can be the hardest part.

What I have done is a few things. First, I went through my render pipeline and used Intel's Threading Building Blocks to easily multi-thread my rendering. I did this mostly as a quick test to see what kind of performance gains I would see while running this on my laptop. The starting speed of the ray tracer before adding in TBB was about 1400-1500ms per frame. That is running at 1280x720 resolution, not a very respectable time. After (sloppily) throwing in TBB my frame time dropped to around 400-500ms per frame, just adding in TBB (which was not much work) brought me out of the realm of Seconds Per Frame and into the wonderful world of Frames Per Second! Also if I drop the resolution down to 800x600 my frame time dropped to around 140ms per frame, that's nearly interactive!

Another change that I made as you can see in the picture is that my triangles are properly casting shadows now. The first iteration of the triangles did not cast shadows because the back faces were being culled, and to properly have a shadow be cast I need a ray to hit the back face of the triangle. The big problem with having a triangle be able to cast shadows properly is that you essentially have to check against the triangle twice per ray, once for the clockwise winding and again for counter-clockwise. Adding support for this allowed me to add support for being able to choose your triangle winding though, now you can choose clockwise, counter clockwise or both. Also the single triangle shadow issue wont be an issue at all if you have a closed mesh since the ray would always intersect with a triangle in the mesh when checking for shadows.

The final update I made was actually a bug fix rather than an "update". I had anti-aliasing in place since it is very easy to do edge detection with a ray tracer, but it never quite looked right. I just passed this issue by and moved on to bigger and better things, but after talking with a friend of mine he convinced me to go back and fix this issue before the bugs started to pile up. There were actually two issues I had, one was that I was not storing off the original colors from the first ray trace that detected the edge properly, the second issue was that I screwed up some very simple math and was doing six samples when my math assumed four. I fixed those two simple problems and now my anti-aliasing looks smooth and nice around those edges.

Future work that needs to be done is that I still need to get model loading in and working, I may start with some third party library for loading models and roll my own when I see fit. Also there is one more known issue that I want to take care of which had to do with floating point precision errors I was seeing back when I was using floats for everything. I want to move back to floats because I find doubles to be a waste of memory and a potential performance sink since if I use floats ( or to be more clear, 32 bit single precision floating point values) I could optimize a lot of my vector math with SSE.

Sunday, October 31, 2010

It has been a while.

Well, I would like to say that I have been hard at work on my ray tracer but that is not very true, I have mostly been hard at work... at work. Since my last update many things have happened, Blacklight: Tango Down has shipped, it is available on XBLA, PC, and PSN, check it out! Shipping Blacklight has been the biggest thing keeping me from writing this update, also I just recently got a new job, I am starting as a UI Engineer for WB Games tomorrow (Nov 1st). I am very excited about this new position as I really like the project I will be working on and I have worked with many of the people there in the past and there are all top quality. Also the new project is not announced so I cannot talk about it, sorry.

Onto what I actually did on my side project recently! As you may be able to tell from the picture, there are two triangles on the screen, your eyes do not deceive you. On top of that there are textures on said triangles. That has been the majority of the work I have been doing lately, just getting triangles and textures in and functional. Now I can move onto whole lists of triangles and loading models and various other image formats so that I can display something that looks nicer than a reflective sphere. I have been reading a lot on barycentric coordinates lately to get the rendering and textures working for the triangles. I have been having a bit of a hard time understanding them so I have been spending a lot of time just trying to figure out how they work.

Yea, that's pretty much the progress so far, next up is to add model loading, clean up textures and materials in general. Also I need to add support for choosing the winding on triangles so that model loading can be easier and I can support shadows from triangles easier. I hope the next update will show up much quicker than this one did.

Sunday, June 27, 2010

Side project progress

Work has slowed down and has allowed me time to get started on a side project (and update my blog!) If you read my last post I asked for help figuring out what I should do for a side project, but I completely ignored all my ideas in that post and decided to write a ray tracer!

As you can see from the picture, that is the progress I have made so far. I have a simple scene that has spheres, planes, and point lights. I have implemented basic diffuse and specular lighting, as well as reflections, shadows, and 4x super sample anti-aliasing. I was able to get this up and going to this point working on it for about four nights. I loosely followed this tutorial, I found it to be very helpful getting started, but I would have appreciated if he had commented his code or named is variables better. I was able to figure out what he was doing and add a few small fixes as I saw fit (for example allowing resolutions that were not 4:3 aspect ratio).

For the future of this project I will be adding camera code next, which will require me to set up some math classes for matricies and quaternions first. After camera code, I will probably try to set up an actual asset loader, set up the ray to triangle intersect functions, and get textured objects on screen and running. I also want to get this either multi-threaded running on the CPU or just running all on the GPU. I think I prefer the GPU method, but I may try both. I have been meaning to try out Intel's Theading Building Blocks for a while now, and a ray tracer is a very easy thing to parallelize.

So far this has been a really fun little side project, if you haven't written a ray tracer I would suggest trying it. It is fairly simple and you get good looking stuff on screen really fast, so its very rewarding. I will be adding more blog posts as I progress.

Wednesday, April 14, 2010

Side project

My work schedule should be slowing down in the next month or so as our project nears its end (for those of you who don't know, I am working on Blacklight: Tango Down at Zombie Studios I am looking for ideas for a side project to work on, I have too many ideas, so I figure I should ask everyone who reads my blog to help me decide.

Here is the list of some projects that I would like to do.
1: a 2D game engine with 3D looking lighting and shadows
2: a shader management system (mainly so I can mess around with writing shaders only SM4.0 until I get a computer with one of those new NVidia cards that does SM5.0)
3: a physics engine (I could always use more math skills)

Those are the top three I can remember at the moment, I should really start writing these things down when I think of them. If you want to see me do one of these things, let me know by leaving me a comment. Or if you have an idea of something you would like me to work on please let me know I am open to suggestions.

Monday, April 5, 2010

Nintendo 3DS

First off, welcome to my blog. I do not know exactly what this blog will be about, but sometimes I have thoughts or ideas that I want to share and others might be interested in reading so I figure I will try out this blogosphere stuff.

Onto the actually content of my post! (is this a post? or a blog? what do I call it? blogging is hard.)

There are a lot of rumors about the new Nintendo 3DS that was sort of announced not too long ago. The 3DS has me intrigued for a few reasons, first because I don't need to wear glasses, and the second more important point is that this is an entire platform that will require developers to create games with 3D in mind! My mind has been going crazy with all the possible things you can do if you have an actual visual depth you can play with in a game. My first thoughts are to trick the player by playing with the in game depth and the actual visual depth if it is possible. I want to see if I can make background objects pop out while foreground objects appear as if they visually deeper than the background objects. You can also mess with the players vision a bit by having something like a sphere appear as green in one eye but blue in the other. Maybe you can do something where the screen is messed up for one eye so you have to close that eye to see what is going on because the other eyes view is fine. These are both probably very bad ideas but just some thoughts I have been having on the possibility of a 3D platform.

Now for the more technical stuff related to the 3DS. A lot of my numbers are based on assumptions and rumors that have been coming out so I could very well be wrong on a lot of this stuff. I am going to assume that by the name 3DS that this system will be backwards compatible with previous DS games, meaning that there will be 2 screens and I would hope that they are both 3D capable screens. Now Sharp has announced screens that can do this 3D visual technique that is claimed to be used in the 3DS and these screens can have a resolution of up to 854x480 which is incredibly good for a 3.4" screen. For a 3D effect in a game you will essentially need two render targets for your scene, one for each eye, and if you have 2 screens doing 3D on both you would need 4 render targets! so lets say that these awesome screens support 32 bit color, you would need a minimum of 6.56MB of video RAM to have 3D on both screens at once (you only need 5MB if it is 24bit color). That is more RAM than the Nintendo DS has in total (4MB, but the DSi has 16MB). This doesn't even take into account the processing power that is required to render an entire scene 4 times each frame from presumably 4 different view points. I am going to venture a guess that this will have the same limitations that the DS has where you can only do 3D on one screen at a time, and for dual screen 3D you will have to essentially cut your frame rate in half so that you can draw each screen every other frame.

I really hope that developers can mess with 3D depth on 2D elements, I would really love to have a menu where options visually pop out. and if this is possible there are a million awesome possibilities for 2D games with 3D visual depth to them. I do have my worries about how the 3D effect will look, it seems like the screen will have tiny slits that are slanted so you can only see certain pixels with one eye or the other. This sounds like it would greatly reduce the viewing angle of the screen to a small sweet spot where the 3D works and if you are at any other angle the effect is broken. This made me realize that 854x480 is the total screen resolution but for the 3D effect to work each eye is probably only seeing every other column of pixels which is essentially cuts the resolution of the screen in half so each eye is only seeing what looks like a 427x240 screen and that you would only need half the amount of video RAM previously mentioned to get dual screen 3D showing, which seems much more manageable.

In conclusion, I can't wait to see what Nintendo has to show at E3 this year, and I hope it meets and maybe exceeds my expectations. Now it is late and I am rambling on as thoughts come into my head. If you made it this far, I am impressed! Thank you for reading and hopefully you like it.