You are on page 1of 7

Smoke Ring Rendering using Photon Mapping

Maria Alejandra Montenegro Fall 2012

Previous Work: At the end of my spring semester Edward Eisenberger and I made a smoke simulation for the final project of our Advanced Computer Graphics class in approximately three weeks. Our simulation used and octree for optimization and the Monte Carlo ray tracing approach was used to render the smoke. After finalizing this project I realized there was much to be done to this project for me to understand the complexity of participating media. I realized how much I enjoyed the rendering part of this project and decided to continue the project until getting more satisfactory results. New Work: I researched and read multiple papers about smoke rendering trying to clear my mind and get a fresh new look to the project. With this in mind I decided to completely change the rendering algorithm I used in the project and moved from the Monte Carlos approach to photon mapping. As I restarted the project, I fixed my current ray marching algorithm and adapted it so I could use it in my new photon mapping approach. My ray marching implementation used a cylinder as step holder. This way I could have a fixed step size while increasing the radius of the cylinder to gather sufficient particles/photons. A volume photon map had to be created to be able to render the smoke. The implementation of the volume map was one of the most complicated problems I encountered. In most of the papers I read the construction of the volume map was ignored. They just stated they had it, making the development an interesting problem to solve. My initial volume map took into account fixed absorption and scattering coefficients throughout the entire smoke and it was stored in an octree.

Figure 1: Initial photon map tracing 10 photons out of 5000 (yellow dots). Tracing not taking into account smoke particles

Figure 2: Initial photon map tracing 10 photons out of 5000 (yellow dots). Tracing taking into account smoke particles

Figure 3: Initial Rendering

Looking at the initial volume map I realized there was something wrong. It was almost empty inside! After debugging the code and re analyzing the papers used for the implementation of the photon map rendering approach, I discovered I was doing a couple of things wrong. I could not have constant scattering and absorption coefficient throughout the smoke because the smoke in a ring varies density. I also realized I was storing the absorbed photons instead of the scattered. To fix these problems I first started debugging the transmittance calculation, one of the most essential parts of rendering smoke. A cylinder visualization was developed cylinders throughout the ray march to assure I was collecting the correct amount of particles needed and that they were indeed inside the cylinder. Cylinder math can get tricky at certain angles and this could be a big error down the line. At the same time I realized the octree has some bugs in storing the right amount of particles in the correct cell. It was originally just returning the particles of one cell when in some cases the cylinder was overlapping more than one cell. Once these two errors were fixed and the visualization data confirmed they were working properly I started working on the transmittance.

To debug the transmittance at each step, I creating a color coded visual of the transmittance throughout the media to see how it changed. It ranged from 1 to 0 (starting red (1) going to black (0) ). Once the visuals showed accurate results; calculations of out-scattering and absorption coefficients inside the media were made. Initially during the photon trace stage, I was adding the transmittance at each step. This created a drastic color change in the transmittance visualization which indicated that something was wrong.

After looking at this image under different smoke conditions (different densities) I realized I shouldnt be adding the transmittance at each step during photon trace. Instead, I should calculate the transmittance and if it was higher that the threshold (0.0001) the photons should keep walking. The transmittance was fixed by calculating the extinction coefficient in

