Showing posts with label Ray-Tracing. Show all posts
Showing posts with label Ray-Tracing. Show all posts

Friday, May 16, 2008

Actual Final Image


2048 x 2048 - 256 samples / pixel
Flipped Image (I trace my image reverse from how I index into my textures)
real 309m15.909s

Wednesday, May 14, 2008

Next Go

Here is my final image showcasing Perlin noise.



1024 x 1024 - 256 samples / pixel


A little different view point


Even Further to the Side - You can see where my star texture repeats

Monday, May 12, 2008

Quite Possibly my ray tracing final project

The "moon" is actually a Perlin noise texture with the color simply as the [0,1] noise value multiplied by white to get a gray color. I am using cubic interpolation and eight octaves of turbulence. The earth is from a previous assignment, and the stars are actually texture mapped onto a plane behind my sphere.


1440 x 1080 32 samples / pixel
(real 21m42.207s - Somewhat low-res star texture)



1440 x 1080 32 samples / pixel
(real 43m23.741s - Extremely High Resolution Star Texture)


The above picture has a star texture of about 20% the resolution of the bottom. At first, I couldn't see any difference between the two pictures, but now I think the bottom image has a sharper background.

Sunday, April 27, 2008

Better Scene Layout

I like this layout more.


(2048 x 2048 -- 256 samples / pixel -- rendering time = real 426m19.944s, 7 hours 30 minutes on a 1800 mhz P4 )

Saturday, April 26, 2008

Transparancy + Reflection

Today I finished the last regular assignment for my ray tracing course - transparancy & reflection! Here are some of the images I generated.


Extremely High Resolution Image (2048 x 2048 -- 128 samples / pixel -- rendering time : real 279m22.153s, a bit over 4 hours)


This is the first image that I generated with spheres of different index of refraction, and ratio of reflectance to transmission. Overall, I think it looks pretty cool. There are a few minor changes I would like to make, but they shouldn't take too long. The sky needs to be changed from my polluted sky brown to a beautiful blue, the small middle sphere looks like it is getting clipped by the camera and the two upper spheres need more reflectance. This was still a ton of work getting here.


I like the color of the balls visible in this one



A box and a sphere



Messing with a transparent sphere and box



Some reflection





One of the passes at multiple spheres - after getting this far scene layout is taking a while


Index of refraction = 1.0, with some phong shading going on


Totally reflective - but still phong shaded

