hw1-2 review hw 3 questions?
Lecture 6 Blending Lighting & Materials Notes on hw4
Blending combine the color value of the fragment with that of pixel in frame buffer. without blending - overwrite - opaque with (lower) alpha values - transparency, translucency
Blending Source & Destination 1. Specify how to compute source/destination factors 2. Combine using factors Source Destination Rs,Gs,Bs,As Rd,Gd,Bd,Ad E.T. 06 SR,SG,SB,SA RsSR GsSG BsSB AsSA Final + RdDR, + GdDG, + BdDB, + AdDA DR,DG,DB,DA
Blending glenable(gl_blend); glblendfunc(source_factor, destination_factor); example factors: GL_ZERO, GL_ONE, GL_DST_COLOR, GL_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA range [0,1] gldisable(gl_blend); glblendfunc(gl_one, GL_ZERO);
Blending E.T. 06 Back-to-Front, Front-to-Back Order Matters! if using z-buffer - if front object translucent overwrites z value of back opaque object - no blending. Solution disable depth buffering and draw in order make it read only when drawing translucent objects gldepthmask(gl_false) : read only gldepthmask(gl_true) : restore original
Lighting
Graphics vs. Physics Color of an object Intensity/Color of light ray Reflection Spectrum: Fraction of light of each frequency that gets reflected Radiance Distribution Intensity/Color of point light source Intensity spectrum of a point light source
Some physics... Radiometry = measuring light Photon : quantum of light with position, direction of propagation and a wavelength λ (assumption - light propogates in straight lines in isotropic medium) speed c that depends on refractive index of medium frequency f = c/λ : invariant to refractive index energy q = hf = hc/λ, h ~1e-34 Plank s constant
Light = Radiant Energy measured in joules Spectral Radiant Energy, Q = i hc λ i sun vs. single-wavelength laser amount of radiant energy per unit wavelength interval at wavelength λ measured in (joules/nm), Radiant flux (Radient power) power = energy per unit time time rate of flow of radient energy Q λ = dq dλ measured in (joules/sec, watts), Φ = dq dt
Radiant Flux Density radiant flux per unit area at a point on a surface measured in (watts/m 2 ) arriving flux - Irradiance leaving flux - Radiant exitance E = dφ in da M = dφ out da!"!!!!"! "#$%&'!()! *&&)+#),-'!!! "#$%&'!(.! /)+#),0!'1#0),-'!
Solid Angles Reminder: A regular angle θ = l R circle has 2π radians solid angle spanned by a cone is measured by the area of intersection of the cone with a sphere:!! $ % % differential solid angle can be assigned a direction. Unit: steradian (full sphere = 4"#
Radiance: Measure of Light Radiance(Luminance): Number of photons(or energy) arriving per time at a small area perpendicular to the ray from a particular direction L(ω) =!!" "! d 2 φφ cos θdadω =!"!"#" $%"&'!(')*+%'+ watt m 2 steradians!! *!" Physical quantity equivalent to psychological concept of brightness as observed by us.!# " "
Constancy of Radiance radiance is constant along a ray: consider the flow of photons in a a thin pencil; the number of photons entering onthe right with the direction inside &",! exit through the other side; equating the expressions for entering and exiting diff. flows we get &!! # #! &"! &'! # # " &" " &' " # &! " but &'! &"! # &' " &" " so #! # # "! 2005 Denis Zorin
Local illumination model Describes interaction of the light and the surface! light can be reflected, absorbed and transmitted! most important: reflection! reflection can be ideal specular, diffuse and and anything between! reflection equation relates the outgoing radiance in some direction to the incoming radiance! 2005 Denis Zorin
Once again, radiance: L(ω, L(ω) θ) = d 2 φφ cos θdadω = watt m 2 steradians and irradiance (flux density incoming energy per area) E = dφ in da E(ω, θ) = L(ω, θ) cos θdω = watt m 2
BRDF Bidirectional Reflectance Distribution Function E.T. 06 ( ) reflected radiance exiting a surface in direction r irradiance incident on the surface from direction i ( ) ians -1! " " " "!!! %& f(ω i, ω r ) = L r(ω r, θ r ) E i (ω i, θ i ) unit : steradians -1
Reflection equation the outgoing radiance in direction r is the sum of the radiances due to radiance from all incoming directions:! "!! " " #! # "!! $ %! " "! $!! $ " $%& " $ &! $ the integral is over the upper hemisphere! " " " "! %&!!! 2005 Denis Zorin
Reflection geometry V: direction to the eye surface N: normal R: reflected diection L: direction to the light source R = 2(N,V)N - V! 2005 Denis Zorin
Snell s law If a surface separates two media with different refraction indices (e.g. air and water) the light rays change direction when they go through. Snell s law: the refracted ray is stays in the plane spanned by the normal and the direction of the original ray. The angles between the normal and the rays are related by!!!"#!! $! "!"#! " where! " and! # are refraction indices. normal!!! 2005 Denis Zorin!"
Refracted ray direction V N!!! $!!! $!!" % T! "!!&"$ #'! " # (!! " &(! &"$ #' " ' #! "! 2005 Denis Zorin
Illumination model Two main components:! light source characteristics! position! intensity for each freq. (color) often, different intensity can be specified for different colors! directional distribution! surface properties! reflectance for each freq. (color)! different reflectance can be specified for diffuse and specular light! 2005 Denis Zorin
And now graphics...
Local lighting model Describes interaction of the light with the surface. Almost never truly based on physics: perception plays a greater role. Visible light: electromagnetic waves, with wavelengths 400nm (violet) - 700nm (red); intensity can vary over many orders of magnitude. Computer model: only three frequencies : RGB, intensity varies over a small range, typically only 255 discrete values/ color.! 2005 Denis Zorin
Perception Perceptual response to light with an arbitrary spectrum = Perceptual response produced by a linear combination of 3 primary wavelengths. (R,G,B)
A simple model In the model commonly used in graphics applications, there are several components! diffuse relection: intensity does not depend on the direction to the viewer! specular: simulates relective surfaces and specular highlights depending on the direction to the viewer! ambient: a crude approximation to the illumination created by the light diffusely reflected from surfaces emissive: simulation of light originating from objects! 2005 Denis Zorin
Diffuse (Lambertian) Component Lambert s Cosine Law : Color intensity is prop. to the cosine of the angle between surface normal and direction to light source l http://escience.anu.edu.au/lecture/cg/illumination/lambertcosinelaw.en.html θ n Ld cos θ Ld (n l) Ld = ld sd (n l) Ld = ld sd max(0,(n l)) (or = ld sd n l ) Does not depend on view direction = scatters the same way in all directions
Diffuse (Lambertian) Component E.T. 06 Light comes from one direction Brighter if perpendicular to surface Once hits surface, scattered equally
Ambient Component La = la sa Scattered light in the environment Seems to come from all directions When ambient light hits a surface, it s scattered in all directions
Specular(Phong) Component Highlights - part of surface where α=0 brightest highlight. There s also brightness when α small. l θ θ n α r e need a function s.t. it s high when r=e and gradually falls off as r gets away from e. lsss(e r) too large area, can be negative r = 2(l n)n-l Ls = lsssmax(0, e r) p
Specular(Phong) Component Light comes from a particular direction Bounces off surface at a preferred direction Shininess Mirror - light from source reaches the eye only if r=e
Specular reflection p = 0 p = 1 p = 2 p = 10 p = 25 p = 100! 2005 Denis Zorin
Metal vs. plasitic Natural look of metallic surfaces is difficult to simulate, but the first approximation is obtained using proper highlight color. For plastic objects, highlights are close in color to the color of the light. For metals, to the color of the surface. Assuming white lights, for plastic set k spec =[c,c,c], where c is a constant, for more metallic look set k spec = k diff! 2005 Denis Zorin plastic look metallic look
Emissive Component simulates light originating from objects (ex: light bulb) is not effected by any other light does not add to light in the scene Le = se
Attenuation In real life: Radiance goes down by 1/r2 Ex: Stars vs. Sun Due to approximations inverse-square law results in very dark images Solution : Let the user choose the attenuation factors (a,b,c) 1/(a + br + cr 2 ) E.T. 06 Default - (1,0,0) - no attenuation
Complete Equation Ld = ld sd max(0,(n l)) La = la sa Ls = ls ss max(0, (e r)) p A = 1/(a + br + cr 2 ) Total Radiance L = A(La + (Ld + Ls))
OpenGL Lighting Model Color of light source depends on amounts of red/green/blue light it emits Ambient Diffuse Specular Emissive
OpenGL Materials Approximate color of material based on percentage of incoming light color it reflects Ex. Red ball - in white light Red ball - in red light Red ball - in green light
RGB Values Lights vs. Materials Materials (R M, GM, BM) reflected percentage Ex. (1,1,0) - reflects all red, all blue, no green Light (R L, GL, BL) percentage of full intensity Ex. (1,1,1) brightest white, (.5,.5,.5 ) gray E.T. 06 The color we see is given by: RL*RM + GL*GM + BL*BM
OpenGL Steps 1. Define normal vectors for each vertex of all objects 2. Create/Select/Position one or more light sources 3. Create/Select a Lighting Model 4. Define material properties for the objects in the scene
Normals Orientation relative to light sources ( = how much light will it get) all normals must be of unit length glenable(gl_normalize) glenable(gl_rescale_normal) (Normal must have been scaled uniformly and must have been unit initially.)
Vertex vs. Face Normals Smooth (Gouraud) vs. Flat Shading There s also Phong Shading
OpenGL Steps 1. Define normal vectors for each vertex of all objects 2. Create/Select/Position one or more light sources 3. Create/Select a Lighting Model 4. Define material properties for the objects in the scene
gllight(light, pname, param) GL_LIGHT0, GL_LIGHT1,... GL_LIGHT8 Note: Default values for lights 1-8 Color: GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR Position: GL_POSITION (Directional/Positional Light) Spotlight Parameters (direction, angle) Attenuation Parameters (constant, linear, quadratic) E.T. 06
OpenGL Steps 1. Define normal vectors for each vertex of all objects 2. Create/Select/Position one or more light sources 3. Create/Select a Lighting Model 4. Define material properties for the objects in the scene
Lighting Model gllightmodel(pname, param) Global Ambient Light Intensity(.2,.2,.2,1.) GL_LIGHT_MODEL_AMBIENT Viewpoint - local to scene or at infinity(*) GL_LIGHT_MODEL_LOCAL_VIEWER Lighting - front(*) and back faces of objects GL_LIGHT_MODEL_TWO_SIDE Specular separate or not(*) GL_LIGHT_MODEL_COLOR_CONTROL (param = GL_SEPARATE_SPECULAR_COLOR for correct texturing)
Enabling Lighting glenable(gl_lighting); After parameter specifications for light: glenable(gl_light0);
OpenGL Steps 1. Define normal vectors for each vertex of all objects 2. Create/Select/Position one or more light sources 3. Create/Select a Lighting Model 4. Define material properties for the objects in the scene
Material Properties glmaterial(face, pname, param) GL_FRONT GL_AMBIENT GL_BACK GL_DIFFUSE GL_FRONT_AND_BACK GL_SPECULAR GL_SHININESS GL_EMISSION call before glbegin()..glend() sequence - just like glcolor A Possibly Faster Method : glenable(gl_color_material); glcolormaterial(face, pname) glcolor(.1,.1,.1,.1)
Final Color Computation Vertex Color = material emission at vertex + global ambient light * material ambient property + attenuated combination of ambient, diffuse and specular contributions from each light source
Final Color Computation Vertex Color = material emission at vertex glmaterial : GL_EMISSION E.T. 06 GL_LIGHT_MODEL_AMBIENT glmaterial : GL_AMBIENT + global ambient light * material ambient property GL_CONSTANT/LINEAR/ QUADRATIC_ATTENUATION + attenuated combination of ambient, diffuse and specular contributions from each light source gllight: GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR
Hw3 help
light positioning tips compute difference in x and y in screen coords. computing motion in world coordinates right/left direction : vector s = up x view up/down direction: vector t = view x s in/out direction : view vector