= Final Project = == Group Members == Christina Chan [[BR]] Crystal Fong == Project Proposal == Our final project proposal can be found at CrystalFong/FinalProjectProposal == Overview == The goal of our project is to render an underwater scene of clownfish and sea anemone. To achieve this, we implemented two different subsurface scattering techniques to simulate the glowing and lighting of an underwater image. == Reference image == ||attachment:iphone.png|| == Approach == == Fish (Christina) == === Model === The fish model used in the project was acquired from the web (http://toucan.web.infoseek.co.jp/3DCG/3ds/FishModelsE.html). We used the wavefront pbrt plug-in provided by Mark Colbert to load the model. Since different segments of a fish display different material properties, we had to separate the model into parts. This is done by parsing the OBJ file, and noting the discontinuities in the model. [[BR]] attachment:fish_model.jpg [[BR]] In order to simulate the texture of a fish, we attempted to create a scale model and procedurally cover the fish body with it. However, that gave a clumpy appearance, and significantly increased the rendering time. We therefore decided to apply bump mapping to the body and the fins instead. [[BR]] Scale model: [[BR]] attachment:scale_model.jpg Sphere covered with scales: [[BR]] attachment:sphere_scales2.jpg Fish body covered with scales: [[BR]] attachment:fish_scales.jpg Bump map texture for fish body: [[BR]] attachment:scales6.jpg [[BR]] === Techniques === To accurately simulate the transparency and the reflective behavior of fish scales, and the softness of fish fins, we implemented the thin film subsurface scattering method described in the “Reflection from Layered Surfaces due to Subsurface Scattering” paper. Because of the thinness of scales and fins, we used a first order approximation, which assumed single scattering event. To implement this, we created two BxDF subclasses, one for reflection and one for transmission. [[BR]] [[BR]] In the reflection model, the radiance included two terms, one for surface reflection and one for subsurface reflection, and the terms are weighted according to the Fresnel coefficients: * f_r= R*f_r,s + (1-R)*f_r,v Backscattered radiance is computed using the following equation: * L_r,v(theta_r, phi_r)= W*T12*T21*phase*cos(theta_i)/(cos(theta_i)+ cos(theta_r))*(1-exp(-tau_d*(1/cos(theta_i)+ 1/cos(theta_r)))*L_i(theta_i, phi_i) where the phase function is estimated using the Henyey-Greenstien formula: * Phase= (1/4*pi)*(1-g^2)/(1+g^2-2*g*cosj)^(3/2) The parameters used are close to those of epidermis given in the paper. The mean cosine of phase function (g) was varied according to the part of the fish. For example, scales are more reflective than fins and thus have a smaller g to give higher backscattering. [[BR]] [[BR]] In the transmission model, the forward scattered radiance is given by * L_t,v(theta_t, phi_t)= W*T12*T23*phase*(cos(theta_i)/(cos(theta_i)-cos(theta_t))*(exp(-tau_d/cos(theta_i)- exp(-tau_d/cos(theta_t))*L_i(theta_i, phi_i) In the case where cos(theta_t)==(cos(theta_i)), the following equation is used to avoid singularity: * L_t,v(theta_t, phi_t)= W*T12*T23*phase*tau_d/cos(theta_t)*exp(-tau_d/cos(theta_t))*L_i(theta_i, phi_i) Test image of the fish: attachment:fish_trial.jpg === Technical Challenges === One of the challenges of creating a realistic rendering of a clown fish is to get the textures right. All texture maps (including color textures and bump map textures) were created in Photoshop. Surprisingly, it was very difficult to get the textures right due the stretching effect during texture mapping. In hindsight, we should have modified the wavefront pbrt plug-in to obtain texture coordinates. The following is the color map used for the fish body: attachment:KumanoT2.jpg [[BR]] == Anemone (Crystal) == === Model === The anemone model was procedurally generated using a python script to create a scene file. Each anemone stalk has a Catmull-Rom spline as a backbone, and is modeled using generalized cylinders (see the Resources section for a link to a tutorial). The script takes a control point list as input to set the initial spline curvature. To interpolate one point, it is necessary to have 4 control points (2 on each side of the desired point.) Intermediate points are generated using the following equation where p_i is a control point and t is a value between 0 and 1 that represents the distance of the desired point from the second (P1) point (where t=0 is at P1 and t=1 is at P2). [[BR]] q(t) = 0.5 * ((2 * P1) + (-P0 + P2) * t +(2*P0 - 5*P1 + 4*P2 - P3) * t2 + (-P0 + 3*P1- 3*P2 + P3) * t3) [[BR]] At each point(q), we calculate and store the normal(N), tangent(T) and binormal(B). This is accomplished by the following steps. * For the very first point, select T, N, and B. * For each point Q1: [[BR]] T1 = unit(Q1 - Q0)[[BR]] N1 = unit(B0xT1) where x is the cross product[[BR]] B1 = unit(T1xN1) [[BR]] * store T,N, and B with each point After the spline is fully specified, each vertex(q) along the spline becomes the center point of a ring of vertices that will define the cross-section of the stalk at that point. The stalk starts out with a maximum radius of .5 and tapers as it grows upwards. At 5/8 * height of stalk, a bulb shape is formed by using a sin function to control the radius of the stalk. Each point(c) on the ring of vertices are calculated by c = radius * (cos(theta),sin(theta),0) where theta is an angle between 0 and 2pi. The point is then translated based on the normal (N) and binormal(B) of current the spline vertex. This is to avoid twisting of the generalized cylinder. We used the following equation to calculat the translated point: [[BR]] translated point = c.x * N + c.y*B + q [[BR]] When all of the points have been generated, a triangle mesh is created and saved in the format of a pbrt scene file. Each anemone is a variation of the input control vertices, but each are translated to a different position, and the spline is modified somewhat to make each stalk unique. To ensure that the stalks do not intersect, each stalk attempts to place itself in such a position that there is not another stalk within a defined radius of each of its spline points. [[BR]] Here is a preliminary image of the anemone stalks after generation. attachment:splines.png === Techniques === To create the translucent and somewhat luminecent look of the anemone, we implemented the BSSRDF algorithm (A Rapid Hierarchical Rendering Technique for Translucent Materials) by Jensen and Buhler. This method is a two pass process where during the first pass, the irradiance at each point is stored in a hierarchical structure to enable fast lookup. The second pass computes the exitant radiance for each point by using a dipole diffusion approximation which uses the cached values from the first pass. [[BR]] The following steps were taken to implement the BSSRDF: * A new material class was created to allow the user to specify which objects use the BSSRDF in their lighting calculations. The material specification allows the user to specify the absorption, scattering and the refraction index from the scene file. * Methods were added to the TriangleMesh class to return the vertices, number of vertices and surface area for a given object. * The API was modified to store a vector of primitives (along with each primitive's surface area, number of points and vecter of vertices) that use the BSSRDF. This vector is then passed to the Scene class. * To sample the irradiance, the paper recommends using a uniform distribution to obtain sample locations on the geometry. Instead of using the the recommended method to sample the geometry, we decided to use the vertices of each anemone stalk directly. This worked relatively well, see the Technical challenges section for further information. * An octree (based on the PBRT's octree class, but modified to suit our needs) was created to store the irradiance samples for the models in the scene using the BSSRDF for lighting calculations. Our implementation of the BSSRDF requires the use of photon mapping to calculate the irradiance for each of the points. After the photon map has finished preprocessing, we create our octree by indexing into the direct photon map (we do not use the caustic or indirect maps for our calculations) with each vertex. Each node in the octree contains the average location (weighted by luminance), the irradiance (weighted by the area) and surface area for the samples contained within it. Each parent node contains the aggregate information of all of its children (meaning the topmost node contains the irradiance, average location, and surface area for all of the primitives that use the BSSRDF in the scene. * The BSSRDF lighting calculation is called from the Li() method of the PhotonIntegrator class. When a ray intersects an object that uses the BSSRDF in the scene, we use the intersection point to index into our octree. This is done quickly by using an approximation of the maximum solid angle(delta_w) of the voxel. [[BR]] delta_w = Area of voxel/ || intersection point - average loc. of voxel || ^2^ [[BR]] If delta_w is greater than a predetermined error value, then we continue down the tree, comparing voxels against delta_w until delta_w <= the error term. Once a suitable voxel has been found, we evaluate the exitant radiance at that point. [[BR]] The total radiant exitance is computed by using the dipole diffusion approximation. [[BR]] Mo_p(x) = Fdt(x) * (dMo(x)/a'dPhi_i(Pp)) * Ep * Ap [[BR]] where,[[BR]] Pp = avg location of irradiance samples in voxel [[BR]] Ep = irradiance of voxel [[BR]] Ap = avg. surface area of voxel [[BR]] dMo(x)/a'dPhi_i(Pp) = radiant exitance/(reduced albedo * incident flux) [[BR]] Fdt = diffuse Fresnel transmittance [[BR]] * for the calculations of these subterms see Jensen and Buhler's paper. [[BR]] The radiance given by: [[BR]] Lo(x,w) = (Ft(x,w)/Fdr) * Mo(x)/pi [[BR]] where,[[BR]] Ft = Fresnel transmittance [[BR]] Fdr = diffuse Fresnel term [[BR]] The radiance term was then multiplied with the rho term in the BSDF to allow contributions from the texture map. [[BR]] We decided to weight the BSSRDF calculation by .8 and add it to a .2 contribution of the diffuse (Lambertian) lighting calculations because we noticed that our images from the top view looked a bit flat. [[BR]] Here are a few example images rendered with different material settings ||Rendered with diffuse only (no BSSRDF) ||single stalk with skim milk settings||single stalk with green settings|| ||attachment:fishTrial_layout.png ||attachment:fishTrial_skimmilk_side.png ||attachment:fishTrial_green_side.png || === Technical Challenges === We had some problems with having circular artifacts in our images. This was a particularly bad case: [[\ BR]] attachment:fishTrial3_4.png [[BR]] This was most likely due to the fact that we were using vertices from the triangle mesh as our sample points for the octree. The octree might not have contained samples that were close enough together. The problem was partially solved by increasing the number of photons that were shot into the scene. To further reduce these artifacts, we increased the value of our error term against which the solid angle of the voxel is compared against. This however, led to rendered scenes that looked quite flat because more points were using the same irradiance values from the trees. We remedied this by mixing our BSSRDF calculation with a small portion of the diffuse calcuation. This seemed to work well and we were able to put a sense of depth back into the scene. == Final Image == attachment:fish_3.png == Source Code == The new and modified source code files can be found [attachment:modifiedCode.zip here]. == Resources == Pat Hanrahan and Wolfgang Kreuger: [http://graphics.stanford.edu/papers/subsurface/ "Reflection from Layered Surfaces due to Subsurface Scattering"] Computer Graphics (Proc. SIGGRAPH 1993), July 1993 [[BR]] Henrik Wann Jensen, Stephen R. Marschner, Marc Levoy and Pat Hanrahan: [http://graphics.stanford.edu/papers/bssrdf/ "A Practical Model for Subsurface Light Transport"]. Proceedings of SIGGRAPH'2001. Henrik Wann Jensen and Juan Buhler: [http://graphics.ucsd.edu/~henrik/papers/fast_bssrdf/ "A Rapid Hierarchical Rendering Technique for Translucent Materials"] Proceedings of SIGGRAPH'2002 [http://www.cs.cmu.edu/afs/cs.cmu.edu/academic/class/15462/web.01s/assts/asst2_notes/primer.html Tutorial on generalized cylinders ] [http://www.mvps.org/directx/articles/catmull/ Tutorial on Catmull-Rom Splines]