Introduction to OpenGL

Similar documents
3D graphic acceleration history and architecture

Hierarchical Models Josef Pelikán & Alexander Wilkie CGG MFF UK Praha

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

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

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

E.Order of Operations

Rendering Objects. Need to transform all geometry then

Rasterization Overview

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

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

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

Basic GPU techniques Josef Pelikán CGG MFF UK Praha.

Lecture 2. Shaders, GLSL and GPGPU

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

Graphics Pipeline & APIs

Introduction to Shaders.

Lecture 4 of 41. Lab 1a: OpenGL Basics

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Graphics Pipeline & APIs

Programming Graphics Hardware

Shaders. Slide credit to Prof. Zwicker

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

Rendering. Part 1 An introduction to OpenGL

Spring 2009 Prof. Hyesoon Kim

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

CS451Real-time Rendering Pipeline

Models and Architectures

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

Graphics Hardware. Instructor Stephen J. Guy

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

Lecture outline. COMP30019 Graphics and Interaction Rendering pipeline & object modelling. Introduction to modelling

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

OpenGL. Toolkits.

CS 354R: Computer Game Technology

CHAPTER 1 Graphics Systems and Models 3

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

Introduction to the OpenGL Shading Language

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

The Application Stage. The Game Loop, Resource Management and Renderer Design

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

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

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

Introduction to Computer Graphics with WebGL

Graphics and Interaction Rendering pipeline & object modelling

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Grafica Computazionale: Lezione 30. Grafica Computazionale. Hiding complexity... ;) Introduction to OpenGL. lezione30 Introduction to OpenGL

Three Main Themes of Computer Graphics

Advanced Computer Graphics

CSC 8470 Computer Graphics. What is Computer Graphics?

Programmable Graphics Hardware

CS427 Multicore Architecture and Parallel Computing

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

CS130 : Computer Graphics Lecture 2: Graphics Pipeline. Tamar Shinar Computer Science & Engineering UC Riverside

Pipeline Operations. CS 4620 Lecture 14

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

Spring 2011 Prof. Hyesoon Kim

CS 428: Fall Introduction to. OpenGL primer. Andrew Nealen, Rutgers, /13/2010 1

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

Transforms 3: Projection Christian Miller CS Fall 2011

Graphics Processing Unit Architecture (GPU Arch)

The Rasterization Pipeline

COMP 371/4 Computer Graphics Week 1

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

2D Drawing Primitives

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

We assume that you are familiar with the following:

Ciril Bohak. - INTRODUCTION TO WEBGL

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

- Location: Annenberg Text: Mostly Self-Contained on course Web pages. - Al Barr

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

Graphics Hardware. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 2/26/07 1

Graphics Hardware. Graphics Processing Unit (GPU) is a Subsidiary hardware. With massively multi-threaded many-core. Dedicated to 2D and 3D graphics

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

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

The Ultimate Developers Toolkit. Jonathan Zarge Dan Ginsburg

Evolution of GPUs Chris Seitz

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

Graphics Performance Optimisation. John Spitzer Director of European Developer Technology

CSE 167: Introduction to Computer Graphics Lecture #5: Illumination Model

Pipeline Operations. CS 4620 Lecture 10

Beginning Direct3D Game Programming: 1. The History of Direct3D Graphics

Computer Graphics 10 - Shadows

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

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

The Rendering Pipeline (1)

Sung-Eui Yoon ( 윤성의 )

The Graphics Pipeline

CS 130 Final. Fall 2015

GPGPU. Peter Laurens 1st-year PhD Student, NSC

CENG 477 Introduction to Computer Graphics. Graphics Hardware and OpenGL

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

CIS 536/636 Introduction to Computer Graphics. Kansas State University. CIS 536/636 Introduction to Computer Graphics

Transcription:

Introduction to OpenGL 1995-2015 Josef Pelikán & Alexander Wilkie CGG MFF UK Praha pepca@cgg.mff.cuni.cz http://cgg.mff.cuni.cz/~pepca/ 1 / 31

Advances in Hardware 3D acceleration is a common feature in consumer devices Focus on games, multimedia Appearance quality of results Sophisticated texturing functionality Combinations of many textures and processing High performance The best semi-conductor technology is used for GPUs (NVIDIA Kepler: 28 nm), massive parallelism Very fast memory (multipath access, GDDR5,..) High performance bus between GPU and CPU (PCI-E) 2 / 31

Advances in Software Two main libraries/apis for 3D graphics OpenGL (SGI, open standard) and Direct3D (Microsoft) Approach is similar, API is hardware-determined Efficient transmission of data to the GPU Maximal use of shared data fields Programmable shaders! Revolution in graphics programming vertex-shader : mesh vertex processing geometry/tesselation-sh. : generating geometry fragment-shader ( pixel-shader ): executed for each pixel that is displayed 3 / 31

