Lecture 4 Advanced Computer Graphics (CS & SE )

Similar documents
Ambient reflection. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 407

INF3320 Computer Graphics and Discrete Geometry

Lighting. CSC 7443: Scientific Information Visualization

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

Illumination and Shading

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

CS Surface Rendering

Why we need shading?

Shading and Illumination

Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Virtual Reality for Human Computer Interaction

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Advanced Computer Graphics (CS & SE )

CEng 477 Introduction to Computer Graphics Fall

Light Sources. Spotlight model

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

Display Issues Week 5

Graphics and Visualization

Computer Graphics. Illumination and Shading

Reading. Shading. Introduction. An abundance of photons. Required: Angel , Optional: OpenGL red book, chapter 5.

Lighting. Chapter 5. Chapter Objectives. After reading this chapter, you'll be able to do the following:

Shading in OpenGL. Outline. Defining and Maintaining Normals. Normalization. Enabling Lighting and Lights. Outline

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Light Transport Baoquan Chen 2017

Understand how real-world lighting conditions are approximated by OpenGL

5.2 Shading in OpenGL

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Illumination and Shading ECE 567

Ligh%ng and Shading. Ligh%ng and Shading. q Is this a plate or a ball? q What color should I set for each pixel?

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Shading. Brian Curless CSE 457 Spring 2015

Shading. CSE 457 Winter 2015

Models and Architectures

Lecture 4 of 41. Lab 1a: OpenGL Basics

Reading. Shading. An abundance of photons. Introduction. Required: Angel , 6.5, Optional: Angel 6.4 OpenGL red book, chapter 5.

CS 4620 Program 3: Pipeline

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Lights, Colour and Materials In OpenGL

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Graphics and Computation Introduction to OpenGL

CS 130 Final. Fall 2015

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Shading , Fall 2004 Nancy Pollard Mark Tomczak

DONALD HOUSE: CPSC 8170, FALL 2018 DESIGN OF A REAL-TIME ANIMATION PROGRAM

OpenGL Lighting Computer Graphics Spring Frank Palermo

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Lighting/Shading III. Week 7, Wed Mar 3

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Blue colour text questions Black colour text sample answers Red colour text further explanation or references for the sample answers

CS452/552; EE465/505. Intro to Lighting

Computer graphic -- Programming with OpenGL 2

Rasterization Overview

Realtime 3D Computer Graphics & Virtual Reality. Shading and Color. Introduction to Lighting and Shading

3D graphics, raster and colors CS312 Fall 2010

Visualizing Molecular Dynamics

Illumination and Shading

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Module 13C: Using The 3D Graphics APIs OpenGL ES

Illumination & Shading: Part 1

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CS4202: Test. 1. Write the letter corresponding to the library name next to the statement or statements that describe library.

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Pipeline Operations. CS 4620 Lecture 14

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Exercise 1 Introduction to OpenGL

Introduction to Computer Graphics with WebGL

CSE4030 Introduction to Computer Graphics

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Virtual Reality for Human Computer Interaction

Introduction to OpenGL

Illumination & Shading I

CHAPTER 1 Graphics Systems and Models 3

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Computer Graphics and Visualization. Graphics Systems and Models

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

Fachhochschule Regensburg, Germany, February 15, 2017

Shading Intro. Shading & Lighting. Light and Matter. Light and Matter

University of British Columbia CPSC 314 Computer Graphics Sep-Dec Tamara Munzner (guest lecturing) Lighting/Shading

CSE 167: Introduction to Computer Graphics Lecture #7: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2015

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

OpenGL/GLUT Intro. Week 1, Fri Jan 12

CS 4731: Computer Graphics Lecture 16: Phong Illumination and Shading. Emmanuel Agu

hw1-2 review hw 3 questions?

Reflection and Shading

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

CSC 470 Computer Graphics

Computer graphics Labs: OpenGL (1/3) Geometric transformations and projections

Visualisatie BMT. Rendering. Arjan Kok

OpenGL refresher. Advanced Computer Graphics 2012

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

Transcription:

Lecture 4 Advanced Computer Graphics (CS & SE 233.420)

Topics Covered Animation Matrices Viewing Lighting

Animating Interactive Programs Consider planet.c Want to animate rotating the Earth around the Sun Let year denote current rotation value 0 < year < 360 Global variable Display the Earth with the display function Suppose we want to increase year by a fixed amount whenever nothing else is happening

Animating with glutidlefunction First define the function void idle() { year+=2; if (year > 360) year-=360; glutpostredisplay(); } Next specify the callback glutidlefunction(idle);

Interactive Routine to Change Idle Use the mouse callback to change the idle function Define mouse callback glutmousefunc(mouse); Mouse function can be written as void mouse(int button, int state, int x, int y) { if(button==glut_left_button&state==glut_down) glutidlefunc(idle); f(button==glut_middle_button&state==glut_down) glutidlefunc(null); } Result Left mouse button starts Earth rotating Middle mouse button stop the rotation

Refresh Rate Want to refresh the screen sufficiently fast enough so the viewer cannot notice the clearing and redrawing of the screen To alleviate display flickering Refresh screen at appropriate refresh rate Most refresh rates are between 58Hz-85Hz Do not change the contents of the frame buffer

What Happens When You Change the Frame Buffer Contents? See undesirable artifacts of how we generate the display May only draw a part of the object May see different parts of objects on successive screens Moving object can appear distorted Solution Double buffering

Double Buffering Technique for the tricking the eye into seeing smooth animation of rendered scenes Color buffer is usually divided into two equal halves Front buffer and the back buffer Render in front buffer back buffer is displayed Swap buffers Render in back buffer front buffer is displayed Front Buffer 1 2 4 8 16 1 2 4 8 16 Display Back Buffer

Double Buffering Instead of one color buffer, we use two Front Buffer: one that is displayed but not written to Back Buffer: one that is written to but not displayed Program then requests a double buffer in main.c glutinitdisplaymode(gl_rgb GL_DOUBLE) At the end of the display callback buffers are swapped void mydisplay() { glclear() /* draw graphics here */ glutswapbuffers() }

Smoother Animation Routine gluttimerfunc(msec, value) Registers a timer callback to be triggered in a specified number of milliseconds The value parameter to the timer callback will be the value of the value parameter to gluttimerfunc. The number of milliseconds is a lower bound on the time before the callback is generated

What is a Matrix? A 2 dimensional array of numeric data where each row or column consist of a numeric values A way to describe n-dimensional transformations in one convenient package OpenGL uses 4x4 matrices

Identity Square matrix with 1 s along the diagonal 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1

Translate Used to position an object within 3D space If the translation is define by (x,y,z) OpenGL call gltranslate(x,y,z); 1 0 0 x 0 1 0 y 0 0 1 z 0 0 0 1

Scale Used to enlarge or shrink a 3D object If the scaling is define by (x,y,z) glscale(x,y,z) x 0 0 1 0 y 0 1 0 0 z 1 0 0 0 1

Rotate Used to rotate a 3D object Matrix used is axis specific X Axis 1 0 0 0 0 cos sin 0 0 -sin -cos 0 0 0 0 1 glrotate(x,0,0,0); Uses radians, not degrees

PUSH/POP Matrix Suppose you have 2 objects Want to translate one object without affecting the other Use glpushmatrix and glpopmatrix glpushmatrix() /* translate object */ glpopmatrix()

OpenGL and Matrices OpenGL has predefined matrices Modelview matrix Specifies location of camera Moves objects around the scene glpush(modelview); Pushes model view matrix onto the stack Think of this matrix as the world view

Viewing - Camera Analogy Set up the tripod and point the camera (view transform) Arrange the objects in the scene (model transform) Choose a lens and adjust zoom (projection transform) Choose photo print size (viewport transform)

3D Graphics is a Synthetic Camera Model camera viewing volume tripod model

Transformations and Camera Analogy Synthetic camera model is used Can synthesize lens OpenGL Viewing Volume Perspective pyramid shaped Human vision camera lens have cone-shaped viewing volumes Computer will see differently from natural viewpoints Especially around edges

Camera Analogy and Transformations Modeling transformations Moving the model Projection transformations Adjust the lens of the camera Viewing transformations Tripod define position and orientation of the viewing volume in the world Viewport transformations Enlarge or reduce the physical photograph

OpenGL and Transformations There are five transforms in OpenGL Vertices pass through: 1. Viewing Specifies location of camera 2. Modeling Moves objects around the scene 3. Projection Defines the viewing volume 4. Viewport Maps the 2D projection to the rendering window 5. Modelview Combination of viewing and modeling transforms Must be executed in a specific order.

Following the Pipeline Transformations Much of the work in the pipeline is in converting object representations from one coordinate system to another Synthetic World coordinates Camera coordinates Screen coordinates Every change of coordinates is equivalent to a matrix transformation Modelview matrix Converts object coordinates into eye coordinates Model transformations move the object View transformations move the eyepoint

Clipping Just as a real camera cannot see the whole world, the virtual camera can only see part of the world space Objects that are not within this volume are said to be clipped out of the scene

Projection Must carry out the process that combines the 3D viewer with the 3D objects to produce the 2D image Perspective projections: all projectors meet at the center of projection Parallel projection: projectors are parallel, center of projection is replaced by a direction of projection

Rasterization If an object is visible in the image, the appropriate pixels in the frame buffer must be assigned colors Vertices assembled into objects Effects of lights and materials must be determined Polygons filled with interior colors/shades Must have also determine which objects are in front (hidden surface removal)

Lighting Principles Lighting simulates how objects reflect light material composition of object light s color and position global lighting parameters ambient light two sided lighting available in both color index and RGBA mode

Turn on the Power gldisable(gl_lighting) Objects are colored according to glcolor state value for that object glenable(gl_lighting) Use lighting Need to specify more about the surface other than just color How shiny is it? Does glow in the dark? Does light scatter uniformly? Flip the light switch glenable(light0)

Lighting Deals with Two Parameters Lighting properties Parameters indexed to light numbers Upto 8 lights (LIGHT0-LIGHT7) Light positions are affected by the modelview matrix stack Material Properties State variables assigned to polygons Can be changes as you draw different polygons

How OpenGL Simulates Light Lighting is based on the Phong lighting model At each vertex in the primitive, a color is computed using primitive's material properties along with light settings The color for the vertex is computed by adding four computed colors for he final vetex color The four contributors to the vertex color are: Ambient Color of the object from all the undirected light in a scene Diffuse Base color of the object under current lighting Specular Contribution of the shiny highlights on the object Emission Contribution added in if the object emits light

Light Properties gllight(light, property, value) Used to set the parameters for a light OpenGL has at least 8 lights GL_LIGHT 0,..., GL_LIGHT (GL_MAX_LIGHTS-1) Characteristics (properties) of lights that can change include Colors Position and type Attenuation

OpenGL Light Properties Light color properties GL_AMBIENT GL_DIFFUSE GL_SPECULAR

Setting Ambient Light Light that comes from all directions equally and is scattered in all directions Set up ambience GLfloat ambient = {0.2,0.2,0.2,1}; Enable ambient light for a specific light gllightfv(gl_light0, GL_AMBIENT, ambient);

Types of Lights OpenGL supports two types of Lights Local (Point) light sources Infinite (Directional) light sources Type of light controlled by w coordinate w = 0 w 0 Infinite Light directed along Local Light positioned at ( x y z) ( x y z ) w w w

Controlling a Light s Position Modelview matrix affects a light s position Different effects based on when position is specified eye coordinates world coordinates model coordinates Push and pop matrices to uniquely control a light s position

Surface Normals Surface normals tell OpenGL how the object reflects light around a vertex Imagine there is a small mirror at the vertex, the lighting normal describes how the mirror is oriented, and consequently how the light is reflected Normals define how a surface reflects light

Lighting Normals glnormal*() Sets the current normal, which is used in the lighting computation for all vertices until a new normal is provided Normals should be normalized to unit length for correct lighting glscale*() affects normals as well as vertices, which can change the normal's length and cause it to no longer be normalized

Lighting Normals OpenGL routines to automatically normalize normals glenable(gl_normalize) Handles all normalization situations Requires square root computation Potentially lower performance glenable(gl_rescale_normal) Special mode for when normals are uniformally scaled

Material Properties Describe the color and surface properties of a material (dull, shiney, etc) OpenGL supports material properties for both the front and back of objects Can be set for each face separately by specifying either GL_FRONT, GL_BACK or GL_FRONT_AND BACK for both faces

OpenGL Material Properties GL_DIFFUSE Base color of object GL_SPECULAR Color of highlights of an object GL_AMBIENT Color of an object when not directly illuminated GL_EMISSION Color emitted from the object GL_SHININESS Concentration of highlights on objects

Light Material Tutorial

Light Position Tutorial

Advanced Lighting Features Spotlights localize lighting affects GL_SPOT_DIRECTION GL_SPOT_CUTOFF GL_SPOT_EXPONENT

Advanced Lighting Features Light attenuation decrease light intensity with distance GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION f i = k c + k l 1 d + k q d 2

Light Model Properties gllightmodelfv( property, value ); Enabling two sided lighting GL_LIGHT_MODEL_TWO_SIDE Global ambient color GL_LIGHT_MODEL_AMBIENT Local viewer mode GL_LIGHT_MODEL_LOCAL_VIEWER Separate specular color GL_LIGHT_MODEL_COLOR_CONTROL

References Open GL web page www.opengl.org http://www.opengl.org/resources/faq/technical http://www.newcyber3d.com/asia/selfstudy/tips/selection.htm http://www.lighthouse3d.com/opengl/displaylists http://www.mfcogl.com/multiview%20animation%20mfc_opengl.htm www.cs.colorado.edu/~janem/cs4229/lec6_ch3-4.pdf http://www.codecolony.de/docs/camera.htm http://mathcs.holycross.edu/~croyden/graphics/assignments/sol5/soluti on5.html www.cs.stevens-tech.edu/~quynh/courses/cs537- fa03/projection_gl.ppt http://gamecode.tripod.com/tut/tut03.htm http://www.basic4gl.net/introduction%20to%20opengl%20part%202.ht m http://www.falloutsoftware.com/tutorials/gl/gl0.htm