Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.

Slides:



Advertisements
Similar presentations
GR2 Advanced Computer Graphics AGR
Advertisements

SI23 Introduction to Computer Graphics
16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.
7.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 7 Polygon Shading Techniques.
Computer Graphics- SCC 342
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 Computer Graphics Chapter 9 Rendering. [9]-2RM Rendering Three dimensional object rendering is the set of collective processes which make the object.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
1 Computer Graphics By : Mohammed abu Lamdy ITGD3107 University of Palestine Supervision: Assistant Professor Dr. Sana’a Wafa Al-Sayegh.
Illumination and Shading
Computer Graphics - Class 10
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading III Week.
1 of 29 Interesting Illumination Demo There’s a very nice Java illumination model demo which may help you understand the effects of different kinds of.
Computer Graphics (Fall 2005) COMS 4160, Lecture 16: Illumination and Shading 1
Lighting and Shading Wen-Chieh (Steve) Lin
(conventional Cartesian reference system)
CS 376 Introduction to Computer Graphics 03 / 30 / 2007 Instructor: Michael Eckmann.
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
©Larry F. Hodges (modified by Amos Johnson) 1 Shading Models.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
Part I: Basics of Computer Graphics Rendering Polygonal Objects (Read Chapter 1 of Advanced Animation and Rendering Techniques) Chapter
Fundamentals of Computer Graphics Part 6 Shading prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
CS 445 / 645: Introductory Computer Graphics
CS 445 / 645 Introduction to Computer Graphics Lecture 18 Shading Shading.
In the name of God Computer Graphics Modeling1. Today Introduction Modeling Polygon.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS 1 Shading (Shading) & Smooth Shading Graphics.
Week 11 - Thursday.  What did we talk about last time?  Image processing  Blurring  Edge detection  Color correction  Tone mapping  Lens flare.
Image Synthesis Rabie A. Ramadan, PhD 1. 2 About my self Rabie A. Ramadan My website and publications
Week 6 - Wednesday.  What did we talk about last time?  Light  Material  Sensors.
CS 325 Introduction to Computer Graphics 03 / 26 / 2010 Instructor: Michael Eckmann.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
CAP4730: Computational Structures in Computer Graphics
Smooth Shading Gouraud Phong
Illumination and Shading
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
CS 445 / 645 Introduction to Computer Graphics Lecture 15 Shading Shading.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
CS 376 Introduction to Computer Graphics 04 / 02 / 2007 Instructor: Michael Eckmann.
Specular Reflection Lecture 27 Mon, Nov 10, 2003.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
Local Illumination and Shading
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] =
Render methods. Contents Levels of rendering Wireframe Plain shadow Gouraud Phong Comparison Gouraud-Phong.
Introduction to Meshes Lecture 22 Mon, Oct 20, 2003.
Illumination and Shading Sang Il Park Sejong University.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Computer Graphics One of the central components of three-dimensional graphics has been a basic system that renders objects represented by a set of polygons.
David Luebke3/16/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
Graphics Review Geometry, Color & Shading Brad Tennis Leslie Wu
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Computer Graphics Lecture 26 Mathematics of Lighting and Shading Part II Taqdees A. Siddiqi
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
POLYGON MESH Advance Computer Graphics
3D Graphics Rendering PPT By Ricardo Veguilla.
Chapter 14 Shading Models.
CSC461: Lecture 23 Shading Computation
Computer Graphics One of the central components of three-dimensional graphics has been a basic system that renders objects represented by a set of polygons.
Lecture 13 Clipping & Scan Conversion
Introduction to Meshes
Chapter 14 Shading Models.
Introduction to Meshes
Presentation transcript:

Polygon Shading

Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first we must digress…

Triangles We chose triangles as our area-based drawing primitive –Always convex –Easy to shade using a scanline algorithm, as we’ll see 23 1

Shading Triangles To shade the interior of a triangle we need to access each pixel within the interior –We can do this using something called barycentric coordinates They provide a parametric form of a triangle –But, as we’ll see, there is an easier way Once we can do this we can assign a color to each pixel

Shading There are two basic methods for assigning color to the interior pixels of an object (shading the object) Constant shading (with 2 sub-methods) –Per object –Per triangle Pixel based shading –Per vertex

Per-object Shading Recall the quadrilateral (or any general polygon with more than 3 sides) which we decided not to use

Per-object Shading To shade it in a per-object fashion we merely assign every pixel within the polygon the same RGB color value

Per-object Shading Efficient scan line algorithms for such shading are difficult, as previously discussed Furthermore, this method does not produce very satisfying results [if photo- realistic graphics is the goal] and therefore is rarely used The only advantage is that object colors can be specified off-line.