Development Tools Can be used by programmers and artists Higher languages for GPU programming Cg (NVIDIA), HLSL (DirectX), GLSL (OpenGL) Cg and HLSL are very similar Composition of graphical effects Compact description of the entire effect (GPU programs, references to data) in one file DirectX.FX format, NVIDIA CgFX format Tools: Effect Browser (Microsoft), FX Composer (NVIDIA), RenderMonkey (ATI) 4 / 31

OpenGL Schematics (FFP) OpenGL Fixed Functionality Pipeline: Geom. Per-Vertex Operations Vertices Primitive Assembly Clip Project Viewport Cull Geom. Rasterize Fragment Processing Fragments Per-Fragment Operations App Memory Pixel Unpack Pixel Transfer Pixels Textures Texture Memory Frame Buffer Operations Pixels Pixel Pack Pixel Groups Read Control Frame Buffer 5 / 31

OpenGL: Geometric Primitives Types of geometric primitives: point, line, polyline, loop polygon, triangle, triangle strip, triangle fan, quad, quad strip Processing of individual vertices glvertex, glcolor, glnormal, gltexcoord,... inefficient (many calls to gl* functions) Vertex Arrays gldrawarrays, glmultidrawarrays, gldrawelements,... glcolorpointer, glvertexpointer,... or interlaced 6 / 31

Geometric Primitives I GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP V 0 V 1 V 0 V 1 V 0 V 1 V 0 V 1 V 2 V 2 V 2 V 2 V 3 V 3 V 3 V 3 V 4 V 4 V 4 V 4 V 5 V 5 V 5 V 5 7 / 31

Geometric Primitives II GL_TRIANGLE S GL_TRIANGLE_STRIP GL_TRIANGLE_FAN V 0 V 1 V 0 V 1 V 6 V 5 V 4 V 2 V3 V 2 V3 V 0 V3 V 4 V 5 V 2 V 5 V 4 V 1 8 / 31

Geometric Primitives III GL_QUADS GL_QUAD_STRIP GL_POLYGON V 0 V 3 V 1 V 0 V 6 V 5 V 4 V 1 V 2 V 3 V 2 V 3 V 4 V 7 V 5 V 4 V 0 V 2 V 6 V 6 V 1 V 5 V 7 9 / 31

OpenGL macros (Display Lists) DISPLAY_LIST_MODE instead of IMMEDIATE_MODE Storage of a sequence of GL commands in memory: glnewlist, glendlist The list can be pushed to the server (graphical HW) Basic idea: list = macro Execution of entire lists glcalllist, glcalllists Potentially very efficient (the commands can be optimised by the graphics server) 10 / 31

Coordinate Systems Model coordinates (Object space) [x,y,z,w] Modeling transform World space -z Camera coordinates (Eye space) -z View transform Projection transform Clip space xy xy n f [x,y,z,w] -z xy -z xy 11 / 31

Coordinate Systems II Clip space Perspective divide Normalized device space [x,y,z,w] [x,y,z] Viewport transform -z Window space [x,y,z] xy OpenGL: [-1,-1,-1] to [1,1,1] DirectX: [-1,-1, 0] to [1,1,1] [x,y] z actual fragment size on screen depth compatible with the z buffer 12 / 31

Coordinate Systems III Model coordinates Database of objects that comprise the scene Source: 3D modeling applications (3DS, Maya,..) World coordinates Absolute coordinates of the 3D world The relative coordinates of object instances are given there Camera coordinates 3D world relative camera coordinates Projection center: origin, view direction: -z (or z) 13 / 31

Coordinate transforms Model camera transforms Combined transformation modelview World coordinates are not directly used Projection transformation Defining the view frustum [ l, r, b, t, n, f ] Near and far clipping plane: n, f Result in homogeneous coordinates (before clipping) Clip space Output coordinates of vertex shaders! 14 / 31

