Phong Illumination Model; Shading
Total Page:16
File Type:pdf, Size:1020Kb
Phong Illumination Model A local illumination model EECS 487: Interactive • one bounce: light → surface → viewer Lighting a single point Computer Graphics At the point: n Lecture 16: : surface normal (orientation of surface) l: light vector (surface to light) n • Phong Illumination Model v: viewing vector (surface to eye) ϕ • Shading θ: light angle of incidence θ l ϕ: viewing angle v Phong Illumination Model Surface Reflection Coefficients Approximate surface color as Light sources: sum of three components: Approximate BRDFs: not physically based sd diffuse light intensity • an ideal diffuse component ss specular light intensity • a glossy/blurred specular component Modify surface color by changing reflection sa ambient light intensity • an ambient term coefficients based on: • material type m ambient color reflection • surface finish a m diffuse color reflection + = • texture maps d • what looks good ms specular color reflection • artistic license mshi shininess (blurriness) • trial and error me emissive color intensity • personal library + = Diffuse Example Ideal Diffuse Reflectance Ideal diffuse surface reflects light equally in all directions, according to Lambert's cosine law: • amount of light energy that falls on surface and gets Where is the light? reflected is proportional to the incidence angle, θ • perceived brightness (reflectance) is view independent Where’s the normal direction at the brightest point? θ Durand Ideal Diffuse Reflectance Ideal Diffuse Model Amount of light energy that falls At the microscopic level, an ideal on surface is proportional to diffuse surface is a very rough surface incidence angle, θ: • microfacets are oriented in any which way cd = sd md cos θ • examples: chalk, clay, surface of moon Curless For normalized n and l: c = s m max((n•l), 0) d d d RTR2 • (n•l) < 0 cos θ < 0 θ > 90º, light source is behind surface • why must n and l be normalized? l n u·v θ u·v = u v cosθ ⇒ cosθ = u v Durand Diffuse Reflectance and Viewing Angle Ideal Specular/Mirror Reflectance Lambert’s Cosine Law: amount of light energy that falls on Accounts for highlight seen on objects surface and gets reflected is proportional to incidence angle, θ i with smooth, shiny surfaces, such as: • cos θi = dot product of light vector with normal (both normalized) • metal • polished stone Shouldn’t the amount of energy reflected also be proportional • plastics to viewing angle, θ ? r • apples • no, whereas larger θi means • n skin energy arriving over area Recall: dA cos θi is spread across the sin (π/2 – θ) = cos θ larger area dA, larger θr simply means collecting energy from n the same area dA, but channelling it through the smaller area dA cos θ dA cos θ r θ Surface 2 π/2 − θ Surface 1 dA TP3, FvD94 Curless,Zhang n Ideal Specular/Mirror Reflectance Phong Specular Reflection r l v Reflection only at mirror angle Simulates a highlight θ θ φ • highlight intensity depends on viewing direction Reflection angle = incidence angle = θ Most intense specular reflection when v = r Model: all microfacets of mirror surface are oriented in the same How to compute r? direction as the surface itself • examples: mirrors, highly polished r = −l + 2(n•l)n n (in OpenGL, specular term is 0 if l • n = 0) metals r l 2(n ⋅ l)n (n ⋅ l)n -l Durand Glossy Reflectors Glossy Real materials tend to deviate significantly from ideal Reflectors mirror reflectors ⇒ highlight and reflections are blurry Simple empirical model: Also known as: “rough specular”, “directional diffuse”, • we expect most of the reflected light to travel in or “glossy” reflection the direction of the ideal reflection ray • but due to variations in microfacet orientations, (there are no ideal diffuse surfaces either …) some of the light will be reflected just slightly off from the ideal reflected direction • as we angle away from the reflected ray, we expect to see less light reflected Durand Durand Surface Roughness Phong “Glossy” Reflection Model Schlick As v angles away from r, specular reflection falls specular diffuse off, simulating “glossy” reflection: Glossy Surface Less Shiny Surface Diffuse Surface Perfect Mirror v v increasing roughness TP3 less glossy/ more glossy/blurry more specular Phong “Glossy” Reflection Model Material Glossiness Phong specular model: To account for the shininess of different material: mshi cs = ss ms max((r • v), 0) cs = ss ms cos φ = ss ms max((r • v), 0) larger mshi gives tighter and shinier highlight, with sudden dropoff, simulating a more mirror-like surface cos φ v n r r l v intensity φ specular angle mshi: RTR3 Phong Specular Reflection Blinn-Phong (Blinn-Torrance) Model larger mshi , tighter highlight Back to micro facets: • model surface by a collection of tiny mirrors • specular reflectance comes from mirrors oriented halfway between l and v, in direction of h , shinier s m l n h v ω ω larger TP3 Manocha Blinn-Phong Illumination Models h A rendering process can be modeled as an integral Model specular reflection with “halfway” l l equation representing the transport of light through vector (h) instead of r v the environment the rendering equation • consider the microfacet through point p that p Local illumination: an approx. of the rendering eqn. reflects light perfectly to the viewer • assumes light is scattered only once: light from light source is reflected by a surface and modulated on its way towards • h is the normal of this plane, it is halfway l + v h = the eye between l and v (by definition), h normalized l + v Global illumination: • angle between h and n is β; v = r when h = n • light rays traveling from light to surface may be v r n h (β is not the angle between and ) l r • blocked by intervening surfaces (shadows) or • specular reflection modeled as: β v • bent or scattered by intervening material (refraction and atmospheric 4m 4m effects) or c = s m (n • h) shi = s m (cos β) shi s s s s s p • light arriving at a surface may come indirectly via another surface (reflection and color bleed) Phong Ambient Term Putting It All Together Phong Illumination Model “Approximates” the contribution of all indirect m c = m s + (m (n⋅l) + m (r ⋅v) shi ) f (d)s illumination t a a d s Phong ρa ρd ρs ρtotal Surface uniformly lit θ = 60º • areas with no direct illumination are not completely dark • independent of: θ = 25º • light direction • surface normal • viewing angle θ = 0º Spheres rendered with ambient reflection only Durand OpenGL Light Sources OpenGL Lighting and Reflectance glLightfv(lightname,param,value) /* Initialize material property, light source, • parameters lighting model, and depth buffer. */ • GL_AMBIENT void init(void) • GL_DIFFUSE { • GL_SPECULAR GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; • GL_POSITION GLfloat mat_shininess[] = { 50.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; • GL_SPOT_DIRECTION glClearColor(0.0, 0.0, 0.0, 0.0); • GL_SPOT_CUTOFF glShadeModel(GL_SMOOTH); • GL_SPOT_EXPONENT glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); • GL_CONSTANT_ATTENUATION glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); • GL_LINEAR_ATTENUATION • GL_QUADRATIC_ATTENUATION glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); Turning on the lights: glEnable(GL_LIGHT0); • glEnable(GL_LIGHTING) glEnable(GL_DEPTH_TEST); } • glEnable(GL_LIGHT0) OpenGL Material Properties Choosing the Parameters glMaterial(face,param,value) Experiment with different parameter settings • face • GL_FRONT A few suggestions: • GL_BACK • ma + md + ms < 1 • GL_FRONT_AND_BACK • use a small m (~0.1) • parameters a • GL_AMBIENT • try mshi ∈ [0, 100] • GL_DIFFUSE • GL_AMBIENT_AND_DIFFUSE TP3 • GL_SPECULAR • GL_SHININESS material m m m • GL_EMISSION d s shi See Redbook Chapter 5 for techniques to minimize metal small, color of metal large, color of metal large performance costs associated medium, color of medium, color of plastic medium with changing material object light (or white) properties planet varying 0 0 Curless Highlight Color Emissive Term For non-metals, e.g., plastics, highlight color is color Material’s emissive parameter me of light (plastics has a transparent/white coating) • assumed not lighting other objects For metals, e.g., brass, highlight depends on surface m c = m + m s + (m (n⋅l) + m (v ⋅r) shi ) f (d)s color t e a a d s Surface plastic metal clay Apodaca&Gritz Funkhouser Attenuation Model Global Ambient and Multiple Lights Whereas the ambient term simulates indirect lighting, attenuation model and fog simulate scattering effect Global ambient light source: cg = sg ma • sg set with: Intensity attenuation: light falls off the further away glLightModel*(GL_LIGHT_MODEL_AMBIENT,ambient_light) one gets from the source • distinguishes overlapping surfaces Multiple lights: n having the same reflection parameters (k) (k) (k) (k) 2 c = c + m + c + f (d )(c + c ), • radiant energy disperses as 1/d d t g e ∑ a d s 1 k=1 • d is the distance from the light source to surface k:!light!number,!not!exponentiation • reason for the inverse square falloff? d 2 ! 2 • attenuation function f (d) = 1/(a0+a1d+a2d ) • user defined constants a0 , a1 , a2 • since we’re not modeling atmospheric scattering, 1/d 2 often appears too harsh • instead, we use f (d) = 1/(a0+a1d) or no attenuation Lighting with attenuation: c’ = f (d )c Fog Fog Simple atmospheric effect f :!fog!factor!at!point!p color of fog: cf p • a little better realism color of surface: cs zend − zstart : the!foggy!range • fog effect: help to convey distances d f : fog!density cp = f cs + (1 − f ) cf , f ∈ [0,1] ! • 2 forms of depth cueing (ignoring scattering) • light-to-object distance conveyed by light attenuation