Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.

Slides:



Advertisements
Similar presentations
Presented by: Stacy C. Lovell. How do we perceive color? Our eyes contain only 3 types of photosentitive cells tuned to three frequencies Red, Green,
Advertisements

OpenGL Course Notes Chapter 5: Lighting Jim Mims, Spring 2009.
Illumination Lighting and Shading CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of New Mexico
Computer Graphics - Class 10
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
IMGD 1001: Illumination by Mark Claypool
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
UniS CS297 Graphics with Java and OpenGL Colour and Lighting.
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
1 Lecture 10 Lighting in OpenGL. 2 Sources of light GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 1.0}; GLLightfv(GL_LIGHT0, GL_POSITION, myLightPosition);
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
Illumination and Shading
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
SET09115 Intro Graphics Programming
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Shading in OpenGL.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
Human Eye and Color Rays of light enter the pupil and strike the back of the eye (retina) – signals go to the optic nerve and eventually to the brain Retina.
Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
OpenGL - Lighting, Shading and Material Properties
Computer Graphics I, Fall 2010 Shading in OpenGL.
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
11/04/04© University of Wisconsin, CS559 Fall 2004 Last Time Visibility –Z-Buffer and transparency –A-buffer –Area subdivision –BSP Trees –Exact Cell-Portal.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Improving the appearance of 3D OpenGL scenes
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
Computer Graphics: Illumination
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
CSC Graphics Programming
Shading To determine the correct shades of color on the surface of graphical objects.
Illumination and Shading
@ 2017 by Jim X. Chen George Mason University
Shading in OpenGL Ed Angel
Lighting and Shading Lab 8:.
Lighting Phong's Lighting Model normals
Lighting and Materials
Lighting – Material Properties
Color and Shading Lecture 9 Mon, Sep 26, 2005.
Computer Graphics 4Practical Lesson
Lighting and Shading Lab 8:.
CS 480/680 Computer Graphics Shading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell

How do we perceive color? Our eyes contain only 3 types of photosentitive cells tuned to three frequencies –Red, Green, and Blue (RGB) Sensation of color is created in our brains by averaging and recognizing millions of combinations of red, green, and blue Different spectra can produce the same color –By mixing two frequencies (blue and yellow) –By providing a single frequency (a green light) –We cannot distinguish the color difference even though the corresponding spectra are totally different

The eye Retina contains cones that register different photons

Newton observed that color is not inherent in objects, rather, the surface of an object reflects some colors and absorbs others. We only perceive the reflected colors.

RGB (and sometimes A) Color model Red, green, and blue pixels are assigned brightness values –0 to 1 where 0 is none or dark –(0,0,0) = black (1,1,1) = white –You can then specify the exact color to be mixed –A computer monitor is only capable of producing a certain range of color, and is further reduced by the limitations of computer hardware. It can display up to 16.7 million colors (with 24 bitplanes)

RGBA mode continued A certain amount of color data is stored at each pixel, determined by number of bitplanes in framebuffer Bitplane contains 1 bit of data for each pixel 8 color bitplanes and 8 color bits per pixel –256 different values or colors can be stored at the pixel

Alpha Alpha value has no direct affect on color displayed on screen Used for blending and transparency

Blending –Green and blue creates shades of cyan –Blue and red creates magenta –Red and green creates yellow Color cube

Specifying color in OpenGL glColor3f(1.0, 0.0, 0.0); //sets RGB color to red glBegin(GL_POINTS); glVertex3f(….) //draw some vertices glEnd(); The color drawn will be red until it is changed glColor4f (1.0,0.0,0.0,0.5) ; //to set an alpha value

There are two modes, RGBA and color- index mode -- we won’t be dealing with color-index mode, but feel free to read up on it if you are interested If lighting is enabled, color is determined from the interaction of the transformation matrices with the surface normals and other material properties

Dithering The technique of using combinations of some colors to create the effect of other colors –For example, to display pink, the hardware can fill the region by alternating red and white pixels. –glEnable(GL_DITHER); or glDisable Enabled by default

Specifying a shading model Lines and filled polygons can be drawn with a single color (flat shading) or with many different colors (smooth shading) –glShadeModel(GL_SMOOTH); //default Or GL_FLAT –For smooth shading, colors along the line segment are interpolated between vertex colors –For polygons, colors along the interior are interpolated between vertex colors