Projective Transformation The remote point f can be moved to infinity [ ] ] 2n 2n 0 0 0 0 0 0 r l r l 2n 0 0 0 2n t b 0 0 0 r l t b t b f n 1 r l t b f n r l t b 1 1 0 0 2fn r l t b 0 f n 0 0 2n 0 xy [ n f -z 15 / 31

Coordinate Transformations Perspective division/clip Transforms homogeneous coordinates to cartesian Normalised Device Coordinates ( NDC ) Unit sized cube OpenGL: [-1,-1,-1] to [1,1,1] DirectX: [-1,-1,0] to [1,1,1] Window coordinates ( window space ) Result of screen and depth transformation Used during rasterisation and when working with fragments 16 / 31

Rigid Body Transformations Retain shape, only change orientation Only consists of translation and rotation Often used for coordinate system transforms (e.g. world coordinates, and viewer coordinates) z v (view) u (up) r (right) y (left handed = right winding system) x 17 / 31

Transformation Between Systems z u O s x y t [1, 0, 0 ] M stu xyz = s [0, 1, 0 ] M stu xyz = t [0, 0, 1 ] M stu xyz = u A coordinate system has its origin in O and is given by three basis vectors [ s, t, u ] [ M stu xyz = M xyz stu s x s y s z t x t y t z u x u y u z] T = M stu xyz 18 / 31

Geometric Data on the Server VBO, VAO, starting with OpenGL 1.5 For.NET practically a requirement (client memory is not fixed) The buffers on the graphics server contain geometric data Buffer creation: glbindbuffer Data entry: glbufferdata, glbuffersubdata Mapping to application memory: glmapbuffer, glunmap.. Work with client memory or with buffers glcolorpointer, glnormalpointer, glvertexpointer,... 19 / 31

Vertex Processing Vertex transformations via model and perspective matrices glmatrixmode glloadidentity, glloadmatrix, glmultmatrix glrotate, glscale, gltranslate,... Lighting attributes gllight, gllightmodel, glmaterial 20 / 31

Assembly and Processing Assembly Determination which vertices a primitive needs Assembly of data packages and uploading Processing of primitives Clipping Projection to view frustum removal of w Projection and clipping to 2D viewport Back face culling - Single vs. double sided primitives 21 / 31

Rasterisation, Fragments Rasterisation = display of vector primitives Decomposition of objects into fragments Objects: points, lines triangles, bitmaps Fragments Raster element, that potentially contributes to the colour of a pixel Size: pixel size, or smaller (anti-aliasing) Data packing in the raster unit of the GPU: - In/Output: x, y, z (depth can be changed!) - Texture coordinates t 0 to t n - Specular and diffuse colour, fog, user data,... - Output colour in RGB and α (frame-buffer op.) 22 / 31

Fragment Interpolation Fragment attributes are automatically interpolated between vertex values for: depth (z or w) Texture coordinates Colour (specular and diffuse) User data,... Fast HW interpolators Perspectivically correct interpolation Only [ x, y ] change linearly Other variables require one division for each fragment 23 / 31

Fragment Processing Texture operations Highly optimised operations Colour selection from texture memory Texel interpolation: - mip-mapping, anisotropic filtering,... Texture combination (many operations possible) Specialised effects (bump-mapping, environment mapping) Calculation of fog Based on depth z Combination of several colours (diff., spec.) 24 / 31

Raster Images in OpenGL Geom. Per-Vertex Operations Vertices Primitive Assembly Clip Project Viewport Cull Geom. Rasterize Fragment Processing Fragments Per-Fragment Operations App Memory Pixel Unpack Pixel Transfer Pixels Textures Texture Memory Frame Buffer Operations Pixels Pixel Pack Pixel Groups Read Control Frame Buffer 25 / 31

OpenGL Programmable Pipeline Texture Memory Geom. App Memory Vertex Processor Vertices Pixel Unpack Primitive Assembly Pixel Transfer Clip Project Viewport Cull Geom. Rasterize Pixels Textures Fragment Processor Fragments Per-Fragment Operations Frame Buffer Operations Pixels Pixel Pack Pixel Groups Read Control Frame Buffer 26 / 31

Vertex Processor Replaces the vertex processing module: Transformation of vertices Transformation/normalisation of normal vectors Calculation of texture coordinates Calculation of lighting vectors Definition of material constants for vertices What cannot be modified: The number of vertices! (no delete/add) Type & topology of geometric primitives - Partial solution: degenerate primitives 27 / 31

Geometric Processor Tesselation shaders New in OpenGL 4.0 HW support for subdivision surfaces (spline sheets,...) Two shaders: tesselation control and tesselation evaluation The first defines topology, the second generates geometry (coefficients) Geometry shader From OpenGL 3.0 onwards Just before the rasterisation unit Possibility to generate/delete primitives and vertices More powerful than TS, but slower (not easy to incude in schematics) 28 / 31

Fragment Processor Replaces the module for fragment processing: Arithmetic operations with interpolation Reading of data and textures Texture generation Fog calculations Computation of the final colour of the fragment colour Possibility to modify fragment depth What cannot be modified: Number of fragments! (no addition or deletion) Fragment position on screen [x,y] 29 / 31

GPU Programming Vertex shader Code for the vertex processor Fragment shader Code for the fragment processors Both can be programmed by the user! HW independent programming languages GPU micro-code compiled at run-time (hard to work with: many versions, specific to individual cards) Low-level instructions (similar to assembler) or higher languages Cg, HLSL, GLSL 30 / 31

Literature Tomas Akenine-Möller, Eric Haines: Real-time rendering, 2 nd edition, A K Peters, 2002, ISBN: 1568811829 OpenGL ARB: OpenGL Programming Guide, 4 th edition, Addison-Wesley, 2004, ISBN: 0321173481 Randima Fernando, Mark J. Kilgard: The Cg Tutorial, Addison-Wesley, 2003, ISBN: 0321194969 Jack Hoxley: An Overview of Microsoft's Direct3D 10 API, 13.12.2005, www.gamedev.net 31 / 31