Sunday, December 15, 2013

[Note] Light Transport Path Integral

From previous post, we've known what rendering equation is:

    L(x, w) = Le(x, w) + Integral(BRDF(x, w(x, x'))L(x', w(x', x))G(x, x')V(x, x')dA'

    x: surface element receiving incoming lights
    w: reflection direction
    w(x', x): direction from x' to x
    G: geometry factor
    V: visibility
   
This is the calculation based on a point on a surface. When producing final image, it actually involves light paths from the light sources to the camera.

Take a look at the (L) inside Integral, this incoming light for point x is also a reflection light for point x', and for point x' itself, it has its own rendering equation. That is to say, if we replace each L inside integral with its rendering equation repeatedly, we will get a multi-integral equation which is called "Measurement contribution function":

 

Screenshot from 2013 Siggraph course by Jaroslav Krivanek

the greek letter rho is actually BRDF

In order to solve this multi integral equation, the general approach is using Monte Carlo integration.


 Screenshot from 2013 Siggraph course by Jaroslav Krivanek

 The main idea of Monte Carlo is utilizing sampling to approximate solutions. For reducing variance, there are many ways to generate samples. here we talk about importance sampling. It is based on probability density function (pdf). Basically, it generates more samples on the region where contributes more to the result, and less samples on the part which doesn't influence the result that much. And because for the region with more samples, the interval of each sample should be smaller, that is why it uses f(x)/p(x) to have proper weight.

Now come back to the light paths integral. With Monte Carlo, we need to know how to properly sample the light path, and what is the probability density of that sampled path to have Monte Carlo estimator ready to be evaluated.

About path sampling, there are different algorithms (ex: path tracing, light tracing, and bidirectional path tracing). Here uses path tracing for instance, the sampling process is based on what is called "local path sampling", which means sample one path vertex at a time. The procedure has three main steps:

 Screenshot from 2013 Siggraph course by Jaroslav Krivanek

 (1) sample a path vertex from the camera, if using light tracing, sample from the light instead. For camera, usually sample with uniform distribution over the lens surface; for light, sample based on emitted power distribution

(2) shoot a random ray thought image plane to extend the path and get the intersection point

(3) from this intersection point, either sample a direction to shoot another ray based on the BRDF repeatedly until reaching the light source, or test the visibility with the light source and connect them together to form a complete light path

Since local path sampling importance sample the contribution function associated with each path vertex, we can be sure that the path with higher contribution would have more possibility to be sampled.

About the probability density of the sampled path, it's quite straightforward,
    p(x) = p(x0, x1, x2, x3) = p(x3)* p(x2|x3) * p(x1|x2) * p(x0)
    x stands for the whole path
    x3 is camera, x0 is light (assume both are sampled using uniform distribution), x1 and x2 are other path vertices along the way

Simply put, it's the product of conditional pdf of each path vertex.


Friday, November 22, 2013

[Unity] Mobile Test Setup


After 2 years without using Unity, got to grab some memory back :)

Android
1. Install Android SDK
2. use Android SDK Manager to install platform files & USB Driver (platform 19 seems not working, I used 17 instead)
3. enable "Unknown Sources" on Android to allow non-GooglePlay apps installation
4. install any file manager for the device (I used the one from rhythm software)
5. build .apk in Unity and copy it into the device
6. use file manager, navigating to where the apk is.  Install, Done!

iOS
On Unity side, just go to the player settings, make sure the bundle ID matches the one in provisioning profile, target iOS version should be set by default to the oldest.

http://www.brianjcoleman.com/tutorial-provision-your-app-to-run-on-a-device/

I found this tutorial written by Brian Coleman quite helpful. The only few things it doesn't mention is you might need to set up the deployment target in Xcode and make device "use for development".


Thursday, November 21, 2013

[Note] Rendering Equation




Differential Solid Angle:
Since light is measured as energy per unit surface area, when we talk about incoming light, we actually mean the amount of light from a small region instead of a beam with single direction.

Differential solid angle is used here for this purpose.
(radius equals to 1 so it's ignored)
it can be treated as a tiny flat region on the unit hemisphere of the object surface element , and because it's tiny and flat, we can assume this region is uniformly illuminated.

The region where the lights come from doesn't have to be on the hemisphere, it can be from some other surface area in the scene. In this case, the differential solid angle formula needs to be changed a bit:

 

 

BRDF:
BRDF is used to describe how much light is reflected. It's defined as a ratio of reflected light in direction Wo to the amount of light hitting the surface element from direction Wi.

if incoming light is from a region on the hemisphere:

dw is the differential solid angle, and remember it's a tiny area that is uniformly illuminated, so we multiply it by Li to get the total amount of light from that region. And because we need to know the amount of light hitting the object surface element, we have to project light from that region onto the surface element. That's where the cosine comes from.

From this BRDF formula, we can get a basic reflection equation:
Lo = BRDF * Li * cos(theta) * dw

if incoming light is from other surface in the scene which mostly is the case, we need to replace the differential solid angle with the one just mentioned above:

 
 

here we get G (geometry factor) =  

so reflection equation becomes Lo = BRDF * Li * G * V * dA
V here stands for visibility between 2 surface points.

OK, all the formulas above are based on one area of light in and one light out. However, in reality, there should be countless lights from every direction contributing to the final reflected light in the direction of an observer. So no doubt, integral !!

 

fr function inside integral is BRDF


Rendering Equation:
Finally time to get the rendering equation!! Basically, we just need to grab the reflection equation above, and add emitted radiance in it because the surface element itself may also be an emitter: