Advanced Graphics – Lecture One

Slides:



Advertisements
Similar presentations
Real-Time Rendering 靜宜大學資工研究所 蔡奇偉副教授 2010©.
Advertisements

CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Advanced Graphics OpenGL Alex Benton, University of Cambridge – Supported in part by Google UK, Ltd.
3D Graphics Rendering and Terrain Modeling
Basics. OpenGL. “Hello world” George Georgiev Telerik Corporation
CS 468 OpenGL Jon Moon Spring 2004 Computer Science Cornell University.
CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t.
HCI 530 : Seminar (HCI) Damian Schofield.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
CGDD 4003 THE MASSIVE FIELD OF COMPUTER GRAPHICS.
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
The Graphics Pipeline CS2150 Anthony Jones. Introduction What is this lecture about? – The graphics pipeline as a whole – With examples from the video.
Game Engine Design ITCS 4010/5010 Spring 2006 Kalpathi Subramanian Department of Computer Science UNC Charlotte.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
Objectives Review some advanced topics, including Review some advanced topics, including Chapter 8: Implementation Chapter 8: Implementation Chapter 9:
CS 480/680 Computer Graphics Course Overview Dr. Frederick C Harris, Jr. Fall 2012.
UniS CS297 Graphics with Java and OpenGL Viewing, the model view matrix.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Graphical Objects and Scene Graphs 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Week 2 - Wednesday CS361.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Computer Graphics An Introduction. What’s this course all about? 06/10/2015 Lecture 1 2 We will cover… Graphics programming and algorithms Graphics data.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
Transforms Hierarchical Modeling Scene Graphs Using hierarchical modeling techniques in 3D software design Transforms Local basis Matrix math review Matrices.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 14 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 14 Going-through.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 19 of 42 William H. Hsu.
The Rendering Pipeline CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
2008/9/24 Kim, HyungSeok. HyungSeok Kim, Konkuk University Part I: Framework – 1. Windows creation – 2. Renderer – 3. Lights and Objects/Model loading.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Implementation II.
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Projective Transformations.
David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Computer Graphics I, Fall 2010 Implementation II.
Graphical Objects and Scene Graphs Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
Computer Graphics One of the central components of three-dimensional graphics has been a basic system that renders objects represented by a set of polygons.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Modeling Transformations Mario Costa Sousa University of Calgary CPSC 453, Fall 2001 Mario Costa Sousa University of Calgary CPSC 453, Fall 2001.
Applications and Rendering pipeline
Graphics Pipeline Bringing it all together. Implementation The goal of computer graphics is to take the data out of computer memory and put it up on the.
Introduction to Computer Graphics
- Introduction - Graphics Pipeline
3D Graphics Rendering PPT By Ricardo Veguilla.
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Lecture 13 Clipping & Scan Conversion
Introduction to Computer Graphics
Geometric Objects and Transformations (II)
CS297 Graphics with Java and OpenGL
Presentation transcript:

Advanced Graphics – Lecture One 3D Graphics and Computational Geometry Alex Benton, University of Cambridge – A.Benton@damtp.cam.ac.uk Supported in part by Google UK, Ltd

Applications of 3D Graphics (a) “Wall-E”, Pixar, 2008 (b) Image from CSB Biomolecular Visualization Workshop, Vanderbilt University, Oct 2007 (c) Two stages of an Invisalign treatment, Align Technology (d) Google Earth (e) World of Warcraft, from South Park 1008 “Make Love not Warcraft”

From model to image Mathematics Modeling Geometry 3D scanning . . . Rendering Pipeline (b) 3D Studio Max, by Autodesk, from oman3d.com (c) 3D scanning project by IBM (d) scanned output image (IBM)

Today’s technologies Java C++ OpenGL DirectX/Direct3d Java3D Common, re-usable language; extremely well-designed Steadily increasing popularity in industry Weak but evolving 3D support C++ Long-established language Long history with OpenGL Technically C has the long history. C++ never really improved it. Long history with DirectX Losing popularity in some fields (finance, web) but still strong in others (games, medical) OpenGL Open source with many implementations Extraordinarily well-designed, old, but still evolving Fairly cross-platform DirectX/Direct3d Less well-designed Microsoft™ only DX 10 requires Vista! But! Dependable updates… Java3D Poor cross-platform support (surprisingly!) Available by GPL; community-developed

OpenGL OpenGL is… OpenGL is a state-based renderer hardware-independent operating system independent vendor neutral OpenGL is a state-based renderer set up the state, then pass in data: data is modified by existing state very different from the OOP model, where data would carry its own state

OpenGL OpenGL is platform-independent, but implementations are platform-specific and often rely on the presence of native libraries Great support for Windows, Mac, linux, etc Support for mobile devices with OpenGL-ES Including Google Android! Accelerates common 3D graphics operations Clipping (for primitives) Hidden-surface removal (Z-buffering) Texturing, alpha blending (transparency) NURBS and other advanced primitives (GLUT)

OpenGL in Java: JOGL JOGL is the Java binding for OpenGL. Using JOGL: JOGL apps can be deployed as applications or as applets. This means that you can embed 3D in a web page. (If the user has installed the latest Java, of course.) Admittedly, applets are somewhat “1998”. Using JOGL: You can download JOGL from https://jogl.dev.java.net/ (choose the “current release build” link) In win32: You’ll want to add the contents of the .zip to your CLASSPATH and PATH system vars In eclipse: In Project->Properties->Java Build Path->Libraries, add jogl.jar and gluegen-rt.jar. To deploy an embedded applet, you’ll use Sun’s JNLP wrappers, which provide signed applets wrapped around native JOGL binaries.

A quick intro to JOGL: Hello Square public class HelloSquare { public static void main(String[] args) { new Thread() { public void run() { Frame frame = new Frame("Hello Square"); GLCanvas canvas = new GLCanvas(); // Setup GL canvas frame.add(canvas); canvas.addGLEventListener(new Renderer()); // Setup AWT frame frame.setSize(400, 400); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.setVisible(true); // Render loop while(true) { canvas.display(); }.start(); public class Renderer implements GLEventListener { public void init(GLAutoDrawable glDrawable) { final GL gl = glDrawable.getGL(); gl.glClearColor(0.2f, 0.4f, 0.6f, 0.0f); } public void display(GLAutoDrawable glDrawable) { gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0, 0, -5); gl.glBegin(GL.GL_QUADS); gl.glVertex3f(-1, -1, 0); gl.glVertex3f( 1, -1, 0); gl.glVertex3f( 1, 1, 0); gl.glVertex3f(-1, 1, 0); gl.glEnd(); public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) { final GL gl = gLDrawable.getGL(); final float h = (float)width / (float)height; gl.glMatrixMode(GL.GL_PROJECTION); (new GLU()).gluPerspective(50, h, 1, 1000); gl.glMatrixMode(GL.GL_MODELVIEW);

Jazzing up the square public void vertex(GL gl, float x, float y, float z) { gl.glColor3f( (x+1)/2.0f, (y+1)/2.0f, (z+1)/2.0f); gl.glVertex3f(x, y, z); } public void sphere(GL gl, double u, double v) { vertex(gl, cos(u)*cos(v), sin(u)*cos(v), sin(v)); } //... for (double u = 0; u <= 2*PI; u += 0.1) { for (double v = 0; v <= PI; v += 0.1) { sphere(gl, u, v); sphere(gl, u+0.1, v); sphere(gl, u+0.1, v+0.1); sphere(gl, u, v+0.1); 1) Shaded square 2) Parametric sphere

Animating a parametric surface What was that opening animation all about? The animation at right shows the linear interpolation between four parametric surface functions. Colors are by XYZ. The code is available, and pretty simple!

Behind the scenes Two players: The CPU, your processor and friend The GPU (Graphical Processing Unit) or equivalent software The CPU passes streams of vertices and of data to the GPU. The GPU processes the vertices according to the state that has been set; here, that state is “every four vertices is one quadrilateral polygon”. The GPU takes in streams of vertices, colors, texture coordinates and other data; constructs polygons and other primitives; then draws the primitives to the screen pixel-by-pixel. This process is called the rendering pipeline. gl.glBegin(GL.GL_QUADS); gl.glVertex3f(-1, -1, 0); gl.glVertex3f( 1, -1, 0); gl.glVertex3f( 1, 1, 0); gl.glVertex3f(-1, 1, 0); gl.glEnd();

Anatomy of a rendering pipeline 1) Geometry is defined in local space. The vertices and coordinates of a surface are specified relative to a local basis and origin. This encourages re-use and replication of geometry; it also saves the tedious math of storing rotations and other transformations within the vertices of the shape itself. This means that changing the position of a highly complex object requires only changing a 4x4 matrix instead of recalculating all vertex values. Local space World space Viewing space 3D screen space 2D display space

Anatomy of a rendering pipeline 2) The pipeline transforms vertices and surface normals from local to world space. A series of matrices are concatenated together to form the single transformation which is applied to each vertex. The rendering engine (e.g., OpenGL) is responsible for associating the state that transforms each group of vertices with the actual vertex values themselves. Local space World space Viewing space 3D screen space 2D display space

Anatomy of a rendering pipeline 3) Rotate and translate the geometry from world space to viewing or camera space. At this stage, all vertices are positioned relative to the point of view of the camera. (The world really does revolve around you!) For example, a cube at (10,000, 0, 0) viewed from a camera (9,999, 0, 0) would now have relative position (1, 0, 0). Rotations would have similar effect. This makes operations such as clipping and hidden-object removal much faster. Local space World space Viewing space 3D screen space 2D display space

Anatomy of a rendering pipeline 4) Perspective: Transform the viewing frustrum into an axis-aligned box with the near clip plane at z=0 and the far clip plane at z=1. Coordinates are now in 3D screen space. This transformation is not affine: angles will distort and scales change. Hidden-surface removal can be accelerated here by clipping objects and primitives against the viewing frustrum. Depending on implementation this clipping could be before transformation or after or both. Local space World space Viewing space 3D screen space 2D display space

Anatomy of a rendering pipeline 5) Collapse the box to a plane. Rasterize primitives using Z-axis information for depth-sorting and hidden-surface-removal. Clip primitives to the screen. Scale raster image to the final raster buffer and rasterize primitives. Local space World space Viewing space 3D screen space 2D display space

Overview of a rendering pipeline Scene composition Viewing frame definition Lighting definition Object definition W2V L2W Local space World space Backface culling Viewing frustum culling HUD definition Viewing space P’ = S2D • V2S • W2V • L2W • PL 3D screen space Display space Hidden-surface removal Scan conversion Shading V2S Image S2D

Transforms you may recognize Translation 1 0 0 x 0 1 0 y 0 0 1 z 0 0 0 1 Rotation by t around Y cos(t) 0 sin(t) 0 0 1 0 0 -sin(t) 0 cos(t) 0 0 0 0 1 Scaling x 0 0 0 0 y 0 0 0 0 z 0 0 0 0 1 Perspective d/h 0 0 0 0 d/h 0 0 0 0 f/(f-d) –df/(f-d) 0 0 1 0 (Watt, pp.149—153)

Why were they 4x4? We do all this in homogeneous coordinates. Why? [X, Y, Z, W] H → [X/W, Y/W, Z/W] [A, B, C] → [A, B, C, 1]H Why? Translation 1 0 0 x a a+x 0 1 0 y b = b+y 0 0 1 z c c+z 0 0 0 1 1 1 Perspective – yields X/Z, Y/Z. (Try it!)

OpenGL’s matrix stacks Recall: matrix multiplication is associative but not commutative. ABC = A(BC) = (AB)C ≠ ACB ≠ BCA Pre-multiplying matrices that will be used more than once is faster than multiplying many matrices every time you render a primitive. OpenGL uses matrix stacks to store stacks of matrices, where the topmost matrix is (generally) the product of all matrices below. This allows you to build a local frame of reference— local space—and apply transforms within that space. ABC AB A

Scene graphs and matrix stacks Matrix stacks are designed for nested relative transforms. glPushMatrix(); glTranslatef(0,0,-5); glRotatef(45,0,1,0); renderSquare(); glPopMatrix(); glRotatef(-45,0,1,0); T • R1 T • R2 T T T T identity identity identity identity … Send primitives

The scene graph A scene graph is a tree of scene elements where a child’s transform is relative to its parent. The final transform of the child is the ordered product of all of its ancestors in the tree. OpenGL’s matrix stack and depth-first traversal of your scene graph: two great tastes that go great together! Person Torso … Arm Arm Leg … Hand … … Finger MfingerToWorld = (Mperson • Mtorso • Marm • Mhand • Mfinger)

Your scene graph and you A common optimization derived from the scene graph is the propagation of bounding volumes. These take many forms: bounding spheres, axis-aligned bounding boxes, oriented bounding boxes… Nested bounding volumes allow the rapid culling of large portions of geometry Test against the bounding volume of the top of the scene graph and then work down. Great for… Collision detection between scene elements Culling before rendering Accelerating ray-tracing

Your scene graph and you Many 2D GUIs today favor an event model in which events ‘bubble up’ from child windows to parents. This is sometimes mirrored in a scene graph. Ex: a child changes size, which changes the size of the parent’s bounding box Ex: the user drags a movable control in the scene, triggering an update event If you do choose this approach, consider using the model/ view/ controller design pattern. 3D geometry objects are good for displaying data but they are not the proper place for control logic. For example, the class that stores the geometry of the rocket should not be the same class that stores the logic that moves the rocket. Always separate logic from representation.

A possible scene graph object class Pt { float x, y, z; } class Face { Pt[] verts; Pt normal; class SceneObject { SceneObject parent; List<SceneObject> children; Matrix4x4 transform; Face[] faces; } Assumes flat or Gouraud shading 4x4 matrix: arbitrary sequences of affine transforms Are floats enough? List instead of array: planning on many dynamic updates? Array instead of list: planning on loading all data up front?

Polygon data structures When designing your data structures, consider interactions and interrogations. If you’re going to move vertices, you’ll need to update faces. If you’re going to render with crease angles, you’ll need to track edges. If you want to be able to calculate vertex normals or curvature, your vertices will have to know about surrounding faces. Is memory a factor? What about the processing overhead of dereferencing a pointer or array?

Improving the sample scene object Vertex order matters Usually anticlockwise about the face normal Could store normal at the vertex Phong shading Vertices could track faces Could introduce edges, tracking vertices and faces together Could store color at the face or at the vertex; depends on lighting model Same for other material traits (shading, bump maps, …) Texture data has to be at the vertices A “winged edge” data structure

Hierarchical modeling in action void renderLevel(GL gl, int level, float t) { gl.glPushMatrix(); gl.glRotatef(t, 0, 1, 0); renderSphere(gl); if (level > 0) { gl.glScalef(0.75f, 0.75f, 0.75f); gl.glTranslatef(1, -0.75f, 0); renderLevel(gl, level-1, t); gl.glPopMatrix(); gl.glTranslatef(-1, -0.75f, 0); }

Hierarchical modeling in action

Recommended reading The OpenGL Programming Guide Some folks also favor The OpenGL Superbible for code samples and demos There’s also an OpenGL-ES reference, same series The Graphics Gems series by Glassner et al All the maths you’ve already forgotten The NeonHelium online OpenGL tutorials http://nehe.gamedev.net/