I also found an interesting blog by Pete Shirley, a professor at the University of Utah, about graphics. My professor, Joe Kniss, went to Utah and studied graphics. Check it out here. I also added him to the "friends links" that I support, even though we have never talked (so aren't friends).

Sunday, April 13, 2008

Axis Aligned Boxes - Stage 1 Complete!

Jon Bradley mentioned that Axis Aligned Boxes would be good to test the dielectric shading with. Since Jon has the best ray tracer I've seen in the class, I thought it would be a good idea to listen to him.




Pass 1 - Axis Aligned Box



Pass 2 - Axis Aligned Box with Correct (matte) Shading



Pass 3 - Axis Aligned Box floating above the plane (rather than bisected)




Jon Bradley, possibly the best living programmer

Saturday, April 12, 2008

General Cleanup on Phong Shading

Today I spent a long time just working on the Phong model stuff that wasn't exactly correct in my ray tracer. I believe I have generally fixed my problems, but touching base with Nate Gaunt might be a good idea.

Coming soon : Dielectrics!



One of the "interesting" images I generated while getting this working...


1024 x 1024 @ 128 samples / pixel (both with a specular power of 25)

Thursday, April 3, 2008

Acceleration Data Structure - Bounding Volume Hierarchy

I finished my bounding volume hierarchy earlier this week and I wanted to post my results and my code. The design is base on a binary tree, with each level splitting the higher level in half. Currently, I simply alternate between splitting along the three planes I have an option of splitting on. My initial structure is simply the bounding box of the .obj file (two points - one constructed from the smallest x, y, and z values and the other from the largest values.)

The basic binary tree stuff is sort of from here, but I wrote my own search routine and modified the code a bit.


The major point that could be improved on this is the splitting. Instead of alternating between the dimensions that I split on, I could write a method that determines the best way to split (based on the equality of the triangles in each subdivision.)

I spent a while getting this page to display in a somewhat aesthetic manner. Copy and paste between Kate and Firefox doesn't always look so great, and my blogger template doesn't lend itself to major widening my posts very well.

For a .tar.gz of this current revision, you can download one here. For the acceleration data structure, check out Object.cpp and Object.h.

1 Box (single bounding box)


real 0m24.015s
user 0m12.120s
sys 0m0.070s


2 Boxes -

real 0m16.169s
user 0m8.080s
sys 0m0.030s


16 Boxes -

real 0m9.564s
user 0m5.310s
sys 0m0.050s



From 1 bounding box to 2 it is very easy to see the running time getting cut in half. From 2 to 16, there is not such an obvious speed up. I believe this is because we have to traverse more levels of our tree (not too much locality) verse iterate through bigger triangle vectors (more locality.) If my model had more triangles, I think we would still see an exponential decrease in running time as we increase the number of leaves in the binary tree.




void Object :: BuildLevels(TreeNode * rootNode, int currentDepth, int splitDimension){

cout << "debugging = " << debugging << "\n";
debugging = debugging + 1;
cout << "currentDepth = " << currentDepth << "\n";

assert (rootNode->item != NULL);6

BoundingBox parentBox = *(rootNode->item);

int maxDepth = 16;

TreeNode * left, * right;

left = new TreeNode();
right = new TreeNode();

rootNode->left = left;
rootNode->right = right;


BoundingBox * leftBox, * rightBox;

Point3D smallPoint = parentBox.getSmallPoint();
Point3D bigPoint = parentBox.getBigPoint();


if (splitDimension == 0){
// split along x
float halfx = (parentBox.getSmallPoint().x + parentBox.getBigPoint().x) / 2;

// Let's start with the smaller box along an x cut
// it is defined by the smallest origional point and
// the x-cutpoint, y-maxPoint and z-maxpoint

leftBox = new BoundingBox(smallPoint, Point3D(halfx, parentBox.getBigPoint().y,parentBox.getBigPoint().z));

// the right box is defined by the x-cutpoint, y-minPoint,
// z-minPoint and the bigPoint from the origional box
rightBox = new BoundingBox(Point3D(halfx, parentBox.getSmallPoint().y, parentBox.getSmallPoint().z), bigPoint);
}

if (splitDimension == 1){
// split along y
float halfy = (parentBox.getSmallPoint().y + parentBox.getBigPoint().y) / 2;

leftBox = new BoundingBox(smallPoint, Point3D(bigPoint.x, halfy, bigPoint.z));
rightBox = new BoundingBox(Point3D(smallPoint.x, halfy, smallPoint.z), bigPoint);
}

if (splitDimension == 2){
// split along z
float halfz = (parentBox.getSmallPoint().z + parentBox.getBigPoint().z) / 2;

leftBox = new BoundingBox(smallPoint, Point3D(bigPoint.x, bigPoint.y, halfz));
rightBox = new BoundingBox(Point3D(smallPoint.x, smallPoint.y, halfz), bigPoint);
}

left->item = leftBox;
right->item = rightBox;

// let's go through all the triangles in the root and
// assign them to the left box, right box or both.

for (int i = 0; i <>triangles.size(); i++){

Triangle * myTriangle =rootNode->triangles[i];


if (triangleInsideBox(myTriangle, *leftBox) == true){
// add the triangle to the left box
left->triangles.push_back(myTriangle);
}

if (triangleInsideBox(myTriangle, *rightBox) == true){
right->triangles.push_back(myTriangle);
}

if ((triangleInsideBox(myTriangle, *rightBox) == false) && (triangleInsideBox(myTriangle, *leftBox) == false)){
cout << "ERROR!!! TRIANGLE IN NEITHER BOX!" << "\n";
}

}


if (currentDepth < maxDepth){
BuildLevels(left, currentDepth + 1,(splitDimension + 1) % 3);

BuildLevels(right, currentDepth + 1,(splitDimension + 1) % 3);

rootNode->triangles.clear();
}

else{
cout << "number of boxes in leaf = " << rootNode->triangles.size() << "\n";

}
}















Monday, March 17, 2008

.OBJ Loading Up

Hey Hey,

With the help of the two Nate's (Nate Gauntt helping with indexing into Nate Robbins GLM stuff) I was able to load in .obj files.


First (working) image generated from an .obj file
1 sample / pixel



As we swim closer to the dolphins...



We begin to question, why were they red?


This took a while to render:
real 5m35.747s
user 4m45.890s
sys 0m2.280s

.OBJ model can be found here. Source is will be here (once the UNM CS network is up, that is.)

Saturday, March 8, 2008

Done - until refactoring

I still have a few errors in my ray tracer. If you closely look at the green sphere, it should be cut by the plane. Also, the order that I add items to my scene object list currently matters in my ray tracer. This is because I do way too much of the scene shading in the object hit function. In order to fix this, I really need to add more methods to my parent GeometricObject class, and stop implementing things in the derived classes. This is going to take a bit of refactoring, but once I get some sort of version control (SVN) setup I should be able to move forward.


Sphere with Cool Texture by Autumn Stinar

I really, really, really like the artwork my sister sends me. Most of the time for Christmas or my birthday, I ask her for art as presents. The texture I wrapped the sphere in is from a picture message she sent me of a piece inspired by trance lyrics. Since the image was taken with a camera phone (and edited a bit by me) it isn't the highest resolution in the world. I have a view other abstract pieces I want to scan at extremely high resolution and use for sphere textures. My goal is to have an entire scene with her textures.


256 samples / pixel

Earth + Plane


Earth above a plane - 32 samples / pixel - no shading



Earth above a plane - 32 samples / pixel - matte shading




Earth above a plane - 128 samples / pixel - matte shading

Friday, March 7, 2008

Tiled Plane = Super Easy to test Anti-Aliasing

It is really, really clear what my anti-aliasing is doing when looking at the plane fading out into the distance. Below are some images (no shading - it is easier to see the plane approach the horizon without any shading) of different sample rates. Getting the plane to work took a bit of trial and error, but I think it is looking OK.

I used a completely square image that tiles perfectly. Here's the tile pattern I used (thanks Nate Gauntt):







1 sample per pixel = ugly



16 sample per pixel = better



5,000 samples per pixel (yes, 5k - I ran it for 6 hours on a university machine)

Thursday, March 6, 2008

Thanks Nate!

Nate and I talked about my bug for about 15 minutes and we were able to find it! I was totally calculating the index into my images incorrectly:

tmpColor = RGBVector[width * vertical + horizontal]; // correct

tmpColor = RGBVector[height * vertical + horizontal] // totally wrong




Map of the Earth, as taught in Panama

Square Textures = Perfect, still some issues with non-square textures

Today I spent a lot of time with my host for my SIBBS class. The speaker, Dr. Julia Cole, is a totally awesome researcher. Listening to her talk, eating a bunch of free meals and hanging out with a number of very intelligent people from all different disciplines made hosting the visit a lot of fun. It still was a lot of work and the experience involved choosing what to sacrifice so I could make the visit enjoyable. I wasn't able to work on graphics quite as much as I would like, but I have made some good progress.

Spherical mapping from a square texture to a sphere is at 100%. Check out the grid texture below Nate Gauntt send me for testing and it perfectly mapped to the sphere.

Welcome to Grid World!


The Square (255 x 255) Texture


However, all is not good and right in Grid World. If I, even slightly, modify the texture to be anything other than a square, it looks really messed up. Check it out below with the (252 x 255 grid):


I must be indexing into Y incorrectly...

Tuesday, March 4, 2008

Anti-Aliasing Looking Good!

Hey hey, it looks like I have random anti-aliasing looking good! I have been working extremely solidly on this project since it was up on the course website. For the next assignment that Joe briefly mentioned, I am going to get started the day after I turn this in, or directly after I turn this in REGARDLESS of when it is posted.



Here's an image I generated from an Earth texture @ 16 samples per pixel. However, I massively shrunk the original image. When I use my giant earth image, I am still getting some moray aliasing patters. I think I'll up the number of samples to 64 or 128 and try with the giant image.






1 Sample per Pixel


16 Samples Per Pixel


And the sweet, sweet code-ness:

....
RGBColor pixelColor = RGBColor(0,0,0);
int num_samples = 16;
float inv_num_samples = (1 / (float)num_samples);

RGBColor tmpColor;
for (int r = 0; r < c =" 0" o =" myWorld.ViewPlane.eyePoint;" count =" 0;" random1 =" (" random1 =" random1" random2 =" (" random2 =" random2" d =" myWorld.ViewPlane.from_screen_to_world(c+random1," tmpcolor =" myWorld.trace_ray(ray);"> 1){
tmpColor.r = 1.0;
}
if (tmpColor.g > 1){
tmpColor.g = 1.0;
}
if (tmpColor.b > 1){
tmpColor.b = 1.0;
}

tmpColor = tmpColor * inv_num_samples;
pixelColor = pixelColor + tmpColor;
}

