Computer Graphics

Computer Graphics


CG2 Ray Tracer Updates

2.22.2012 | 0 Comments

Howdy folks!

These past two weeks have been an interesting few for my ray tracer. It began with this:

That’s not a lossy image, unfortunately it’s my graphics card doing some ungodly things. Occasionally, it would cause the system to freeze entirely when drawing the app, but for the most part, things weren’t so bad…. until my hard drive decided it didn’t want to be friends with me anymore.
So, I did a Time Machine restore and ultimately ended up only losing about two weeks of work. Not as bad as it could have been.
However, that’s when things started to get interesting. I started doing some LINQ at work and thought this would be so cool to use for my ray tracer. I could do three dimensional spatial query using LINQ to take care of the ray intersection logic for me (among other things), check it out:
private IEnumerable<ISect> Intersections(Ray ray, CGScene scene)
{
return scene.AllObjects
.Select(obj => obj.Intersect(ray))
.Where(inter => inter != null)
.OrderBy(inter => inter.Dist);
}
This, however, meant that I would have to have both a language and paradigm shift over to C#/.NET. I was already a few weeks in the hole, but I knew what I needed to do and calculated that it should only be “an extra three hours or so of work” to port it over.
I was wrong. The work took longer than I had expected, and now I was maintaining two different codebases. Retrospectively, this was a poor choice. As a result, I wasn’t able to get everything working that I wanted to for Checkpoint 7 functionality, but I was able to do a lot of extras! Here are some screenshots of the app demonstrating some of those functionalities (some of these I forgot to put in the Readme):
  • Adjust your shadow ray to take into consideration the transparency of any object(s) it intersects
  • Implement another procedural shader or texture
  • Implement texture mapping from an image
  • Add support for multiple light sources

Here are some sample images of the .NET version. Check it out!

Checkpoint 6

Different Programmatic Shader

Different Light Position

Different Light Position and Color

Wood Texture Mapping

Wood Texture Mapping

Anyways, this project certainly has been a learning experience, and I got some cool images to show at the end of the day. Not bad!


CG2 Raytracer: Assignment 5

2.03.2012 | 0 Comments

Assignment 5

Alas, here it is! Reflections!

Good news is that I have reflections working the way I want, bad news is that I’ve incurred a lot of technical debt in the process so I’ll be working some refactoring this weekend. Truth be told, I’ve been working on it for a while (another completely codebase), but I haven’t had the time to devote to polish yet. I have some extra time this weekend, so I’m planning on going to town and getting the other codebase back up to speed. More to come on that soon ;)


CG2 Raytracer – Checkpoint 2 “Not What You Expected”

12.16.2011 | 0 Comments

Checkpoint #2 – Release Name: “Not What You Expected” (http://dl.dropbox.com/u/113994/silly/gifs/J5kTJ.gif)

Remember how last week’s ray tracer was in OpenGL and GLUT? Boy, that was a mistake. Although I got the end result I was hoping for, I really shot myself in the foot for future increments. The primary reason for this was that I was attacking the problem the wrong way. Although I was able to rasterize an end result that looked visually correct, it relied on the OpenGL and GLUT calls to rasterize the end result, and I found myself having to write some janky and nefarious workarounds to make it work with GLUT that just (for lack of a better phrase) made me feel dirty.

So, on Tuesday night I decided something had to go and scrapped everything and began anew. This time, I’m taking the high road and writing everything from scratch in C++. This release has its own geometry classes (CGRay, CG3DPoint, CG3DVector, CGNormal, CGMatrix, etc.) and all that business is happening in an O-O way.

I’m happy with how it’s coming together now, and the design I’m very satisfied with. Moreover, the extra push I had to get this release working The Right Way™ will help grease the skids in the future.

Here’s a couple other improvements which I feel will help me in the future:

  • The scene is now centered at the camera at 0,0,0. Now everything can be positioned relative to the camera in absolute space, which gives me some cleaner numbers to work with when manipulating objects.
  • Ability to do supersampling.

Here’s the default output image:

Here’s a supersampled image, notice that it looks a little bit crisper (look closely):

I did not have time to add an extra object type for this release due to time constraints, but I’ll be working on that in the future, perhaps in terms of an .obj or .dae loader.

I’m also looking into deferring some of the processing to the GPU (CUDA) to increase rendering performance, and I plan to look at that over the break. I’ve installed the SDK and I’m dabbling with that now, and I hope to have some elements of GPU-accelerated rendering for the next release.

At any rate, there’s lots of cool stuff happening under the hood! Take a look:

For simplification purposes, a CGShape is an abstract class that (at this point) is either a CGSphere or CGRect.

There’s lots left to do though, so I’m going to capitalize on the break to get some extra polish done on the ray tracer. So far this scene rendered in 0.5 seconds. Not too bad, but I think I can do better!

PS: Every release I have for personal software projects is accompanied by a tagline and a silly image. This release was called “Not What You Expected” because my previous release ultimately had to be thrown out – something I most certainly didn’t expect ;)


CG2 Raytracer – Checkpoint 1

12.06.2011 | 0 Comments

In the following weeks to come I’ll be posting my progress in RIT’s Computer Graphics II class with Professor Bailey. It’s required to blog about our work as it evolves, and this seemed like an excellent venue! So, without further ado:

Setting up the Scene

In this assignment I began my recreation of Turner Whitted’s famous ray tracer published in his 1980 paper. The assignment was relatively straightforward, but the majority of my time was spent getting the objects to appear as they did in Whitted’s paper. The image I am trying to replicate looks like this:

So, as far as the objects are concerned and the position of the objects… not too bad! Here are the parameters I used to generate the scene:

  • Size and location of two spheres:
    • Big Sphere (foreground)
      • X: -1.83
      • Y: 1.1
      • Z: 8.3
      • Size: 1.0
    • Small Sphere (background)
      • X: -0.83
      • Y: 0.35
      • Z: 7.55
      • Size: 1.0
  • The size and location of the floor (conveyed by locations of vertices):
    • Vertex1
      • X: -3.0
      • Y: 0.0
      • Z: 10.0
    • Vertex2
      • X: 3.0
      • Y: 0.0
      • Z: 10.0
    • Vertex3
      • X: 3.0
      • Y: 0.0
      • Z: 0.0
    • Vertex4
      • X: -3.0
      • Y: 0.0
      • Z: 0.0
  • The location and parameters of your light source:
    • X: -1.5
    • Y: 9.0
    • Z: -10.0
  • The location and “lookat” of your camera:
    • Eye
      • X:  -1.65
      • Y: 0.9
      • Z: 11.2
    • Center
      • X: -1.675
      • Y: -0.005
      • Z: 0.65
    • Up
      • X: 0.0
      • Y: 1.0
      • Z: 0.0