every step of the ray-march. To calculate the extinction coefficient the absorption coefficient and the scattering coefficient have to be taken into account: double distance = step_width; double tav = 1-exp(-distance*densit double tsv = mR.rand()*tav*(1-tav); double k = tav + tsv; double T1 = 1-k; /* T1 + tav + tsv = 1 */

//absorption coefficient //scattering coefficient // extinction coefficient // transmittance

With the transmittance fixed and all the coefficients being calculated accordingly, the first scenes were rendered. The initial renderings were a good sign that the transmittance was being calculated correctly and the initial pass of tracing photons was working. These rendering also uncovered errors in the second pass, the scattering algorithm.

Figure 3: Rendering with high density: Particle mass=0.0012 gm, 1,000,000 photons

Figure 4: Rendering with in between density: Particle mass=0.00012 gm, 1,000,000 photons

Figure 5: Rendering with low density: Particle mass=0.000052 gm, 1,000,000 photons

The images showed great improvement, starting with initial scattering like we can see in the middle and right most images. Looking at the images and compering them with the parameters used to render them, errors can be spotted. The first error is the sharp edges that border the smoke. They should be smoother. Another error we can see is how the photons are aligned arising questions about octree errors again; or if it is an effect due to the fixed step size. Fixing the sharp edges consisted on looking into the ray marcher and finding where the edges were being formed. Originally, when marching down the ray I had a maximum radius the

cylinder could grow trying to catch particles. Once the radius was reached, if not enough particles were gathered, the ray marcher would just advance one step. I realized the value was too small, not allowing the smoke to affect a greater part of the scene as it should. Smoke is not encapsulated just where the ring is, in theory there should be some really light smoke all around. With this in mind, the max value was changed and adapted for a more realistic rendering of smoke, deleting the sharp edges we originally had. The second renderings did in fact get rid of the sharp edges as expected, but also introduced a new artifact, the sharp lines or spikes. Before solving the new error, I was more worried about why the photons were rendering aligned. During the debugging process of the photon map and how they were being added and rendered, I found that when adding photons to the volume map, the scattering angle wasnt changing, being constant for the entire scene. I fixed the error by scattering the photon in a new direction with a random angle every time. Compering both images of the volume photon map, its clear that a random angle is needed to really represent what happens inside the smoke and how they bounce around.

Figure 5: Photon map no random angle

Figure 6: Photon map with random angle

There was still something odd about the second volume map that didnt make sense. I started re-reading the papers now with more knowledge than before and I realize I wasnt taking into account the particles grabbed at the moment where the cylinder had reached its max radius and the amount of particles to grab was not reached. At this point, I was discarding the particles even if one particle was missing to successfully grab the amount needed. I changed my algorithm to add this step. Each time this step was encountered, I calculated

the variables as if I had cached the number of particles requires but then did all my calculation accordingly with the amount of particles grabbed. While debugging this I increased the step size of the ray march. As expected, a more accurate volume map and rendering were produced! With the new renderings, the alignment of the photons was fixed. With this error out of the ways I started searching for the cause of the weird spikes in the outside of the ring. To find out what was causing this error I started making rendering with very few particles to make sure the octree was working as expected. When rendering the scene with 20-100 particles I was expecting present circles to appear representing the cylinders march. As expected, the circles appeared and I knew that the problem was not the octree, which was a great relive because I had been debugging the octree for much too long. This image did reveille the cause of the lines in more dense renderings. As we start to see with the image in our left, where the circles start to overlap thin dark lines start to form. With denser rendering the lines are more pronounced and end up looking like artifacts in the side of the ring.

With this in mind a Poisson Disk was implemented to create a controlled random distribution of particles. Implementing Poisson Disk was not complicated. What was complicated was finding the right minimum radius particles had to be apart and the time it took for the particles ring to generate. For optimization, once I found the right radius I would save the particles ring in a text file so I could easily loaded up for efficiency.

Great improvement was visible in these rendering but it was visible that the renderings were not smooth instead they were splotchy. To fix the splotches a greater amount of particles and photons were gathered at each step. All the renderings until this point had been rendered with 8-20 particles and 25 photons collected at each step. The number of collected particles was increased first. It increased in small increments until I found that 55 particles gave better results while not increasing the rendering time drastically. At this point, a rendering with

4000 particles would take around 45 minutes with 10,000 photons. To smooth the rendering even more, a Gaussian filter was added.

Figure 7: 3,500 particles, particle mass: 0.00012, no photons just transmittance

Figure 8: Photon map: 10,000 photons

The final renderings of my project have almost all the bugs encountered fixed. I am well aware that there is a lot of research in this field to be done and this was a good experience for me to understand the complexity rendering participating media is. Compering my initial results to my final results show how far I have come on understanding the smoke rendering algorithm. Now I know by experience why participating media is considered one of the hardest problems in computer graphics, a field of never ending challenges.

Figure 9: Rendering with photons. Specs of above photon map

Figure 10: Rendering with photons. Same sects as above image, difference is it is in a black background

Bibliography:
Greve, B. d. (2004, October 10). Reections and Refractions in Ray Tracing. Retrieved from http://wwwinst.eecs.berkeley.edu/~cs184/sp11/resources/reflection_transmission.pdf Jensen, H. W. (1996). Global Illumination using Photon Maps. Department of Graphical Communication. Jensen, H. W. (1998). Efficient Simulation of Light Transport in Scenes with Participating Media using Photon Maps. Mental Images. Jensen, H. W. (2001). Realistic Image Synthesis Using Photon Mapping.

You might also like