09.07.2015 Views

Realistic Light Modelling with Photon Mapping in POV-Ray.

Realistic Light Modelling with Photon Mapping in POV-Ray.

Realistic Light Modelling with Photon Mapping in POV-Ray.

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Realistic</strong> <strong>Light</strong> <strong>Modell<strong>in</strong>g</strong> <strong>with</strong> <strong>Photon</strong> <strong>Mapp<strong>in</strong>g</strong> <strong>in</strong><strong>POV</strong>-<strong>Ray</strong>.Josh McCoyJuly 25, 2006Introduction<strong>Photon</strong> <strong>Mapp<strong>in</strong>g</strong>In computer graphics, photon mapp<strong>in</strong>g is a global illum<strong>in</strong>ation algorithm based onray trac<strong>in</strong>g used to realistically simulate the <strong>in</strong>teraction of light <strong>with</strong> different objects.Specifically, it is capable of simulat<strong>in</strong>g the refraction of light through a transparentsubstance, such as glass or water, diffuse <strong>in</strong>terreflections between illum<strong>in</strong>ated objects,and some of the effects caused by particulate matter such as smoke or water vapor.It was developed by Henrik Wann Jensen.In the context of the refraction of light through a transparent medium, the desiredeffects are called caustics. A caustic is a pattern of light that is focused on a surfaceafter hav<strong>in</strong>g had the orig<strong>in</strong>al path of light rays bent by an <strong>in</strong>termediate surface. Anexample is a glass of w<strong>in</strong>e on a table. As light rays pass through the glass and theliquid, they are refracted and focused on the table the glass is stand<strong>in</strong>g on. The w<strong>in</strong>e<strong>in</strong> the glass also produces <strong>in</strong>terest<strong>in</strong>g effects, chang<strong>in</strong>g the pattern of light as well asits color.With photon mapp<strong>in</strong>g, light packets (photons) are sent out <strong>in</strong>to the scene fromthe light source. Whenever a photon <strong>in</strong>tersects <strong>with</strong> a surface, the <strong>in</strong>tersection po<strong>in</strong>t,<strong>in</strong>com<strong>in</strong>g direction, and energy of the photon are stored <strong>in</strong> a cache called the photonmap. As each photon is bounced or refracted by <strong>in</strong>termediate surfaces, the energygets absorbed until no more is left. We can then stop trac<strong>in</strong>g the path of the photon.Often we stop trac<strong>in</strong>g the path after a predef<strong>in</strong>ed number of bounces <strong>in</strong> order to savetime. One of the great advantages of photon mapp<strong>in</strong>g is the <strong>in</strong>dependence of thescene’s description. That is, the scene can be modeled us<strong>in</strong>g any type of geometricprimitive as for <strong>in</strong>stance triangles, spheres, etc. [wikipedia]1


<strong>POV</strong>-<strong>Ray</strong><strong>POV</strong>-<strong>Ray</strong>, or Persistence of Vision <strong>Ray</strong>tracer, is a render<strong>in</strong>g and ray trac<strong>in</strong>g application<strong>with</strong> an open license and freely available source code. Specializ<strong>in</strong>g <strong>in</strong> high quality3D render<strong>in</strong>g, <strong>POV</strong>-<strong>Ray</strong> makes use of many computationally expensive algorithmswhen render<strong>in</strong>g a scene.[povray.org]Prepar<strong>in</strong>g Environment for Runn<strong>in</strong>g <strong>POV</strong>-<strong>Ray</strong>LAM/MPI EnvironmentTo run <strong>POV</strong>-<strong>Ray</strong> <strong>in</strong> parallel, a work<strong>in</strong>g LAM/MPI environment is needed. BCCDprovides a user, lambccd, <strong>with</strong> such an environment. SSH to a mach<strong>in</strong>e runn<strong>in</strong>g theBCCD as the lambccd user (the password should be ”bccd”):ssh lf0 -l lambccdPasswordless Authentication via SSHLogon to each mach<strong>in</strong>e <strong>with</strong> which you want to run <strong>POV</strong>-<strong>Ray</strong> as the lambccd userchose “yes” when prompted about start<strong>in</strong>g a heartbeat process and run bccd-allowall:bccd-allowallOn the mach<strong>in</strong>e from which you want to start the jobs, gather a mach<strong>in</strong>e list:bccd-snarfhostsConfirm your mach<strong>in</strong>e list:bccd-checkemObta<strong>in</strong><strong>in</strong>g the Curriculum ModuleUse the list packages command to br<strong>in</strong>g up a list of available curriculum modulesand software:list-packagesSelect the <strong>Photon</strong> <strong>Mapp<strong>in</strong>g</strong> package and press enter. The curriculum moduleshould now be <strong>in</strong>stalled <strong>in</strong> the home directory of the lambccd user. Enter the povraydirectory:cd povray2


