1Greg HumphreysCS445: Intro GraphicsUniversity of Virginia, Fall 2004Local IlluminationRay CastingImage RayCast(Camera camera, Scene scene, int width, int height){Image image = new Image(width, height);for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j);Intersection hit = FindIntersection(ray, scene);image[i][j] = GetColor(scene, ray, hit);}}return image;}WireframeRay CastingImage RayCast(Camera camera, Scene scene, int width, int height){Image image = new Image(width, height);for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j);Intersection hit = FindIntersection(ray, scene);image[i][j] = GetColor(scene, ray, hit);}}return image;}Without IlluminationRay CastingImage RayCast(Camera camera, Scene scene, int width, int height){Image image = new Image(width, height);for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j);Intersection hit = FindIntersection(ray, scene);image[i][j] = GetColor(scene, ray, hit);}}return image;}With IlluminationIllumination• How do we compute radiance for a sample ray?Angel Figure 6.2image[i][j] = GetColor(scene, ray, hit);Goal• Must derive computer models for ... Emission at light sources Scattering at surfaces Reception at the camera• Desirable features … Concise Efficient to compute “Accurate”2Overview• Direct (Local) Illumination Emission at light sources Scattering at surfaces• Global illumination Shadows Refractions Inter-object reflectionsDirect IlluminationModeling Light Sources• IL(x,y,z,θ,φ,λ) ... describes the intensity of energy, leaving a light source L, … arriving at location(x,y,z), ... from direction (θ,φ), ... with wavelength λ(x,y,z)LightEmpirical Models• Ideally measure irradiant energy for “all” situations Too much storage Difficult in practiceλOpenGL Light Source Models• Simple mathematical models: Point light Directional light Spot lightPoint Light Source• Models omni-directional point source intensity (I0), position (px, py, pz), factors (kc, kl, kq) for attenuation with distance (d)2qlc0kkkIddIL++=dLight(px, py, pz) Directional Light Source• Models point light source at infinity intensity (I0), direction (dx,dy,dz)0IIL=(dx, dy, dz)No attenuationwith distance3Spot Light Source• Models point light source with direction intensity (I0), position (px, py, pz), direction (dx, dy, dz) attenuation2qlc0kkk)(IddLDIL++•=dLight(px, py, pz) DLγOverview• Direct Illumination Emission at light sources Scattering at surfaces• Global illumination Shadows Refractions Inter-object reflectionsDirect IlluminationModeling Surface Reflectance• Rs(θ,φ,γ,ψ,λ) ... describes the amount of incident energy, arriving from direction (θ,φ), ... leaving in direction (γ,ψ), … with wavelength λSurface(θ,φ)(γ,ψ)λEmpirical Models• Ideally measure radiant energy for “all” combinationsof incident angles Too much storage Difficult in practiceSurface(θ,φ)(γ,ψ)λOpenGL Reflectance Model• Simple analytic model: diffuse reflection + specular reflection + emission + “ambient”SurfaceBased on modelproposed by PhongOpenGL Reflectance Model• Simple analytic model: diffuse reflection + specular reflection + emission + “ambient”SurfaceBased on Phong illumination modelBased on modelproposed by Phong4Diffuse Reflection• Assume surface reflects equally in all directions Examples: chalk, claySurfaceDiffuse Reflection• How much light is reflected? Depends on angle of incident lightSurfaceθDiffuse Reflection• How much light is reflected? Depends on angle of incident lightSurfacedL!= cosdAdLdAθDiffuse Reflection• Lambertian model cosine law (dot product)LDDILNKI )( •=SurfaceNLθOpenGL Reflectance Model• Simple analytic model: diffuse reflection + specular reflection + emission + “ambient”SurfaceSpecular Reflection• Reflection is strongest near mirror angle Examples: mirrors, metalsNLRθθ5Geometry of ReflectionNIRN(I)θiθrθi=θrGeometry of ReflectionNIRN(I)θ θθi=θrcos(θi)NGeometry of ReflectionNIRN(I)θ θθi=θr-(I.N)N-I-2(I.N)N( ) ( ) ( )( ) ( )22NNR I I I N NR I I I N N+ ! = ! •= ! •Specular ReflectionHow much light is seen?Depends on: angle of incident light angle to viewerNLRVViewerαθθSpecular Reflection• Phong Model cos(α)nLnSSIRVKI )( •=NLRVViewerαθθThis is a physically-motivated hack!OpenGL Reflectance Model• Simple analytic model: diffuse reflection + specular reflection + emission + “ambient”Surface6EmissionEmission ≠ 0• Represents light emanating directly from polygonOpenGL Reflectance Model• Simple analytic model: diffuse reflection + specular reflection + emission + “ambient”SurfaceAmbient TermThis is a total hack (avoids complexity of global illumination)!• Represents reflection of all indirect illuminationOpenGL Reflectance Model• Simple analytic model: diffuse reflection + specular reflection + emission + “ambient”SurfaceOpenGL Reflectance Model• Simple analytic model: diffuse reflection + specular reflection + emission + “ambient”SurfaceOpenGL Reflectance Model• Sum diffuse, specular, emission, and ambientLeonard McMillan, MIT7Surface Illumination Calculation• Single light source:LnSLDALAEIRVKILNKIKII )()( •+•++=NLRVViewerαθθSurface Illumination Calculation• Multiple light sources:))()((!•+•++=iiniSiiDALAEIRVKILNKIKIINL2VViewerL1Overview• Direct Illumination Emission at light sources Scattering at surfaces• Global illumination Shadows Transmissions Inter-object reflectionsGlobal IlluminationHenrik Wann JensenGlobal IlluminationShadows• Shadow term tells if light sources are blocked Cast ray towards each light source Li Si = 0 if ray is blocked, Si = 1 otherwise 0 < Si < 1 soft shadows (hack)!•+•++=LLLnSDAAEISRVKLNKIKII ))()((ShadowTermRay Casting (last lecture)• Trace primary rays from camera Direct illumination from unblocked lights only!•+•++=LLLnSDAAEISRVKLNKIKII ))()((8 I = IE+ KAIA+ (KD(N • L) + KS(V • R)n)SLILL!+ KSIR+ KTITRecursive Ray Tracing• Also trace secondary rays from hit surfaces Global illumination from
View Full Document