Computer Graphics. Bing-Yu Chen National Taiwan University

Similar documents
An Interactive Introduction to OpenGL Programming

CS 5610 / Spring Depth Buffering and Hidden Surface Removal

Better Interactive Programs

Better Interactive Programs. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

12. Selection. - The objects selected are specified by hit records in the selection buffer. E.R. Bachmann & P.L. McDowell MV 4202 Page 1 of 13

4 Introduction to OpenGL Programming. Chapter 4. Introduction to OpenGL Programming. Department of Computer Science and Engineering 4-1

An Interactive Introduction to OpenGL Programming. An Interactive Introduction to OpenGL Programming. SIGGRAPH New Orleans 1

Scan line algorithm. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 272

E.Order of Operations

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Input and Interaction

Chapter 10 The Framebuffer Buffers and Their Uses Color Buffers Clearing Buffers Selecting Color Buffers for Writing and Reading Masking Buffers

Chapter 13 Selection and Feedback

Buffers and Processing Fragments

Graphics Pipeline & APIs

Lecture 4. Interaction / Graphical Devices. CS 354 Computer Graphics Sunday, January 20, 13

Definition. Blending & Compositing. Front & Back Buffers. Left & Right Buffers. Blending combines geometric objects. e.g.

Computer Graphics. Bing-Yu Chen National Taiwan University

Pixels and Buffers. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Graphics Pipeline & APIs

Advanced Computer Graphics (CS & SE )

Lecture 4 of 41. Lab 1a: OpenGL Basics

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

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

OpenGL. Toolkits.

/opengl/docs/man_pages/hardcopy/gl/html/gl/

Display Lists. Conceptually similar to a graphics file. In client-server environment, display list is placed on server

INF3320 Computer Graphics and Discrete Geometry

Loop Boundary - ignore edge vertex near boundary rule. use the same edge vertex rule. Deadline changed to Friday night(7/20) 11:59p Selection - extra

Display Lists in OpenGL

Buffers, Textures, Compositing, and Blending. Overview. Buffers. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E.

INF3320 Computer Graphics and Discrete Geometry

Lectures Display List

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

Working Style of Program

Lecture 26 of 41. Picking Videos 5: More CGA

Computer Graphics. Bing-Yu Chen National Taiwan University

Discrete Techniques. 11 th Week, Define a buffer by its spatial resolution (n m) and its depth (or precision) k, the number of

Shadow Algorithms. CSE 781 Winter Han-Wei Shen

Computer Graphics. Bing-Yu Chen National Taiwan University

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Rasterization Overview

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

Normalized Device Coordinate System (NDC) World Coordinate System. Example Coordinate Systems. Device Coordinate System

World Coordinate System

Computergrafik. Matthias Zwicker. Herbst 2010

CHAPTER 1 Graphics Systems and Models 3

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

CS418 OpenGL & GLUT Programming Tutorial (IV) MP2 Bonus/Object Picking. Presented by : Wei-Wen Feng 2/20/2008

Interaction. CSCI 480 Computer Graphics Lecture 3

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

cs123 Lab 3 OpenGL Part One 1 Introduction 2 OpenGL Basics 2.2 The Rendering Pipeline 2.1 The CPU and the GPU 2.3 Basic Syntax of OpenGL commands

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Interaction Computer Graphics I Lecture 3

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Imaging and Raster Primitives

Image Rendering. Rendering can be divided into three sub-problems. Image Formation The hidden surface problem visibility determination steps

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

Exercise 1 Introduction to OpenGL

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

Introduction to OpenGL

Modeling with Transformations

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

OpenGL Transformations

Performance OpenGL Programming (for whatever reason)

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

VR-programming tools (procedural) More VRML later in this course! (declarative)

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Interaction. CSCI 420 Computer Graphics Lecture 3

CS193P - Lecture 19. iphone Application Development. OpenGL ES

Chapter 7 Display Lists

An Interactive Introduction to OpenGL Programming

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

Lectures OpenGL Introduction

Introduction to OpenGL. Prof. Dr.-Ing. Lars Linsen

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

HE COMPLETE OPENGL PROGI FOR WINDOW WIND

Picking. Lecture 9. Using Back Buffer. Hw notes. Using OpenGL Selection Using Back Buffer

Lectures Transparency Case Study

Scanline Rendering 2 1/42

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

C OMPUTER G RAPHICS Thursday

Computer Graphics. Chapter 10 Three-Dimensional Viewing

CS 591B Lecture 9: The OpenGL Rendering Pipeline

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

Introduction to the OpenGL Shading Language

Rasterization Computer Graphics I Lecture 14. Scan Conversion Antialiasing Compositing [Angel, Ch , ]

Today s class. Viewing transformation Menus Mandelbrot set and pixel drawing. Informationsteknologi

Lecture 2. Determinants. Ax = 0. a 11 x 1 + a 12 x a 1n x n = 0 a 21 x 1 + a 22 x a 2n x n = 0