Three vertices at corners drawn in red, green, and blue, and the rest is smooth shaded between these colors

Color cube

Lighting (Chapter 5)

Overview 2 different types of light sources –Directional - infinite distance away from objects in scene, rays are considered parallel by the time they reach the object –Positional - near or within scene, direction of rays taken into account in lighting calculations

Overview continued glLightfv() used to specify position of light regardless of type, and is also used to specify color components Normal vectors and material properties must be defined after light sources are defined

Hidden-surface removal Uses the depth buffer (or z-buffer) –Associated a depth from the view plane with each pixel on the window. Set to the largest possible distance initially using glClear(GL_DEPTH_BUFFER_BIT) Objects are then drawn in any order –If enabled, before each pixel is drawn a comparison is done with the depth value already stored at the pixel, if a new pixel is closer, then its value replace those currently written

Depth-buffer testing and hidden-surface removal can increase performance glutInitDisplayMode (GLUT_DEPTH |.... ); glEnable(GL_DEPTH_TEST);... while (1) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); get_viewing_point_from_mouse_position(); draw_3d_object_A(); draw_3d_object_B(); }

Different types of light Ambient - light that comes from all directions Diffuse - light that comes from one directions –Once it hits a surface, it is scattered equally Specular - comes from a particular directions and tends to bounce off the surface in a preferred direction –Ex: a laser bouncing off a mirror produces almost 100% specular reflection –Think of as “shininess”

Lighting model OpenGL makes approximation that a color depends on the percentages of incoming light it reflects. Materials have both ambient, diffuse, and specular reflectance properties and emissive properties which simulate light originating from an object –Like a light bulb –Emissive color is unaffected by any light sources

RGB, light, materials All 1.0 = brightest possible white light All 0.5 = half intensity of white light (gray) R=G=1 B=0? –Full red, full green, no blue = yellow light For materials, numbers correspond to reflected proportions of color R=1, G=0.5, B=0 means material reflects all the incoming red light, half incoming green, and no blue. If light has component (LR, LG, LB) and a material has (MR, MG, MB) then light that arrives at eye is given by: ( LR*MR, LG*MG, LB*MB)

A lit and unlit sphere

Defining normal vectors An object’s normals determine its orientation relative to light sources –Very important if you want your object to display correctly –For each vertex, it uses the normal to determine how much light that vertex receives from each light source

Normal review A normal vector is a vector that points in a direction that is perpendicular to a surface “Right hand rule” –Use glNormal() to set current normal glBegin (GL_POLYGON); glNormal3fv(n0); glVertex3fv(v0); glNormal3fv(n1); glVertex3fv(v1); glNormal3fv(n2); glVertex3fv(v2); glNormal3fv(n3); glVertex3fv(v3); glEnd();

Normals continued… The cross product or vector product produces a resulting vector that is orthogonal to both u and v, where n is the direction of the resulting vector. Remember? u x v is the notation which is defined as: n |u||v| sin  where n is the unit vector that is perpendicular to u and v and  is the angle between the vectors u and v

Defining properties Use glEnable(GL_LIGHTING) –glEnable(GL_LIGHT0) //explicitly enable each light source that you define after you’ve specified the parameters Select a light model glLightModelfv(GL_LIGHT_MODEL_AMBIENT) Define material properties –glMaterialfv(GL_DIFFUSE); (GL_AMBIENT_AND_DIFFUSE) (GL_SPECULAR) (GL_EMISSION) (GL_AMBIENT)

Creating light sources –glLightfv (GL_AMBIENT) DIFFUSE, SPECULAR, POSITION, ETC… To specify a blue ambient light, for example GLfloat light_ambient[ ] = { 0.0, 0.0, 1.0, 1.0 } ; glLightfv( GL_LIGHT0, GL_AMBIENT, light_ambient ); GL_DIFFUSE can be thought of as “the color of light” GL_SPECULAR affects the color of the specular highlight (often same color as light shining on it) -like light reflecting off of a glass Changing light position –Pass GL_POSITION to glLightfv

Left - pale blue ambient light, white diffuse light source Right - pale blue ambient light source, no ambient light

Left - infinite light source Right - local light source

Teapots drawn with increasing ambient light

The color produced by lighting a vertex is computed as follows: –Vertex color = The material emission at that vertex + The global ambient light scaled by materials ambient property at that vertex + The ambient, diffuse, and specualr contributions from all the light sources

The End!