Advanced OpenGL. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/05/07 1

Similar documents
Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

OpenGL Performance Tuning

Image Synthesis. Transparency. computer graphics & visualization

INTRODUCTION TO RENDERING TECHNIQUES

Aston University. School of Engineering & Applied Science

Graphics Pipeline in a Nutshell

Recent Advances and Future Trends in Graphics Hardware. Michael Doggett Architect November 23, 2005

Computer Graphics Hardware An Overview

3D graphic acceleration history and architecture

Methodology for Lecture. Review of Last Demo

GPU(Graphics Processing Unit) with a Focus on Nvidia GeForce 6 Series. By: Binesh Tuladhar Clay Smith

GPU Architecture. Michael Doggett ATI

The Evolution of Computer Graphics. SVP, Content & Technology, NVIDIA

OpenGL ES* Framework Software Developer s Guide

Real-Time Realistic Rendering. Michael Doggett Docent Department of Computer Science Lund university

Basic ios development

L20: GPU Architecture and Models

OpenGL & Delphi. Max Kleiner. 1/22

Touchstone -A Fresh Approach to Multimedia for the PC

GPGPU Computing. Yong Cao

Advanced Visual Effects with Direct3D

How To Use An Amd Graphics Card In Greece And (Amd) With Greege (Greege) With An Amd Greeper 2.2.

Introduction to Computer Graphics

Shadows. Shadows. Thanks to: Frédo Durand and Seth Teller MIT. Realism Depth cue

A Short Introduction to Computer Graphics

The OpenGL Framebuffer Object Extension. Simon Green. NVIDIA Corporation

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

CS 4204 Computer Graphics

Optimizing Unity Games for Mobile Platforms. Angelo Theodorou Software Engineer Unite 2013, 28 th -30 th August

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Introduction to Game Programming. Steven Osman

Overview Motivation and applications Challenges. Dynamic Volume Computation and Visualization on the GPU. GPU feature requests Conclusions

CSE 564: Visualization. GPU Programming (First Steps) GPU Generations. Klaus Mueller. Computer Science Department Stony Brook University

Advanced Rendering for Engineering & Styling

Dynamic Resolution Rendering

Lecture Notes, CEng 477

NVPRO-PIPELINE A RESEARCH RENDERING PIPELINE MARKUS TAVENRATH MATAVENRATH@NVIDIA.COM SENIOR DEVELOPER TECHNOLOGY ENGINEER, NVIDIA

How To Teach Computer Graphics

The OpenGL R Graphics System: A Specification (Version 3.3 (Core Profile) - March 11, 2010)

Optimizing AAA Games for Mobile Platforms

GPUs Under the Hood. Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology

NVFX : A NEW SCENE AND MATERIAL EFFECT FRAMEWORK FOR OPENGL AND DIRECTX. TRISTAN LORACH Senior Devtech Engineer SIGGRAPH 2013

Developer Tools. Tim Purcell NVIDIA

Deferred Shading & Screen Space Effects

Introduction to GPGPU. Tiziano Diamanti

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

QCD as a Video Game?

GPU Christmas Tree Rendering. Evan Hart

OpenGL Insights. Edited by. Patrick Cozzi and Christophe Riccio

Radeon HD 2900 and Geometry Generation. Michael Doggett

Modern Graphics Engine Design. Sim Dietrich NVIDIA Corporation

The Design of the OpenGL Graphics Interface

BCC Multi Stripe Wipe

SkillsUSA 2014 Contest Projects 3-D Visualization and Animation

A Crash Course on Programmable Graphics Hardware

NVIDIA workstation 3D graphics card upgrade options deliver productivity improvements and superior image quality

Computer Graphics Labs

How To Understand The Power Of Unity 3D (Pro) And The Power Behind It (Pro/Pro)

Intel Graphics Media Accelerator 900

GUI GRAPHICS AND USER INTERFACES. Welcome to GUI! Mechanics. Mihail Gaianu 26/02/2014 1

Making natural looking Volumetric Clouds In Blender 2.48a

DATA VISUALIZATION OF THE GRAPHICS PIPELINE: TRACKING STATE WITH THE STATEVIEWER

Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list

Programming 3D Applications with HTML5 and WebGL

Introduction GPU Hardware GPU Computing Today GPU Computing Example Outlook Summary. GPU Computing. Numerical Simulation - from Models to Software

3D Computer Games History and Technology

The Car Tutorial Part 1 Creating a Racing Game for Unity

Computer Graphics. Anders Hast

NVIDIA IndeX Enabling Interactive and Scalable Visualization for Large Data Marc Nienhaus, NVIDIA IndeX Engineering Manager and Chief Architect