Computer Graphics 1 Computer Graphics 1

Order Independent Transparency with Dual Depth Peeling. Louis Bavoil, Kevin Myers

GPU Memory Model. Adapted from:

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Advanced Shading and Texturing

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

CONTENTS... 1 OPENGL REFERENCE MANUAL...

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

Models and Architectures

Fachhochschule Regensburg, Germany, February 15, 2017

Transcription:

Computer Graphics Bing-Yu Chen National Taiwan University

Introduction to OpenGL General OpenGL Introduction An Example OpenGL Program Drawing with OpenGL Transformations Animation and Depth Buffering Lighting Evaluation and NURBS Texture Mapping Advanced OpenGL Topics Imaging modified from Dave Shreiner, Ed Angel, and Vicki Shreiner. An Interactive Introduction to OpenGL Programming. ACM SIGGRAPH 2001 Conference Course Notes #54. & ACM SIGGRAPH 2004 Conference Course Notes #29.

Advanced OpenGL Topics Display Lists and Vertex Arrays Alpha Blending and Antialiasing Using the Accumulation Buffer Fog Feedback & Selection Fragment Tests and Operations Using the Stencil Buffer

Immediate Mode versus Display Listed Rendering Immediate Mode Graphics Primitives are sent to pipeline and display right away No memory of graphical entities Display Listed Graphics Primitives placed in display lists Display lists kept on graphics server Can be redisplayed with different state Can be shared among OpenGL graphics contexts

Immediate Mode versus Display Lists Immediate Mode Polynomial Evaluator Per Vertex Operations & Primitive Assembly CPU Display List Rasterization Per Fragment Operations Frame Buffer Display Listed Pixel Operations Texture Memor y

Poly. Per Vertex Display Lists CPU DL Pixel Texture Raster Frag FB Creating a display list GLuint id; void init( void ) { id = glgenlists( 1 ); glnewlist( id, GL_COMPILE ); /* other OpenGL routines */ glendlist(); } Call a created list void display( void ) { glcalllist( id ); }

Display Lists Not all OpenGL routines can be stored in display lists State changes persist, even after a display list is finished Display lists can call other display lists Display lists are not editable, but you can fake it make a list (A) which calls other lists (B, C, and D) delete and replace B, C, and D, as needed

Display Lists and Hierarchy Consider model of a car Create display list for chassis Create display list for wheel glnewlist( CAR, GL_COMPILE ); glcalllist( CHASSIS ); gltranslatef( ); glcalllist( WHEEL ); gltranslatef( ); glcalllist( WHEEL ); glendlist();

Advanced Primitives Vertex Arrays Bernstein Polynomial Evaluators basis for GLU NURBS NURBS (Non-Uniform Rational B-Splines) GLU Quadric Objects sphere cylinder (or cone) disk (circle)

Vertex Poly. Per Vertex Arrays CPU DL Pixel Texture Raster Frag FB Pass arrays of vertices, colors, etc. to Color OpenGL in a large chunk data glvertexpointer( 3, GL_FLOAT, 0, coords ) glcolorpointer( 4, GL_FLOAT, 0, colors ) glenableclientstate( GL_VERTEX_ARRAY ) glenableclientstate( GL_COLOR_ARRAY ) gldrawarrays( GL_TRIANGLE_STRIP, 0, numverts ); All active arrays are used in rendering Vertex data

Why use Display Lists or Vertex Arrays? May provide better performance than immediate mode rendering Display lists can be shared between multiple OpenGL context reduce memory usage for multi-context applications Vertex arrays may format data for better memory access

Alpha: the 4th Color Component Measure of Opacity simulate translucent objects glass, water, etc. composite images antialiasing ignored if blending is not enabled glenable( GL_BLEND )

Poly. Per Vertex Blending CPU DL Pixel Texture Raster Frag FB Combine pixels with what s in already in the framebuffer glblendfunc( src, dst ) Fragment (src) C r Framebuffer Pixel (dst) src C Blending Equation f dst C p Blended Pixel

Multi-pass Rendering Blending allows results from multiple drawing passes to be combined together enables more complex rendering algorithms Example of bump-mapping done with a multi-pass OpenGL algorithm

Antialiasing Removing the Jaggies glenable( mode ) GL_POINT_SMOOTH GL_LINE_SMOOTH GL_POLYGON_SMOOTH alpha value computed by computing sub-pixel coverage available in both RGBA and colormap modes

Accumulation Buffer Problems of compositing into color buffers limited color resolution clamping loss of accuracy Accumulation buffer acts as a floating point color buffer accumulate into accumulation buffer transfer results to frame buffer

Accessing Accumulation Buffer glaccum( op, value ) operations within the accumulation buffer: GL_ADD, GL_MULT from read buffer: GL_ACCUM, GL_LOAD transfer back to write buffer: GL_RETURN glaccum(gl_accum, 0.5) multiplies each value in write buffer by 0.5 and adds to accumulation buffer

