CS 431/636 Advanced Rendering Techniques Ø Dr. David Breen Ø Korman 105D Ø Wednesday 6PM 8:50PM Presentation 6 5/16/12 Questions from ast Time? Ø Sampling Theory" Ø Fourier Analysis Ø Anti-aliasing Ø Supersampling Strategies" 1 2 Slide Credits Ø Charles B. Owen - Michigan State University Illumination and Shading Ø The Hall illumination model Hall, R. A. and Greenberg D.P., "A Testbed for Realistic Image Synthesis", IEEE Computer Graphics and Applications, 3(8, pp. 10-20, ov. 1983 Ø Original ray tracing paper Whitted, T., An Improved Illumination Model for Shaded Display, Communications of the ACM, 23(6, pp. 343-349 (1980 3 4 Discrete Illumination Models Ø What occurs when light strikes a surface is quite complex. Continuous process ight from infinite angle reflected in infinite directions Ø We are determining intensity of a pixel with Finite number of point lights Finite reflections into space Finite illumination directions Ø Hence, we must have a discrete model for lighting and illumination. Illumination Models Ø What should a lighting model entail? Discrete ights Types of surface reflection Ø Commercial systems can be quite complex Most start with a basic model and embellish to pick up details that are missing 5 6 1
Elements of ighting at a point Reflection Ø What we need is the amount of light reflected to the eye The surface normal ector to the light ector to the eye R Reflection direction R 7 8 This consists of several components Ø Diffuse reflection - light reflected in all directions equally (or close to equally. Most obects have a component of diffuse reflection other than pure specular reflection obects like mirrors. What determines the intensity of diffuse reflection? Characteristics Ø Since the intensity is the same in every direction, the only other characteristic is the angle between the light and the surface normal. The smaller this angle, the greater the diffuse reflection: 9 10 ambert s aw 11 w w w cos = w / w' w = w'cos Diffuse reflection decreases intensity by the cosine of the angle between the light and surface normal. Ø Specular reflection - If the light hits the surface and is reflected off mostly in a reflection direction, we have specular reflection. There is usually some diffusion. A perfect specular obect (no diffusion at all is a mirror. Most obects have some specular characteristics 12 2
Diffuse and Specular colors Where do these come from? Ø Typically Ø Most the colors reflected for diffuse and specular reflection are different surfaces tend to have: Deep color, the color of the paint, finish, interior material, etc. Diffuse Generally the surface appearance Specular The color of bright highlights, often more white then the surface color Diffuse Color Surface reflection characteristics, varnish, polish, smoothness Specular Color 13 14 Components of the Hall Model The Hall Illumination Model I( = ksr Il ( Fsr (,"r, (cos" r, n + kst I l(fst (,"t, (cos" t, n' + kdr I l (Fdr (( $ + ksr Isr ( Fsr (,"R T r %sr + kst Ist (Fst (," T T t %st + kdr ( Fdr ( Ambient ight 15 16 Hall Model Implementing Shadows Ø At every ray intersection shoot a shadow ray at every point light source in your scene Ø If an obect is hit before reaching the light, don t use the light when shading that intersection point Ø What if occluding obect is transparent? Make light s contribution weighted rather than binary 17 18 3
Ambient ight Ambient ight ( Ø Ambient light is light with no associated direction. The term in the Hall shading model for ambient light is: Ø is the coefficent of diffuse reflection. This term determines how much diffuse reflection a surface has. It ranges from 0 to 1 (as do most of these coefficients. 19 ( Ø (λ is the spectrum of the ambient light. It is a function of the light wavelength λ. In nature this is a continuous range. For us it is the intensity of three values: Red, Blue, and Green, since that is how we are representing our spectrum. In other words, there are only 3 possible values for λ. Simply perform this operation for each color 20 Ambient ight ( Implementation ( Ø F dr (λ is the Fresnell term for diffuse reflection. It specifies a curve of diffuse reflections for every value of the spectrum. We don t have every possible color, we only have three. So, this term specifies how much of each color will be reflected. It is simply the color of the obect. Ø It s common to combine and F dr (λ F dr (λ is really ust a color. Just call this is ambient surface color (λ is the ambient light color Ø Implementation (But you don t have to for(int c=0; c<3; c++ hallcolor[c] = lightambient[c] * * surfacediffuse[c]; 21 22 of ight Sources Ø The iterator takes on the index of every light in the system. - coefficent of diffuse reflection. I l (λ - spectrum of light source. It is simply the color of the light. I l (( " of ight Sources I l (( " Ø component." is the surface normal at the point. is a vector towards the light. Dot product is the cosine of the angle (vectors must be normalized. alue decreases as the angle increases. 23 24 4
of ight k Sources sr Ø k sr and I l (λ are now obvious. Ø F sr (λ,θ r, is the Fresnell term representing the specular reflection curve of the surface. Specular reflection is due to microfacets in the surface and this curve can be complex. In real world systems which strive for accuracy, this curve will be measured for a given material. ote that the curve is dependent on not only the wavelength, but also an angle. Ø A simplification of this is to ignore the angle, which is what we will do. But, the color of spectral highlights is independent of the color of the surface and is often ust white. 25 I l (," r, (cos" r, n The Spectral Intensity Function Ø (cosθ r, n is the spectral intensity function. It represents the cosine of the angle between the half reflection vector and the surface normal raised to a power. Maximum reflection is in the mirror direction 26 k sr I l (," r, (cos" r, n Cosine of Reflection Angle H k sr I l (," r, (cos" r, n Reflection Angles H This is an example α α of maximum reflection H cos r, = " H cos r, = " H + H = + In this case, the half vector is the same as the surface normal Cosine of angle between half vector and normal is 1. H bisects the angle between and 27 28 Different Than Phong Shading H cos" r, = H Hall Model cos" r, = v r Phong Model Hall vs. Phong Specular Ø Same when = R cos(θ = cos(φ = 1 Ø Phong goes to zero when R. Then it goes negative Ø Hall only goes to zero when = &&. Ø Hall never negative. H R H 29 30 5
Highlight Coefficient Ø The term n is called the specular reflection highlight coefficient. Ø This effects how large the spectral highlight is. A larger value makes the highlight smaller and sharper. Matte surfaces has smaller n. 31 ery shiny surfaces have large n. A perfect mirror would have infinite n. from Other Surfaces Ø This is reflections of other surfaces Ø The only new terms are I sr (λ and T r Δsr The T r Δsr term reflects the fact that light falls off exponentially with distance. T r is a term which models how much light falls off per unit of travel within the medium. The Δsr term represents how far the light travels. ote that for mediums such as air and a small scene T r is close to 1, so you can sometimes ignore it. Glassner suggests 1/(1 + a*δsr instead 32 k sr I sr (," R T r sr The Reflection Direction Ø Given a view direction and a normal, the reflection direction R is: R = 2( " Ø I sr (λ is the color seen in the reflection direction, i.e. returned from the reflection ray Transmission Ø Transmission is light that passes through materials 33 34 from ights Ø Bright spots from lights passing through obects. Most of the same issues apply. Ø I l (λ is the color of light. Ø F st (λ,θ t, specular transmissive color of obect Ø (cosθ t, n is how the specularity falls off if looking directly down the direction of transmission. 35 k st I l (F st (," t, (cos" t, n' Refractive Transmission Ø Given indices of refraction on above and below a surface, we can compute the angle for the view and transmission vectors using Snell s law 36 sin sin" " i = i θ i T - θ η i η 6
What Transmission ooks ike Index of Refraction Ø Ratio of speed of light in a vacuum to the speed of light in a substance. 37 - T H H ' = " " 1, where " = 2 1 cos t, this time is (" H' η 1 and η 2 are the indices of refraction for the from and to obects respectively. 38 Substance Index acuum 1.0 Air 1.00029 Water 1.33 Glass 1.52 Diamond 2.417 Sapphire 1.77 Salt 1.54 The Transmission Direction Total Internal Reflection " r = " i " T = " r 39 ( ( $ 1$" 2 r (1$ ( 2 $" r See Glassner p. 134-141 T η i η Ø If light is traveling from η i to a smaller η (e.g. out of water into air, the angle from the negative normal increases: 40 This can lead to the angle for T being >=90 degrees This is called total internal reflection Square root term in previous equation goes negative T T η i η Total Internal Reflection Hack What to do if square root is negative? Ø Return obect s reflective color, or Ø Shoot an internal reflective ray, or Ø Make T equal to - Ø Do the one that looks best 41 from Other Surfaces 42 k st I st (F st (," T T t st Ø This is transmitted light from other obects Ø K st - specular transmission coefficient Ø I st (λ is the light value from transmitted ray Ø F st (λ,θ Τ specular transmissive color of obect Ø T r Δst is the light fall off term, as before Glassner suggests 1/(1 + a*δst instead Ø Δst is distance traveled through obect 7
Hall Model Recap Hall Model Revisited I( = k sr I l (," r, (cos" r, n +k st I l (F st (," t, (cos" t, n' + I l (( $ +k sr I sr (," R T r %sr +k st I st (F st (," T T t %st + ( Ambient ight I( = k sr I l (," r, (cos" r, n +k st I l (F st (," t, (cos" t, n' + I l (( " sr +k r I sr (," R T r st +k st I st (F st (," T T t +k a ( Ambient ight 43 44 ew Parameters Ø Adding two new coefficients in order to provide more flexibility to the model Ø K r Reflection coefficient If set to zero, the obect is not reflective This will allow you to generate Phongshaded models Ø K a Ambient coefficient Allows you to set ambient properties separate from diffuse properties 45 Algorithm Overview Ø For every primary ray that hits obect Shoot shadow ray at each light If you hit something don t use that light Or decrease light color if obect is transparent Calculate diffuse, specular and ambient colors Shoot reflected ray. Calculate color I sr (λ and add it to the shading equation Shoot transmitted ray. Calculate color I st (λ and add it to the shading equation Calculate transmissive specular highlight, if light ray goes through transparent obect 46 Generating trees for moderately complex scenes Ø Ø Ø Ø ight is reflected from several surfaces before reaching the viewer. The light ray behavior can be modeled as a tree. The shader traverses the tree, applying the shading equation at each node to calculate intensity. Tree should have a preset maximum depth Tricks Ø Terminate shadow ray ASAP Ø imit the depth of ray tree Ø Recursion can be stopped when color value drops below ε Ø Shooting a secondary ray can be tricky Move start point slightly away from surface Ø What if shadow ray hits a non-opaque obect? Ø What to do with total internal reflection and coming to the bottom of ray tree? 47 48 8
ext Programming Assignment Ø Update shading equation ew specular angle k d + k s = 1 Ø Add shadows Ø Add reflections I = k s I C s (cos n +k d I C d (cos" +k s I r C s +k a C d 49 9