3D Graphics and Cameras

Real-Time Graphics Architecture

Lecture 3: Coordinate Systems and Transformations

Performance Optimization and Debug Tools for mobile games with PlayCanvas

3D Viewing. Chapter 7. Projections. 3D clipping. OpenGL viewing functions and clipping planes

Beginning Android 4. Games Development. Mario Zechner. Robert Green

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

Low power GPUs a view from the industry. Edvard Sørgård

Advanced Graphics and Animations for ios Apps

Midgard GPU Architecture. October 2014

Workstation Applications for Windows. NVIDIA MAXtreme User s Guide

Course Overview. CSCI 480 Computer Graphics Lecture 1. Administrative Issues Modeling Animation Rendering OpenGL Programming [Angel Ch.

CUBE-MAP DATA STRUCTURE FOR INTERACTIVE GLOBAL ILLUMINATION COMPUTATION IN DYNAMIC DIFFUSE ENVIRONMENTS

Graphics Cards and Graphics Processing Units. Ben Johnstone Russ Martin November 15, 2011

Beyond 2D Monitor NVIDIA 3D Stereo

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

Nicolas P. Rougier PyConFr Conference 2014 Lyon, October 24 25

Using Photorealistic RenderMan for High-Quality Direct Volume Rendering

Realtime 3D Computer Graphics Virtual Reality

Radeon GPU Architecture and the Radeon 4800 series. Michael Doggett Graphics Architecture Group June 27, 2008

GPU Shading and Rendering: Introduction & Graphics Hardware

Working with the BCC Clouds Generator

3D Application and Game Development With OpenGL

Writing Applications for the GPU Using the RapidMind Development Platform

OpenGL Shading Language Course. Chapter 5 Appendix. By Jacobo Rodriguez Villar jacobo.rodriguez@typhoonlabs.com

Transcription:

Advanced OpenGL Computer Graphics COMP 770 (236) Spring 2007 Instructor: Brandon Lloyd 3/05/07 1

From last time Flexible shading shading networks shading languages GLSL language features interfacing shaders with the application 3/05/07 2

Topics for today Extensions Performance optimizations Display lists Triangle strips and fans Vertex arrays / vertex buffer objects Multipass rendering Render-to-texture Accumulation buffer Back end operations Scissor test, stencil test, alpha test, blending, etc. 3/05/07 3

OpenGL extensions OpenGL has a flexible extension mechanism Tokens an functions from extension have special suffixes _NV or _ATI - vendor specific _EXT - general extensions _ARB - approved by architecture review board ARB extensions are then folded into later versions of OpenGL. features from later versions are accessed through extension mechanism 3/05/07 4

GLEW The OpenGL Extension Wrangler (GLEW) hides details of initializing extensions http://glew.sourceforge.net/ glewinit(); if (GLEW_EXT_framebuffer_object) { /* It is safe to use the EXT_framebuffer_object extension here. */ } if (GLEW_VERSION_2_0) { /* It is safe to use version 2.0 functions. */ glattachshader(programid, codestr); } 3/05/07 5

Immediate mode versus display lists Immediate Mode Polynomial Evaluator Per Vertex Operations & Primitive Assembly CP Display List Rasterization Per Fragment Operations Frame Buffer Pixel Operations Texture Memory 3/05/07 6

Display lists Creating a display list def init(void): global id id = glgenlists( 1 ) glnewlist( id, GL_COMPILE ) # various OpenGL routines glendlist() glnewlist also accepts the constant GL_COMPILE_AND_EXECUTE, which both creates and executes a display list. If a new list is created with the same identifying number as an existing display list, the old list is replaced with the new calls. Call a created list def display(): glcalllist( id ) CPU CPU Poly. Poly. DL DL Pixel Pixel Per Per Vertex Vertex Texture Texture Raster Raster Frag Frag FB FB 3/05/07 7

An example cow = None def drawcow(color): global cow, cowid if (cow == None): cow = WaveFrontOBJ( cow.obj ) cowid = glgenlists(1) glnewlist(cowid, GL_COMPILE) glpushmatrix() glscaled(0.8,0.8,0.8) gltranslated(0,-cow.min.y,0) cow.draw() glpopmatrix() glendlist() glenable(gl_lighting) glmaterialfv(gl_front, GL_AMBIENT, color) glmaterialfv(gl_front, GL_DIFFUSE, color) glcalllist(cowid) def drawscene(): drawfloor() gltranslated(0,0,6) drawcow([0.6, 0.0, 0.8, 1.0]) gltranslated(0,0,6) drawcow([0.8, 0.6, 0.0, 1.0]) gltranslated(-12,0,-6) drawcow([0.0, 0.6, 0.8, 1.0])... 3/05/07 8

Display lists Not all OpenGL routines can be stored in display lists 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 can provide a significant speedups over immediate mode 3/05/07 9

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() 3/05/07 10

Efficient primitive representations Triangle strips and fans avoid specifying redundant vertex information Each triangle specified with about 1 vertex on average 12 Triangle Strip 8 10 3 4 2 4 6 11 Triangle Fan 1 5 1 3 5 7 9 2 9 8 7 6 3/05/07 11

Vertex arrays Vertex arrays allow for more efficient memory access Vertex arrays can specify a batch of vertices in a single call Indexed vertex arrays avoid specifying redundant vertex information Can specify vertex data in a wide variety of formats Vertex arrays can be stored on the GPU in Vertex Buffer Objects (VBOs) 3/05/07 12

OpenGL Vertex Arrays Specify locations of the vertex attribute arrays Enable the arrays and render Render with gldrawarrays or gldrawelements() glvertexpointer( 3, GL_FLOAT, 0, coords ) glcolorpointer( 4, GL_FLOAT, 0, colors ) glenableclientstate( GL_VERTEX_ARRAY ) glenableclientstate( GL_COLOR_ARRAY ) Processes each vertex sequentially Color data Vertex data gldrawarrays( GL_TRIANGLE_STRIP, 0, numverts ) -orgldrawelements( GL_TRIANGLE_STRIP, 20, GL_SHORT, indices ) Allows random access to vertices, thus supporting sharing 3/05/07 13

Multipass rendering Breaks up complex rendering into more than one rendering pass. Can combine passes into the frame buffer with blending Can use multiple passes to store results in textures that can be used in subsequent rendering passes Dynamic shadow maps Dynamic cube maps GPGPU 3/05/07 14

Render-to-texture glcopyteximage2d() copies the frame buffer to a texture but slow The Frame Buffer Object (FBO) extension allows rendering directly to a texture Allows you to attach textures to use as color and depth buffers Buffers have to be the same size Not all possible combinations are allowed Can also attach render buffers in place of textures Aaron Lefohn s FBO class provides encapsulation of details http://sourceforge.net/projects/gpgpu/ 3/05/07 15

Initializing an FBO // initialize textures glbindtexture( GL_TEXTURE_2D, colortexid );... set texture parameters... glteximage2d( GL_TEXTURE_2D, 0, GL_RGBA, fbow, fboh, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ); glbindtexture( GL_TEXTURE_2D, depthtexid );... set texture parameters... glteximage2d( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, fbow, fboh, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL ); // initialize fbo fbo = new FramebufferObject(); fbo->bind(); fbo->attachtexture( GL_TEXTURE_2D, colortexid, GL_COLOR0_ATTACHEMENT_EXT ); fbo->attachtexture( GL_TEXTURE_2D, depthtexid, GL_DEPTH_ATTACHMENT_EXT ); if(!fbo->isvalid() ) printf("fbo format not supported.\n" ); fbo->disable(); 3/05/07 16

Using an FBO fbo->bind(); glclearcolor(1,1,1,1); glclear( GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT ); // setup the viewing transformations... // draw a rotating wire torus float t = glutget( GLUT_ELAPSED_TIME ) / 1000.0; glrotatef( 20*t, 0, 1, 0 ); glrotatef( 10*t, 1, 0, 0 ); gllinewidth( 3 ); glcolor3f(0,0,0); glutwiretorus( 0.5, 1, 20, 20 ); gllinewidth( 1 ); fbo->disable(); 3/05/07 17

OpenGL accumulation buffer Problems of compositing into color buffers limited color resolution due to clamping and limited precision Accumulation buffer has higher precision accumulate multiple rendering passes into accumulation buffer transfer results to frame buffer Applications Explicit Do-it-yourself Compositing Full Scene Antialiasing Depth of Field Motion Blur Filtering 3/05/07 18

OpenGL accumulation buffer glaccum( op, value) Functions performed for various values of op: GL_LOAD AB = FB * value GL_ACCUM AB += FB * value GL_ADD AB += value GL_MUL AB *= value GL_RETURN FB = AB * value AB = accumulation buffer FB = frame buffer 3/05/07 19

Full Scene Antialiasing Each time we move the viewer, the image shifts Different aliasing artifacts in each image Averaging images using accumulation buffer averages out these artifacts 3/05/07 20

Full Scene Antialiasing samples = 4 for i in xrange(samples*samples): dx = ((i % samples) - 0.5*(samples-1))/float(samples) dy = ((i / samples) - 0.5*(samples-1))/float(samples) glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT) drawscene((dx,dy)) if (i == 0): glaccum(gl_load, 1/float(samples*samples)) else: glaccum(gl_accum, 1/float(samples*samples)) glaccum(gl_return, 1) def drawscene(dx,dy): glmatrixmode( GL_PROJECTION) glloadidentity() gltranslate( dx, dy ) glperspective( fov, aspect, znear, zfar)... 3/05/07 21

