Improving the appearance of 3D OpenGL scenes

Slides:



Advertisements
Similar presentations
15.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 15 – Visible Surfaces and Shadows.
Advertisements

16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.
8.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 8 Polygon Rendering.
Graphics Pipeline.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
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.
1 3D modelling with OpenGL Brian Farrimond Robina Hetherington.
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.
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL Brian Farrimond Robina Hetherington. What is OpenGL A specification of a set of functions for drawing graphics –Names of functions –What information.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
SET09115 Intro Graphics Programming
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.
Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Shading & Texture. Shading Flat Shading The process of assigning colors to pixels. Smooth Shading Gouraud ShadingPhong Shading Shading.
OpenGL - Lighting, Shading and Material Properties
Computer Graphics I, Fall 2010 Shading in OpenGL.
Lecture 9: Lighting and Shading 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Lecture 6: 3D graphics Concepts 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 
Lecture 11: Exam Revision 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271  Coursework.
Taku KomuraComputer Graphics Local Illumination and Shading Computer Graphics – Lecture 10 Taku Komura Institute for Perception, Action.
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,
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
Chris Mayer & Nic Shulver Hidden Surface Wire frame drawings Wire frame drawings are quick to produce but are often confusing It is difficult to determine.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
1 A first OpenGL program Brian Farrimond Robina Hetherington.
Illumination and Shading
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.
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.
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[] =
Visible surface determination. Problem outline Given a set of 3D objects and a viewing specification, we wish to determine which lines or surfaces are.
1 Computer Graphics Week11 : Hidden Surface Removal.
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 Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
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.
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
Vectors, Normals, & Shading
Shading in OpenGL Ed Angel
Lighting and Shading Lab 8:.
Lighting.
Lighting Phong's Lighting Model normals
The Graphics Pipeline Lecture 5 Mon, Sep 3, 2007.
Lighting and Materials
Computer Graphics 4Practical Lesson
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Material Colours and Lighting
Presentation transcript:

Improving the appearance of 3D OpenGL scenes Brian Farrimond Robina Hetherington

What we shall do Hidden line removal Lighting and shading Materials Enable nearer objects to hide distant objects Lighting and shading Improve the sense of depth with shading Materials Add colour Importing 3DSMax models Add realistic models

Hidden line removal Unless told otherwise, OpenGL draws on top of other objects regardless of how far away they are Suppose we want to draw this -----------

First attempt

The effect Because OpenGL draws the cube then the sphere, the sphere is drawn on top even though it is further away Ex07

Hidden line removal OpenGL uses depth-buffering (also known as z-buffering) Depth buffer is created It records for each pixel, the distance from the viewer Initially all set to a very large value

Hidden line removal As each object drawn each pixel is generated its distance from the viewer is compared with the corresponding value in the depth buffer If smaller than the value already there then Pixel is updated Its distance is recorded in the depth buffer Otherwise Pixel is not drawn

Coding in OpenGL 1. In main – create a depth buffer

Coding in OpenGL 2. In reshape – enable depth testing

Coding in OpenGL 3. In display – set the depth buffer to high values

Results – Ex08

Lighting 3D drawing aims to look realistic Realism includes realistic lighting effects Light in the real world is very complicated Optics is a whole branch of Physics Light involves quantum mechanics! OpenGL uses simplified light calculations Results are acceptable

Default lighting OpenGL default is to have no lighting Switch on the lighting with: glEnable(GL_LIGHTING); OpenGL has 8 lights available named GL_LIGHT0, GL_LIGHT1, .., GL_LIGHT7 Switch on a light like this: glEnable(GL_LIGHT0);

Ex09 Here is init modified to switch on GL_LIGHT0

Ex09 Ex08 – no lighting Ex09 – with lighting

Ex09 Sphere has its polygons visible No colours – glColor3f is ignored in a lit scene

Setting the shade model We can make the sphere show its polygons with glShadeModel(GL_FLAT); When drawing a polygon, OpenGL chooses one of the polygons vertices and colours all the polygon's pixels the same colour as this vertex Put the command into init

Setting the shade model We can make the sphere look smoother with glShadeModel(GL_SMOOTH); When drawing a polygon, OpenGL computes a colour for each vertex then colours the polygon's interior pixels by interpolating the vertex values to provide the smooth effect. This is the OpenGL default. Put the command into init

Defining materials to get colour When we use lights we need to specify an object’s colour in a more sophisticated way Interaction of a surface with light is scary physics In OpenGL we simplify by using the concept of material properties

Lights with colour

OpenGL material properties Material property Description Ambient Light scattered by the rest of the scene. It is omnidirectional. Diffuse Reflected light from light sources. The more directly the surface faces a light, the more light is reflected. Emissiveness Light generated by the object. Used mainly to simulate lamps or the Sun in a scene Specular Specular reflection produces highlights which are brightest at the angle of reflection between the light and the viewpoint. Shininess The brightness and sharpness of the highlight.

Specifying diffuse colour Defining colours as 4 element arrays of floating point numbers: red, green, blue, alpha

Specifying diffuse colour Each array element is a floating point number

Specifying diffuse colour Indicates the variable is an array instead of a single value

Specifying diffuse colour Puts values into the array

Specifying diffuse colour Setting the colour for the red cube

Specifying diffuse colour Setting the colour for the green sphere

Notes We need to use arrays to define material colours GL_FRONT specifies that the colour should be applied to the front of the object’s polygons Alternatives are GL_FRONT and GL_FRONT_AND_BACK

Defining the light Default colour is white Default position is (0, 0, 1) Change the position like this …

Array containing x, y, z coords of light position Defining the light Default colour is white Default position is (0, 0, 1) Change the position like this … Array containing x, y, z coords of light position plus w value w = 0 : light at specified point w = 1 : light is at infinity in direction from origin through (x, y, z)

Light is moved to the new position Defining the light Default colour is white Default position is (0, 0, 1) Change the position like this … Light is moved to the new position

Nate Robbins tutorial LightMaterial

ExLoad3DS Illustrates changing the light position interactively

Using 3DS Models in OpenGL Complex models can be imported into OpenGL if the file format is understood 3DSMax has a facility for exporting models as .3ds files. Web sites contain clues as to the structure of this file format In this module we shall use the vertex and polygon information found there

Using 3DS Models in OpenGL We need to Load the 3DS data into a suitable data structure Use the data structure to draw OpenGL polygons

Procedure: adding files Put a copy of the files load3dsbtf.cpp load3dsbtf.h into your project folder Add load3dsbtf.cpp to your project tree

Procedure: programming the OpenGL Add a variable that forms the data structure Use the call loadBTF3DS to load a model from the .3ds file Use the call display3DSObject to display the model in OpenGL

Include file with definitions needed for 3DS ExLoad3ds Include file with definitions needed for 3DS

3DS file may contain more than one object ExLoad3ds 3DS file may contain more than one object

Array of pointers to 3ds object data structures ExLoad3ds Array of pointers to 3ds object data structures

Count of the number of 3ds objects ExLoad3ds Count of the number of 3ds objects

A function to set the colour

Here we load the 3DS object from its file init Here we load the 3DS object from its file

display

Display each of the objects read from the 3DS file