Upload
umay
View
44
Download
1
Embed Size (px)
DESCRIPTION
CSE 410 Computer Graphics Sessional. Virtual Realism LIGHTING AND SHADING. Lighting & Shading. Approximate physical reality Ray tracing : Follow light rays through a scene Accurate, but expensive (off-line) Radiosity : Calculate surface inter-reflection approximately - PowerPoint PPT Presentation
Citation preview
Slide 1
Types of Light SourcesAmbient light: no identifiable source or directionDiffuse light - Point: given only by pointDiffuse light - Direction: given only by directionSpot light: from source in directionCut-off angle defines a cone of lightAttenuation function (brighter in center)Light source described by a luminanceEach color is described separatelyI = [I r I g I b ] T (I for intensity)Sometimes calculate generically (applies to r, g, b)Ambient LightGlobal ambient lightIndependent of light sourceLights entire sceneLocal ambient lightContributed by additional light sourcesCan be different for each light and primary colorComputationally inexpensiveDiffuse LightPoint SourceGiven by a pointLight emitted equally in all directionsIntensity decreases with square of distancePoint source [x y z 1]TDirectional SourceGiven by a directionSimplifies some calculationsIntensity dependents on angle between surface normal and direction of lightDistant source [x y z 0]T
Spot Lights Spotlights are point sources whose intensity falls off directionally. Requires color, pointdirection, falloffparameters
dPIntensity at P = I cos()This model is based on modeling surface reflection as a combination of the following components:Emission Ambient ReflectionDiffuse ReflectionSpecular ReflectionUsed to model objects that glowA simple way to model indirect reflectionThe illumination produced by dull smooth surfacesThe bright spots appearing on smooth shiny surfacesPhong illumination modelDiffuse Reflection Ideal diffuse reflectionAn ideal diffuse reflector, at the microscopic level, is a very rough surface (real-world example: chalk) Because of these microscopic variations, an incoming ray of light is equally likely to be reflected in any direction over the hemisphere
What does the reflected intensity depend on? Computing Diffuse Reflection Independent of the angle between m and v Does depend on the direction s (Lambertian surface)
Diffuse Reflection CoefficientAdjustment for inside face
Therefore, the diffuse component is:Specular Reflection Shiny surfaces exhibit specular reflectionPolished metalGlossy car finish A light shining on a specular surface causes a bright spot known as a specular highlight Where these highlights appear is a function of the viewers position, so specular reflectance is view dependent
Specular Reflection Perfect specular reflection (perfect mirror)The smoother the surface, the closer it becomes to a perfect mirror Non-perfect specular reflection: Phong Modelmost light reflects according to Snells Lawas we move from the ideal reflected ray, some light is still reflected
Non-Ideal Specular Reflectance: Phong ModelAn illustration of this angular falloff
msrPhong Lightingmsrv
The Specular Intensity, according to Phong model:
Specular Reflection CoefficientShininess factor
Phong Lighting ExamplesThese spheres illustrate the Phong model as s and f are varied:
Blinn and Torrence VariationIn Phong Model, r need to be foundcomputationally expensiveInstead, halfway vector h = s + v is usedangle between m and h measures the falloff of intensitymshv
Combining EverythingSimple analytic model: diffuse reflection +specular reflection +ambientSurface
The Final Combined EquationSingle light source:
msrvViewerqq
Adding ColorConsider R, G, B components individuallyAdd the components to get the final color of reflected light
Shading ModelsApplying IlluminationWe have an illumination model for a point on a surfaceAssuming that our surface is defined as a mesh of polygonal facets, which points should we use? Polygon ShadingTypes of Shading Model
Flat Shading
Gouraud Shading
Phong ShadingSmooth ShadingFlat ShadingFor each polygon Determines a single intensity value Uses that value to shade the entire polygon
AssumptionsLight source at infinityViewer at infinityThe polygon represents the actual surface being modeled
Wire-frame ModelFlat ShadingFlat Shading
Smooth ShadingIntroduce vertex normals at eachvertexUsually different from facet normalUsed only for shadingThink of as a better approximation of the real surface that the polygons approximateTwo typesGouraud ShadingPhong Shading (do not confuse with Phong Lighting Model)Gouraud ShadingThis is the most common approachPerform Phong lighting at the verticesLinearly interpolate the resulting colors over facesAlong edgesAlong scanlines
Gouraud Shadingxrightysytopybottxleftcolor1color2color3color4y4
Gouraud ShadingVertex 1I = 0.2Vertex 2I =0.8I = 1.0Vertex 3I = 0.6Vertex 40.30.40.50.850.90.950.350.500.65
Wire-frame ModelGouraud ShadingFlat Shading
Gouraud Shading
Gouraud ShadingArtifactsOften appears dullLacks accurate specular componentIf included, will be averaged over entire polygonC1C2C3Cant shade the spot lightPhong Shadingysxm1m2m3m4mleftmrightmInterpolate normal vectors at each pixel
Wire-frame ModelPhong ShadingFlat Shading
Gouraud Shading
Phong Shading
If a highlight does not fall on a vertex Gouraud shading may miss it completely,but Phong shading does not.Phong vs Gouraud ShadingShading Models (Direct lighting)Flat ShadingCompute Phong lighting once for entire polygonGouraud ShadingCompute Phong lighting at the vertices and interpolate lighting values across polygonPhong ShadingInterpolate normals across polygon and perform Phong lighting across polygonLighting in OpenGLLighting in OpenGL [1/2]Enabling shadingglShadeModel(GL_FLAT)glShadeModel(GL_SMOOTH); // Gouraud Shading onlyUsing light sourcesUp to 8 light sourcesTo create a lightGLfloat light0_position[] = { 600, 40, 600, 1.0};glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glEnable(GL_LIGHT0);glEnable(GL_LIGHTING);Lighting in OpenGL [2/2]Changing light propertiesGLfloat light0_ambient[] = { 0.4, 0.1, 0.0, 1.0 };GLfloat light0_diffuse[] = { 0.9, 0.3, 0.3, 1.0 };GLfloat light0_specular[] = { 0.0, 1.0, 1.0, 1.0 };glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);For more detailSee Red Book (Ch 5)
ReferencesHill 8.1 ~ 8.3