Full Scene Antialiasing 3/05/07 22

Depth of Field Jitter the viewpoint in such a way as to leave the focal plane unchanged accumulate each rendered view far plane near plane focal plane eye pos 1 eye pos 2 3/05/07 23

3/05/07 24 Getting to the framebuffer Blending Blending Depth Test Depth Test Dithering Dithering Logical Operations Logical Operations Scissor Test Scissor Test Stencil Test Stencil Test Alpha Test Alpha Test Fragmen Framebuffe CPU CPU DL DL Poly. Poly. Per Vertex Per Vertex Raster Raster Frag Frag FB FB Pixel Pixel Texture Texture

Scissor Test glscissor( x, y, w, h ) Additional clipping test any fragments outside of box are clipped useful for updating a small section of a viewport enable with glenable( GL_SCISSOR_TEST) Scissor Box Viewport 3/05/07 25

Alpha Test glalphafunc( func, value ) Reject pixels based on their alpha value Enable with glenable( GL_ALPHA_TEST ) use alpha as a mask in textures func can be one of the following: GL_NEVER GL_LESS GL_EQUAL GL_LEQUAL GL_GREATER GL_NOTEQUAL GL_GEQUAL GL_ALWAYS 3/05/07 26

Stencil Buffer Stencil buffer associates counter with each pixel updated depending on the result of the stencil and depth tests The stencil test rejects pixels based on the contents of the stencil buffer Lots of creative uses Irregular shaped rendering regions Screen-door transparency Counting the number of times a given pixel is touched (depth complexity) CSG operations (Intersection, and Difference) Shadows 3/05/07 27

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 GL_NEVER, GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL, GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS glstencilop( stencilfail, zfail, zpass ) Modify stencil buffer based on stencil and depth tests: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT 3/05/07 28