Accumulation Buffer Applications Compositing Full Scene Antialiasing Depth of Field Filtering Motion Blur

Full Scene Antialiasing : Jittering the view Each time we move the viewer, the image shifts Different aliasing artifacts in each image Averaging images using accumulation buffer averages out these artifacts

Depth of Focus : Keeping a Plane in Focus Jitter the viewer to keep one plane unchanged Back Plane Focal Plane Front Plane eye pos 1 eye pos 2

Fog glfog{if}( property, value ) Depth Cueing Specify a range for a linear fog ramp GL_FOG_LINEAR Environmental effects Simulate more realistic fog GL_FOG_EXP GL_FOG_EXP2

Fog Tutorial

Feedback Mode Transformed vertex data is returned to the application, not rendered useful to determine which primitives will make it to the screen Need to specify a feedback buffer glfeedbackbuffer( size, type, buffer ) Select feedback mode for rendering glrendermode( GL_FEEDBACK )

Selection Mode Method to determine which primitives are inside the viewing volume Need to set up a buffer to have results returned to you glselectbuffer( size, buffer ) Select selection mode for rendering glrendermode( GL_SELECT )

Selection Mode (cont.) To identify a primitive, give it a name names are just integer values, not strings Names are stack based allows for hierarchies of primitives Selection Name Routines glloadname( name ) glpushname( name ) glinitnames()

Picking Picking is a special case of selection Programming steps restrict drawing to small region near pointer use glupickmatrix() on projection matrix enter selection mode; re-render scene primitives drawn near cursor cause hits exit selection; analyze hit records

Picking Template glutmousefunc( pickme ); void pickme( int button, int state, int x, int y ) { GLuint namebuffer[256]; GLint hits; GLint myviewport[4]; if (button!= GLUT_LEFT_BUTTON state!= GLUT_DOWN) return; glgetintegerv( GL_VIEWPORT, myviewport ); glselectbuffer( 256, namebuffer ); (void) glrendermode( GL_SELECT ); glinitnames();

Picking Template (cont.) } glmatrixmode( GL_PROJECTION ); glpushmatrix(); glloadidentity(); glupickmatrix( (GLdouble) x, (GLdouble) (myviewport[3]-y), 5.0, 5.0, myviewport ); /* gluperspective or glortho or other projection */ glpushname( 1 ); /* draw something */ glloadname( 2 ); /* draw something else */ glmatrixmode( GL_PROJECTION ); glpopmatrix(); hits = glrendermode( GL_RENDER ); /* process namebuffer */

Picking Ideas For OpenGL Picking Mechanism only render what is pickable (e.g., don t clear screen!) use an invisible filled rectangle, instead of text if several primitives drawn in picking region, hard to use z values to distinguish which primitive is on top Alternatives to Standard Mechanism color or stencil tricks (for example, use glreadpixels() to obtain pixel value from back buffer)

Framebuffer Fragment Getting to the Framebuffer Scissor Test Alpha Test Stencil Test Depth Test Blending Dithering Logical Operations

Scissor Box Additional Clipping Test glscissor( x, y, w, h ) any fragments outside of box are clipped useful for updating a small section of a viewport affects glclear() operations

Poly. Per Vertex Alpha Test CPU DL Pixel Texture Raster Frag FB Reject pixels based on their alpha value glalphafunc( func, value ) glenable( GL_ALPHA_TEST ) use alpha as a mask in textures

Poly. Per Vertex Stencil Buffer CPU DL Pixel Texture Raster Frag FB Used to control drawing based on values in the stencil buffer Fragments that fail the stencil test are not drawn Example: create a mask in stencil buffer and draw only objects not in mask area

Controlling Stencil Buffer glstencilfunc( func, ref, mask ) compare value in buffer with ref using func only applied for bits in mask which are 1 func is one of standard comparison functions glstencilop( fail, zfail, zpass ) Allows changes in stencil buffer based on passing or failing stencil and depth tests: GL_KEEP, GL_INCR

Creating a Mask glinitdisplaymode( GLUT_STENCIL ); glenable( GL_STENCIL_TEST ); glclearstencil( 0x0 ); glstencilfunc( GL_ALWAYS, 0x1, 0x1 ); glstencilop( GL_REPLACE, GL_REPLACE, GL_REPLACE ); draw mask

Using Stencil Mask Draw objects where stencil = 1 glstencilfunc( GL_EQUAL, 0x1, 0x1 ) Draw objects where stencil!= 1 glstencilfunc( GL_NOTEQUAL, 0x1, 0x1 ); glstencilop( GL_KEEP, GL_KEEP, GL_KEEP );

Dithering glenable( GL_DITHER ) Dither colors for better looking results Used to simulate more available colors

Logical Operations on Pixels Combine pixels using bitwise logical operations gllogicop( mode ) Common modes GL_XOR GL_AND

Advanced Imaging Imaging Subset Only available if GL_ARB_imaging defined Color matrix Convolutions Color tables Histogram MinMax Advanced Blending