Per-triangle Shading In this method we do first divide the polygon into triangles Various techniques exist for performing this operation (e.g. Delauney triangulation) It is generally performed off line during the modeling of the objects

Per-triangle Shading Then, once we have the triangles we can shade each one individually

Per-triangle Shading Efficient scan line algorithms for such shading are available, as we will see –At very least the barycentric coordinates will help us Results are better than with per-object shading but still not great Where to store the color for each triangle may be problematic in that most efficient drawing systems allow triangle vertices to be reused for neighboring triangle specification

Triangle Vertices Rather than specify 9 vertices for these 3 triangles We specify the first 3 then let the next triangle share 2 Using a prescribed order we get a triangle strip Long strips save a lot of resources (time, space)

Triangle Vertices and Color But, given a triangle strip, in which vertex do you store the color for a given triangle when using per-triangle shading? Specify a convention and stick to it –e.g. the last vertex specified

Vertex Color What exactly does the vertex color represent and how is it represented? Use of triangles to represent a curved (or any) 3D surface is called tessellation and results in a faceted model of the surface –Basically, this saves memory and processing time Each surface will have at every triangle (point) –an orientation –a reflectance model –a natural color –Possibly other attributes

Vertex Color Perhaps the most important of these attributes is the orientation The orientation is a unit vector that is normal (perpendicular) to the surface at the given point The normals are used to determine the displayed color of an object after the lighting and viewer parameters have been defined (at run time)

Surface Normals To get the surface normal at the triangle vertices we average the normals of the triangles that meet at the vertex This method of assigning vertex normals is the basis for Gouraud Shading (Henri Gouraud)

Per-vertex (Gouraud) Shading Points on a given triangle are assigned a color that is a linear interpolation of the three vertex colors (as determined by their normals, color, surface material, the lighting model, and the viewer model) Gouraud does not care where the vertex colors come from, just that they are there

Per-vertex (Gouraud) Shading Gouraud shading is really nothing more than a linear interpolation of the 3 vertex colors Thus, all we have to do is interpolate the colors along the three edges –You can use the Bresenham algorithm for this Then interpolate colors along scan lines

Per-vertex (Gouraud) Shading P 0 (R 0, G 0, B 0 ) P 1 (R 1, G 1, B 1 ) P 2 (R 2, G 2, B 2 ) Interpolate between two end points of line segment

Triangle Shading Per-triangle (constant) shading Per-vertex (Gouraud) shading

Mach Bands Linear interpolation (Gouraud) provides realistic looking smooth surfaces most of the time But, Gouraud shading is not always good enough to fool the human visual system Due to the way cones in the eye are connected to the optic nerve, the human visual system has great sensitivity to small intensity changes –This is due to a property called lateral inhibition It is especially apparent at sharp intensity changes and changes in intensity gradient direction

Mach Bands The human visual system tends to “overshoot” intensities at transition points Although this quadrilateral is made of two triangles that share an edge, we still perceive a bright line Mach Band effect

Mach Bands The answer to this phenomenon is to invent algorithms that provide even more smoothness in intensity transitions… …which results in greater computational cost

Phong Shading Phong took Gouraud’s ideas a step further Rather than using the 3 vertex normals to define 3 vertex colors then interpolate the interior points of the triangle based on those colors, he interpolates the surface normals at each point then computes the color This results in –Reduced [but not eliminated] Mach Banding –More accurate representation of specular highlights –More computational requirements

Lighting The modeler assigns colors to vertices off line (during the design process) The shader combines the vertex color and the lighting specification to determine a render color for a vertex at run time The simplest lighting model is a cosine function

Cosine model lighting Lambertian reflector –Reflected energy from a small surface area in a particular direction is proportional to the cosine of the angle between that direction and the surface normal –It is not dependent on the position of the viewer

Cosine model lighting The cosine can be computed by taking the vector dot product between the surface normal and the light source –Just make sure that both are normalized to unit vectors Surface (triangle facet) Surface normal Light source

Calculating surface normals You already know how to compute the surface normal (orientation) for a triangle –Use the vector cross product –Make sure you know which direction your triangles are specified in (clockwise or counter-clockwise) u v (u X v) would be pointing out of the page

Assignment For the sphere model, do a per triangle shader –Calculate the surface normal for each triangle –Calculate the color of the triangle Set a light source (x, y, z) Set the color to R=G=B=dot(normal, light) Use your Bresenham code to scan each triangle into a scratch buffer Copy the scratch buffer into the on screen render buffer Gouraud’s technique (per vertex) is more difficult –Have to find a way to compute the normal at each vertex then compute the dot product with the light source – think about how you might do it