Logg<strong>in</strong>g WalltimeAs you progress, record the time it takes to render the three scenes us<strong>in</strong>g eachrender<strong>in</strong>g method <strong>in</strong> the follow<strong>in</strong>g table:<strong>Ray</strong> Trac<strong>in</strong>g <strong>Photon</strong> <strong>Mapp<strong>in</strong>g</strong> DispersionGlass SphereDiamond BoxWater TorusModel<strong>in</strong>g a Glass SphereThe default render<strong>in</strong>g method of <strong>POV</strong>-<strong>Ray</strong> is ray trac<strong>in</strong>g. Run the sphere-rt.shscript./sphere-rt.shAfter the render<strong>in</strong>g is complete, view the animated gif, sphere-rt.gif, viafirefox (<strong>in</strong> firefox’s File menu, select open file and set the filter to image files).To start firefox, use the follow<strong>in</strong>g command:firefox &Notice how ray trac<strong>in</strong>g reproduces a translucent sphere while refract<strong>in</strong>g the lightas it passes through the glass.If the glass sphere was seen <strong>in</strong> a similar scene <strong>with</strong> real world light <strong>in</strong>teractions,you would see light light be<strong>in</strong>g focused by its refraction through the glass. As mentioned<strong>in</strong> the <strong>in</strong>troduction, this focus<strong>in</strong>g of light is called a caustic. One benefit ofphoton mapp<strong>in</strong>g is that it can form these caustics. Now, render the same glass sphere<strong>with</strong> photon mapp<strong>in</strong>g enabled by runn<strong>in</strong>g the sphere-pm.sh script:./sphere-pm.shView the results <strong>in</strong> firefox and notice the caustics produced by the sphere.Dispersion, or the separation of the wavelengths of light as the light is refractedthrough media, is shown <strong>in</strong> the next sphere to be rendered. Run the sphere-dis.shscript:./sphere-dis.shView the animated gif and exam<strong>in</strong>e the caustics and notice the dispersion (th<strong>in</strong>l<strong>in</strong>es of ra<strong>in</strong>bow-like color) at their edges.3


Model<strong>in</strong>g a Diamond BoxRun the script to render a diamond box <strong>with</strong> ray trac<strong>in</strong>g:./box-rt.shNotice the complexity of the light refracted <strong>in</strong> the box itself.F<strong>in</strong>d<strong>in</strong>g po<strong>in</strong>ts of collision of rays and photons <strong>with</strong> rendered objects (a processcalled collision detection) is a crucial computation to render<strong>in</strong>g <strong>in</strong> <strong>POV</strong>-<strong>Ray</strong>. As wasthe case <strong>with</strong> the set of sphere render<strong>in</strong>gs, detect<strong>in</strong>g collisions <strong>with</strong> a sphere is asimple algorithm and takes little time to compute. Detect<strong>in</strong>g collisions <strong>with</strong> a simplegeometric object, such as a box, takes slightly more computation. Run the same box<strong>with</strong> photon mapp<strong>in</strong>g enabled:./box-pm.shThe time it took to render this scene is much longer <strong>in</strong> comparison to the timeused to render the glass sphere <strong>with</strong> photon mapp<strong>in</strong>g. This is due to the amount ofcollision detection. Each time a photon hits a face of the box, one of two additionalcollision detections can take place: one if the photon is reflected by the surface andanother if the photon is refracted. Each photon or ray is traced through a scene whileit encounters reflective or translucent surfaces until it f<strong>in</strong>ds no collision is detected (itshoots off <strong>in</strong>to empty space)or the medium it hits does not reflect or call for furthertrac<strong>in</strong>g.When a medium disperses light dur<strong>in</strong>g refraction, additional photons correspond<strong>in</strong>gto the different wavelengths of the dispersed light need to be modeled. Run thediamond box <strong>with</strong> dispersion enabled to see the <strong>in</strong>creased workload needed to renderdispersed light:./box-dis.shModel<strong>in</strong>g a Torus Made of WaterRender the water torus <strong>with</strong> ray trac<strong>in</strong>g:./torus-rt.shWithout photon mapp<strong>in</strong>g, the shadow of a non-white and translucent object takesthe color of that object. A more complex and believable shadow can be rendered viacaustics. This is shown <strong>in</strong> the output of the render<strong>in</strong>g of our second torus:4


./torus-pm.shThe resultant animation looks much more realistic than the ray traced version.Also noticeable is the sharp <strong>in</strong>crease <strong>in</strong> render<strong>in</strong>g time. The torus is a more complexobject than either the box or the sphere and has many more faces for the photonsto <strong>in</strong>teract <strong>with</strong>. Now render the same scene <strong>with</strong> dispersion enabled:./torus-dis.shThe results should look identical to the previous animation. This is due to thefull spectrum, white light be<strong>in</strong>g filtered through a color medium. Only a s<strong>in</strong>gle wavelengthof light, correspond<strong>in</strong>g to the wavelength of the color of the water, transmitsthrough the torus. S<strong>in</strong>ce there is only a s<strong>in</strong>gle wavelength of light be<strong>in</strong>g refracted bythe torus, there are no separate colors of light to disperse. By look<strong>in</strong>g at the time ittook to render, it is evident that <strong>POV</strong>-<strong>Ray</strong> does not perform dispersion calculationson light of a s<strong>in</strong>gle wavelength.5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!