myWorld.myfile << " " << (ceil( 255 * pixelColor.r)) << " " << (ceil( 255 * pixelColor.g)) << " " << (ceil( 255 * pixelColor.b)) << " "; // Don't forget to zero this out! This jacked me up bad. pixelColor = RGBColor(0, 0,0); ....

Sphere Texturing Done - Just need Anti-Aliasing

Things are looking all right with the spheres. You can completely see the moire patterns due to aliasing on the big sphere. Once I get a little more time to add content to this blog, I'll go over the math behind translating between world coordinated - polar coordinates - image coordinates.




Looking all right, if a bit aliased.


I'm not completely sure if I have the texture mapping completely right - it looks like only 1/4 of the below smiley texture mapping onto 1/2 of the sphere - I am fairly certain my polar - y image index is OK, but my polar - x may still need a little work. These concepts are not extremely difficult mathematically, but it takes a LONG time for me to code them up in C++.


Texture mapped onto the sphere - no shading




If people like checking this stuff out, leave me a comment! I've seen some hits from all over the world on this, and I would like to hear what you guys think.

Sunday, March 2, 2008

Looking Better

The texture mapping is going better. I think I may almost be done with the sphere. After contemplating a handball, and talking with my friend from Kazakhstan, I realized that when looking at a sphere from my angles, you will see the full -radius to +radius in two dimensions. However, the third dimension you will only see one radius worth of sphere. This is due to the self occlusion of the sphere; once you reach a (relative) peak, the sphere will be blocking itself. Maybe this seems obvious to many people, but for me it was a wonderful revelation while looking at the handball.

Ultimately, I realize that the Z-axis and Y-axis are incorrectly labeled in my code (they are switched). This hasn't been noticeable before, due to the self similar nature of all the objects I have ray-traced, but it explains why my relative positions look a little different than my class mates. Now, because of the above property, it makes a huge difference. I was repeating the texture below and above the equation.


More coming Soon
200 x 200 texture

Attempt at Texture Mapping on a Sphere

There is something weird going on around the poles; I may be calculating rho incorrectly by somewhere taking an absolute value or something. I should index different parts of the image if I am close to 0 or if I am close to Pi.

The red around the border is intentional - I was concerned with accessing elements of my image in a non sequential way, I thought this was the source of my problem. However, the non sequential accesses are as they should be, right around the edges of the sphere where I wrap around to the other side to get my texture.


Here is a big sphere with my texture mapped to it - no shading



Here's the texture - generated in Gimp

Wednesday, February 27, 2008

Code Up

Here's a link to my code.

Download it

A lot of the basic math stuff was taken from this guy, who wrote the book I paid almost $100 for. Since I signed up with amazon's referal program, I will have a link up soon for everyone to purchase the book from.

Next up is antialiasing and texture mapping. My plane will have a checkerboard and my sphere will have a texture of the earth. I hope everyone enjoys.