Creating a Mask Setup mask glenable( GL_STENCIL_TEST ); glclearstencil( 0x0); glstencilfunc( GL_ALWAYS, 0x1, 0x1 ); glstencilop( GL_REPLACE, GL_REPLACE, GL_REPLACE ); // draw mask draw objects where stencil!= 1 glstencilfunc( GL_EQUAL, 0x1, 0x1 ) // draw objects draw objects where stencil = 1 glstencilfunc( GL_NOT_EQUAL, 0x1, 0x1 ) glstencilop( GL_KEEP, GL_KEEP, GL_KEEP ) // draw objects 3/05/07 29

Alpha blending Combines fragment with contents of the frame buffer Uses simulate translucent objects - transparent objects must be rendered after opaque ones and in back to front order composite images antialiasing Enabled with glenable(gl_blend) alpha component ignored when blending disabled 3/05/07 30

Alpha Blending Modes glblendfunc( src, dst ) src and dst can be one of the following: GL_ONE GL_ZERO GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA C r = src C f + dst C p Fragment (src) Framebuffer Pixel (dst) Blending Equation Blended Pixel 3/05/07 31

Dithering Dither colors for better looking results Used to simulate more available colors Particularly when using 16-bit colors Often used by gamers to double bandwidth 24-bit 16-bit 16-bit dithered 3/05/07 32

Logical Operations on Pixels gllogicop( mode ) Combine pixels using *bitwise* logical operations Common modes - GL_XOR useful for rubber-banding style selection - GL_AND useful for masking off bits All 16 possible boolean functions of source and destination - GL_CLEAR GL_SET GL_COPY, - GL_COPY_INVERTED GL_NOOP GL_INVERT - GL_AND GL_NAND GL_OR - GL_NOR GL_XOR GL_AND_INVERTED - GL_AND_REVERSE GL_EQUIV GL_OR_REVERSE - GL_OR_INVERTED 3/05/07 33

Antialiasing glenable( mode ) - GL_POINT_SMOOTH - GL_LINE_SMOOTH - GL_POLYGON_SMOOTH alpha value determined by pre-computing sub-pixel coverage around object silhouettes available in both RGBA and colormap modes 3/05/07 34

Fog glfog[fvd]( 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 Other Properties GL_FOG_COLOR, GL_FOG_START, GL_FOG_END 3/05/07 35

Assignment #3 3/05/07 36

Next time Visibility computations 3/05/07 37