Shading Shading: determining light reflection from objects at each pixel. Basic Reflection Model:...

of 36 /36
Shading Shading : determining light reflection from objects at each pixel. Basic Reflection Model: Phong Reflection Model (most commonly used) I= k a I a + k d I d (l · n) + k s I s (v · r ) α I : reflected-light intensity
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    216
  • download

    1

Embed Size (px)

Transcript of Shading Shading: determining light reflection from objects at each pixel. Basic Reflection Model:...

  • Slide 1
  • Shading Shading: determining light reflection from objects at each pixel. Basic Reflection Model: Phong Reflection Model (most commonly used) I= k a I a + k d I d (l n) + k s I s (v r ) I : reflected-light intensity
  • Slide 2
  • Ambient Reflection: Direction independent k a I a I a : incident ambient-light intensity k a : object ambient-reflection coefficient part of the object material properties
  • Slide 3
  • Lambertian / Diffusive Reflection: Lighting-direction dependent I d k d (l n) = I d k d cos( ) I d : incident difussive-light intensity k d : object diffusive-reflection coefficient : angle between light direction (l) and surface normal (n). Both l and n are unit vectors.
  • Slide 4
  • Specular Reflection: Viewing-direction dependent I s k s (v r) = I s k s cos (). I s : incident specular-light intensity k s : object specular-reflection coefficient : angle between reflection direction (r) and viewing direction (v). : specular-reflection exponent, shaniness coefficient. 1/ : roughness.
  • Slide 5
  • The effects of ambient, diffusive and specular reflection.
  • Slide 6
  • The effects of ambient, diffusive and specular reflection. (http://en.wikipedia.org/wiki/Utah_teapot) Teapots shaded with different parameters.
  • Slide 7
  • Attenuation: Distance dependent, no impact on ambient light f att = 1/(a + bd + cd 2 ) d : distance from the light to the surface point. a,b,c: constant, linear, quadratic attenuation coefficients. I = k a I a + f att k d I d (l n) + f att k s I s (v r ) I = k a I a + I d k d cos( ) / (a + bd + cd 2 ) + I s k s cos () / (a + bd + cd 2 )
  • Slide 8
  • Summary: I = k a I a + f att k d I d (l n) + f att k s I s (v r ) I = k a I a + I d k d cos( ) / (a + bd + cd 2 ) + I s k s cos () / (a + bd + cd 2 )
  • Slide 9
  • Colored Lights and Surfaces : I = (I r, I g, I b ) = { I, = r, g, b} : color channel ->Colored lights: I a, I d, I s, ->Colored objects: k a, k d, k s, I = I a k a + f att I d k d (l n) + f att I s k s (v r) with = r, g, b. I r = I ar k ar + f att I dr k dr (l n) + f att I sr k sr (v r) I g = I ag k ag + f att I dg k dg (l n) + f att I sg k sg (v r) I b = I ab k ab + f att I db k db (l n) + f att I sb k sb (v r)
  • Slide 10
  • Multiple Lights: I = I a k a + f atti [I d i k d (l i n) + I s i k s (v r i ) ] with = r, g, b. m: number of lights. OpenGL support ambient component for individual light. I = [ I a i k a + f atti [I d i k d (l i n) + I s i k s (v r i ) ]]
  • Slide 11
  • Many more things consider: Shadow, Reflection, Transparency, Refraction, http://www.codeproject.com/KB/graphics/RayTracerNet.aspx Figure 2. Shading effects: a) Ambient, b) Diffuse, c) Highlights, d) Shadows and e) Reflection (notice the reflection on the floor also)
  • Slide 12
  • How to get to each pixel? Two approaches: object order and image order Frame Buffer: a buffer of memory to store the colors of the screen, one memory cell per pixel. http://www.webopedia.com/TERM/F/frame_buffer.html http://en.wikipedia.org/wiki/Framebuffer http://en.wikipedia.org/wiki/Linux_framebuffer
  • Slide 13
  • Image-order Shading
  • Slide 14
  • Ray-tracing (Image created by Russell Yuncker) (Image created by Jian He)
  • Slide 15
  • Simple Ray Tracing: for (each scan line in image ) { for (each pixel in scan line ) { determine ray from eye through pixel; for(each object in scene) { if(object is intersected and is closest considered thus far) record intersection point and object id. } set pixels color to that at closest object intersection point (using the REGULAR I formula.) }
  • Slide 16
  • Recursive Ray Tracing: Set pixels color to that at closest object intersection point using the I formular given below. I = (1- k r - k t )I regular + k r I r + k t I t I regular : regular reflection of lights from light source. Computed by the formula above. k r : reflection coefficient. I r : illumination from other objects (to be reflected). k t : transmission coefficient. I t : illumination from other objects (to be transmitted).
  • Slide 17
  • Recursive Ray Tracing: for (each scan line in image ) { for (each pixel in scan line ) { determine ray from eye through pixel; for(each object in scene) { if(object is intersected and is closest considered thus far) record intersection point and object id. } set pixels color to that at closest object intersection point (using the RECURSIVE I formula.) }
  • Slide 18
  • Programming Image-order Shading Ray Tracing using Povray (Image created by Russell Yuncker) (Image created by Jian He)
  • Slide 19
  • http://www.iss.rwth- aachen.de/Projekte/grace/raytracing.html http://www.iss.rwth- aachen.de/Projekte/grace/raytracing.html Figure: mirror + shadow Free ray tracing software: POV-Ray (http://www.povray.org/)http://www.povray.org/ Start->Program Files->Pov Ray for Windows Run the examples in the scenes directory: C:\Program Files\Pov Ray for Windows\scenes. The resulting image is stored in the same directory as the source file.
  • Slide 20
  • // Shading Demonstration // Using POV-Ray's SDL (Scene Description Language) #include "colors.inc" #include "stdcam.inc" sphere {, 0.4// center & radius pigment { rgb }//color finish { ambient.2// k a diffuse.6// k d specular.75// k s roughness.01 // 1/ } } text { ttf "cyrvetic.ttf"// font type "Color Sphere", 0.1, 0// string, thickness, gap scale translate pigment { rgb }
  • Slide 21
  • Note: Rotation and scaling are about the origin. Need to move the object to the origin, rotate/scale there and then move it back. (WoodBox example) #declare Box_Lid = box { translate -2.75*z // put "hinge" at origin rotate x*25 // open the lid translate 2.75*z // move "hinge" back translate y*2 // lift to top texture {T3} }
  • Slide 22
  • By default, POV-Ray has the positive y-axis pointing up, the positive x-axis pointing to the right, and the positive z-axis pointing into the screen. But this will change depending on the camera settings. (Help: camera, placing) You place the camera in the world coordinate system. But the images are displayed from the cameras point of view.
  • Slide 23
  • More Info on Ray Tracing Povray Community (Hall of Fame, Contests, ) http://www.povray.org/community/ UNC Ray Tracing Tutorial http://www.cs.unc.edu/~rademach/xroads- RT/RTarticle.html Ray Tracing Contests: http://www.irtc.org:7777/irtc/irtc
  • Slide 24
  • Ray Traced Images and Videos Images for raytracing Images for raytracing http://www.google.com/images?hl=en&rlz=&q=Raytracing&um=1 &ie=UTF- 8&source=univ&ei=Z4VxTN6RGIG0lQei3_C0Dw&sa=X&oi=ima ge_result_group&ct=title&resnum=4&ved=0CD4QsAQwAw&biw =1280&bih=621 http://www.google.com/images?hl=en&rlz=&q=Raytracing&um=1 &ie=UTF- 8&source=univ&ei=Z4VxTN6RGIG0lQei3_C0Dw&sa=X&oi=ima ge_result_group&ct=title&resnum=4&ved=0CD4QsAQwAw&biw =1280&bih=621 Videos for raytracing Videos for raytracing http://www.google.com/search?source=ig&hl=en&rlz=&=&q=r aytracing&aq=f&aqi=g-s7g1g- s2&aql=&oq=&gs_rfai=Ch7LQko1xTLWPBZG6hATSztjlDwA AAKoEBU_Q5UWV#q=raytracing&hl=en&prmd=ivb&source =univ&tbs=vid:1&tbo=u&ei=ko1xTMeSE4TGlQePy_mhDg&sa =X&oi=video_result_group&ct=title&resnum=8&ved=0CEkQ qwQwBw&fp=fff49bcb8f5e5b8c http://www.google.com/search?source=ig&hl=en&rlz=&=&q=r aytracing&aq=f&aqi=g-s7g1g- s2&aql=&oq=&gs_rfai=Ch7LQko1xTLWPBZG6hATSztjlDwA AAKoEBU_Q5UWV#q=raytracing&hl=en&prmd=ivb&source =univ&tbs=vid:1&tbo=u&ei=ko1xTMeSE4TGlQePy_mhDg&sa =X&oi=video_result_group&ct=title&resnum=8&ved=0CEkQ qwQwBw&fp=fff49bcb8f5e5b8c
  • Slide 25
  • Hardware Assisted Ray Tracing Nvidia GF100 Ray-tracing http://www.youtube.com/watch?v=Cbnv_z6VDj8 Writing a Ray Tracer http://www.siggraph.org/education/materials/HyperGraph/r aytrace/rtrace0.htm A raytracer in C++ http://www.codermind.com/articles/Raytracer-in-C++- Introduction-What-is-ray-tracing.html Povray Source Code http://www.povray.org/download/
  • Slide 26
  • Object Order Shading: Geometrically approximate objects as patched (triangled) surfaces. Appearance-wise use three shading methods to approximate: Flat, Gouraud, Phong
  • Slide 27
  • Z Buffer (depth buffer): a buffer of memory to store the z values of the screen, one memory cell per pixel. http://en.wikipedia.org/wiki/Z-buffering line of sight Frame buff Z buff
  • Slide 28
  • Flat/Constant Shading: http://www.yourdictionary.com/computer/flat-shading http://www.yourdictionary.com/computer/flat-shading for (each object) for(each triangle of the object) compute its reflection using color and normal of the triangle for(each pixel in the triangle) if(closer to the viewer than the current z buffer value) { update z buffer with the new z update pixel color with the triangle reflection }
  • Slide 29
  • Gouraud/Smooth Shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Gouraud_shading for (each object) for(each triangle of the object) {for(each vertex of in the triangle) compute the vertex reflection using the color and the normal of the vertex for(each pixel in the triangle) if(closer to the viewer than the current z buffer value) { update z buffer with the new z interpolate the pixel color from the vertex reflections. }
  • Slide 30
  • Phong Shading: http://www.yourdictionary.com/phong-shading#computer for (each object) for(each triangle of the object) for(each pixel in the triangle) if(closer to the viewer than the current z buffer value) {update z buffer with the new z interpolate the pixel normal from the vertex normals compute the pixel color/relection using Phong reflection model using pixel normals and the properties of the object. }
  • Slide 31
  • Comparaison of Shading Methods: http://en.wikipedia.org/wiki/Gouraud_shading
  • Slide 32
  • Comparaison of Shading Methods: http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading
  • Slide 33
  • Comparaison of Shading Methods: Gouraud Shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading
  • Slide 34
  • Comparaison of Shading Methods: Gouraus vs. Phong http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading GOURAUD SHADING
  • Slide 35
  • Comparaison of Shading Methods: High Resolution Gouraud http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading http://en.wikipedia.org/wiki/Gouraud_shading http://en.wikipedia.org/wiki/Phong_shading
  • Slide 36
  • Graphics Packages using Object-order Shading: Animation: Alice Panda3D XNA / XNA Game Studio Express Processing 3DS Max Maya Flash Rendering APIs: OpenGL ActiveX Renderman Pixie - Open Source RenderMan Web Graphics: VRML X3D SecondLife Flash Microsoft Silverlight Google SketchUp HTML5.0