Monday, April 23, 2012

GPU Final: Final Project

Final project

Finished everything. Correct the bugs in Fresnel reflection and also the gamma correction. Some images of the result:
Figure 1. Image rendered with 600 seconds. All features turned on. 
 Figure 2. Rendered with 400 seconds. Focus on mirror sphere
Figure 3. Rendered with 400 seconds. Focus on icosahedron


The following are the resources related to this project. The paper is my favorite, also the demo with a voice over could explain details related to this project.

Source: https://github.com/duxing/GPUFinal
Paper: https://docs.google.com/open?id=0BxjlXUodntYuRkpYU1ZnVmdyYzA
Demo: http://www.youtube.com/watch?v=7x0vuwqoLeY&feature=youtu.be
Or http://vimeo.com/40990912

Sunday, April 22, 2012

GPU Final: Week 6_2

This week I've been most working on the 660 final project. However I made something to show by now.

I made a few changes to the data structure and also fixed a small bug in my previous version. The changes are made mostly due to supporting new features.

The first thing added was Depth of Field. This part is done using a stochastic method based on purely physics. It's not computational heavy, cause I'm doing path tracing. If it has to be done in ray tracing, distributed ray tracing have to be used to generate a good result.
Here's a group of image showing lens with different focal plane (focus on different object).





Another feature is Fresnel refraction and reflection. I added this because I felt the transparent sphere in the scene seems weird, and then I realized that there should be reflection. This part is done also based on pure physics. Stochastic method is also used here to simulate different kinds of polarized light beams.

The third thing I did was analyzing the performance. Thanks to Varun, I learned to use Visual Profiler to see the detailed information of my program in run time, as well as occupancy calculator to find out the best block size for my program. Moreover, I changed the main PathTrace() function a little bit, and thus almost doubled the performance. In the previous version, I'm using a simpler scene and the fps is around 12, and now I've added a simple obj file into the scene, and rearranged the block size. The result is around 20 fps.

One last thing to say is I added a fps viewer. Showing not only the displaying frame rate(how frequently openGL is called draw function), but also the real rendering speed(how many layers rendered per second). In the process of adding this tool, I realized there's a certain need for my PathTrace() function to call cudaDeviceSynchronize(). And because I added this, the two frame rate displayed on the screen are almost the same all the time.

Here's two final image of my tracer. One takes 4 minutes to render and the other takes about 10 minutes. I just leave it running while writing this post.


Here's a image of previous version. No depth of field, no Fresnel equations, and also no obj files are added in the scene. You could make a comparison with former ones.



OK now I feel it's pretty much done for everything I thought possible to implement for final project. It's time to turn to my final paper and demo.

There's still lot's of future work to do, like continue with my previous cuda kdtree, and the image space photon mapping. This would definitely be my own projects during the summer.

Tuesday, April 17, 2012

GPU Final: Week 6

In the past week I've been working on my other final projects, and the only thing I did related to the GPU final is fixing a problem with generating secondary rays. In the final week, I'll be working on the required paper and video. Also an analysis of my final project is included.
I'll keep updating if I got more ideas.

Monday, April 9, 2012

GPU Final: Week5

The path tracer is ready. I modified the basic structure supporting both point light and area light, also the algorithm for path tracing.

Because it has to run on the GPU, with each thread in charge of a pixel, I build a color stack for each thread for unwrap the recursion. After primary rays are shooted, based on the material it hits, different kinds of secondary rays are generated  and used for later loop.

The idea of this path tracer compared to photon mapping, is to use Monte Carlo method to approximate the natural light. For random number generate, I used the thrust library. Although I haven't finished the planned photon mapping tracer, I got pretty familiar with some of common parts of the thrust library.

Apart from the light part, transparency and reflectivity are added compared to the first version of this path tracer last friday. Also a bug related to shading has been fixed.

I guess it's pretty much done for my final project. I've been working on this final project for the whole past 4 weeks. I'll spend less time on this from now on and turn to other two final projects.

If possible I'll add more feature to this path tracer and update the blog with it. For the photon mapping part, I've already build a frame work for it, and finished the photon tracing and large node construction of KD tree. I'll definitely finish that in summer, when I don't have that much pressure from the three final projects which keep me away from necessary sleeping.

Here's a picture rendered from the path tracer.

Global illumination features like the caustic effect could be seen directly from the image. Yet it takes a few minutes to render a picture with such quality. In real time it's more like a spotted image.
I'll see if it's possible to make it faster for higher quality image.

Saturday, April 7, 2012

GPU Final: Week 4_2

Since last post I've been working on GPU KD tree construction.

And I've been spending my whole past 4 days reading and implementing Kun Zhou's paper "Real-Time KD-Tree Construction on Graphics Hardware"

Good news is I've implemented part of the construction part. Bad news is that there's a few ambiguity in the paper and is not well illustrated. Based on the time I've already spent on this paper I made a prediction of how long it would take me to finish the KD tree part. Given the fact that I haven't started the other two final projects yet, I decided to do path tracing instead. The basis set up for photon mapping would be finished when I don't have that heavy coursework pressure.

So start off today I turned into path tracing. A preliminary result has come out, which come up with a nice rendered image but takes a few seconds to converge. Because I'm using a point light right now, the result looks a little bit dim.

I'll focus on tuning my framework to support other kind of lights in the coming days, and also dealing with reflection and transparency. Now the result only have diffuse part and is limited to effects like color bleeding.

I'll post a video when I'm satisfied with the result.

Thursday, April 5, 2012

GPU Final: Week 4

ok. I admit I lied to you.

I said I won't be working this week on GPU final but I just cannot stop.

Things are going well but slowly. I've been spend the first few days trying to figure out how to build a KDtree on GPU for the scene. Then I found out that is too hard and too heavy paper reading. So in the following days I've been working on the photons parts.

By now the photons part has pretty much been done. Here's a video rendering all the photons out based on the same scene of ray tracer. It's still capable to running in real time with 40K photons.

For the next step, I'll start to build the KD tree for photons so that I could finish the gathering part way much faster. For the photon part I've been spend a whole day on stream compaction just because of a weird unknown system error which would only occur in debug mode. Damn it wasted me around 12 hours. Anyway I solved that problem.

I like this feeling of exploring unknown things. I wish I could get some good result next week. Good luck to me!HAHAHAHA

Monday, April 2, 2012

GPU Final: Week 3

The past week is a important week.

First I gave up implementing the ISPM paper using G3D engine. It's ill documented and too complicated to start off and come up with a real time photon mapping tracer. Anyway, spending 2 weeks trying to implement such a fancy paper is a good experience. And I gradually understand the idea of the whole paper and start to know how to implement it. Thanks professor Morgan McGuire, not only for presenting this good idea but also for his patient answer to my questions.

I tried to implement ISPM from scratch using GLSL, and set up a basic framework for it. Then I realize the data structure might be a big problem for GLSL, so I turned to CUDA instead. Also I wish to lower the difficulty of my project. ISPM would be too hard to implement within the given time.

So I planned to implement a GPU photon mapping tracer or path tracer. Now I've already build a GPU ray tracer. Because I thought the CPU ray tracer is ill-written in format and structure, I build this from scratch.
It is done using CUDA. The tool bar is a third party library called "AntTweakBar". It's pretty much done the ray tracing part. Now I'm thinking about turning it into a path tracer or a photon mapping tracer. In addition I'm reading GPU Kdtree construction papers recently.  For the past three weeks I've spend all my spare time on GPU. So this week I would have to stop focusing on GPU and turn to my 660 and 563 final projects instead.

Here's a short video showing my present result. It's a simple Cornell box and the resolution is full 1K.