= 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.png [[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]] attachment:scale_model.png attachment:fish_scales.png attachment:sphere_scales.png attachment:scales6.png [[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 using the cornell box: attachment:cornell.png ==== 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 === 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 ==== ==== Technical Challenges ==== == 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]