Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 19 of 42 William H. Hsu.

Slides:



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

MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Basics. OpenGL. “Hello world” George Georgiev Telerik Corporation
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
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.
CGDD 4003 THE MASSIVE FIELD OF COMPUTER GRAPHICS.
OpenGL (II). How to Draw a 3-D object on Screen?
02/04/03 Page 1 Rendering Visibility Lighting Texturing.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Hierarchical Transformations Hierarchical Models Scene Graphs
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
Introduction to 3D Computer Graphics and Virtual Reality McConnell text.
COMP 175: Computer Graphics March 10, 2015
3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!
CS 480/680 Computer Graphics Course Overview Dr. Frederick C Harris, Jr. Fall 2012.
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 6 of 41 William H. Hsu Department of Computing.
CSE 381 – Advanced Game Programming Basic 3D Graphics
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Week 2 - Wednesday CS361.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
Lecture 6: 3D graphics Concepts 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 
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.
Computer Graphics Bing-Yu Chen National Taiwan University.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Review of OpenGL Basics
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
10/7/04© University of Wisconsin, CS559 Fall 2004 Last Time Transformations Homogeneous coordinates Directions Rotation Geometry 101 – Points, edges, triangles/polygons.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
1 Perception and VR MONT 104S, Fall 2008 Lecture 20 Computer Graphics and VR.
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.
1 CSCE 441: Computer Graphics Hidden Surface Removal Jinxiang Chai.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL LAB III.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Introduction to Computer Graphics
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
- Introduction - Graphics Pipeline
School of Computer Science
Week 2 - Friday CS361.
CSCE 441 Computer Graphics 3-D Viewing
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Projection in 3-D Glenn G. Chappell
UMBC Graphics for Games
Presentation transcript:

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 19 of 42 William H. Hsu Department of Computing and Information Sciences, KSU KSOL course pages: Course web site: Instructor home page: Readings: Sections 4.4 – 4.6, Eberly 2 e – see Scene Graph Traversal

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics 3D Rendering in OpenGL David Blumenthal, SkyJuggler Consulting David Murray Anthony Magro 20 February 2006

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Looking at the Code Setup OpenGL State Geometry precomputation Frame Loop Drawing Code

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Draw Buffers The Front Buffer is what you see on screen – everything else is off-screen Draw to the back buffer, then call SwapBuffers Accumulation Buffer Stencil Buffer Depth Buffer Back Buffer Texture 1 Texture 2 Texture 3 Window decoration Front Buffer

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics OpenGL Coordinate Spaces Window Space Clipping Space Eye Space World Space Model Space Model vertices become window coordinates via a series of spaces and transformations

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Modeling Transformations Use any transformations you want to place model geometry in the “World” space. Window Space Clipping Space Eye Space World Space Model Space GL_MODELVIEW matrix Define Objects and Lights Hierarchical Modeling by nesting transforms  glPushMatrix  glPopMatrix Most common GL calls:  glTranslate  glRotate

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Order is Important glLoadIdentity() glRotated(45, 0, 0, 1) glTranslated(5, 0, 0) glLoadIdentity() glTranslated(5, 0, 0) glRotated(45, 0, 0, 1) OpenGL commands successively define new “local” coordinate spaces in terms of the “current” or previous local space.

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Viewing Transformation Window Space Clipping Space Eye Space World Space Model Space gluLookAt OpenGL doesn’t care about “World” space, it does all lighting, culling, etc. calculations in Eye Space. GL_MODELVIEW matrix Position the world in front of the camera. Define Objects and Lights which are relative to the viewpoint  Headlights  First Person objects

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Positioning the View Don’t position the camera in the world…  Position the world in front of the camera! Transform the world into “Eye Space”  The camera is at the origin  Looking down the negative Z axis  X points right, Y points up gluLookAt  Converts a world space camera into the correct rotation and translation Or, invert a camera position matrix Camera in world space World in eye space

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Projection Transformation Window Space Clipping Space Eye Space World Space Model Space glOrtho, glPerspective gluPerspective Transform the region to be displayed into the region of the Clipping Cube. The Clipping Cube:  -1 to 1 in X  -1 to 1 in Y  -1 to 1 in Z Everything outside that volume is clipped out. Use the GL_PROJECTION matrix

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Perspective Projection Eye spaceClip Space Items close to the camera get stretched The GL_PROJECTION matrix maps a region of eye space to the clipping space cube. glFrustum creates a non-linear mapping, yielding a perspective effect. Items far from the camera get squished

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Viewport Transformation Window Space Clipping Space Eye Space World Space Model Space glViewport and glDepthRange The Clipping Cube is mapped to the viewport bounds. [-1,1] in X is mapped to the left to right viewport range. [-1,1] in Y is mapped to the bottom to top viewport range. [-1,1] in Z is mapped to the near and far limits of the depth buffer range.

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics OpenGL Setup Create a Window and a GL Context (glut, SDL) Load Models, Textures, and Shaders  Load from files, or generate at runtime  Put static geometry into display lists or Vertex Buffer Objects  Put textures onto the card or in Pixel Buffer Objects Setup Lighting  Light positions may change, but light colors, ambient lighting, and other lighting parameters often don’t Setup any other static OpenGL state  Enable depth testing, antialiasing, backface culling Initialize the program and animation state

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Scene Graphs Organize all your models into a structure  Update the structure for animation  Iterate over the nodes to draw Create a base SG Node class  Manage tree structure (parent, children pointers)  Manage transforms and bounding boxes Subclass for different types of objects  Primitives which can generate their own geometry  Generic Mesh class for loaded geometry Lights and Cameras are special nodes  Need to be handled outside the normal traversal

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Scene Graphs (continued) Keep the actual geometry in a separate class  Contain the logic for managing display lists/VBOs  Allows reuse of geometry for multiple objects  Special logic for drawing at a reduced level of detail Keep the appearance in a separate class  Material parameters, texture and shader IDs  Be able to iterate over appearances, and find all the objects which use the same appearance  Special logic for drawing transparent surfaces Keep the behavior in a separate class  Behaviors often belong to an object, but are updated by a separate behavior manager

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Don’t Reinvent the Wheel Freely available math libraries:  Wild Magic ( Freely available image libraries:  libjpg  libpng Model formats and loading libraries:  Plenty of them out there if you search

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Performance Use the best vertex mechanism you can  Vertex Buffer Objects are the best because the data is in memory which the hardware can access  Vertex arrays are good – several extensions make them better  glVertex3fv is better than glVertex3f Don’t use glScale if you’re using lighting  Requires GL_NORMALIZE to be enabled Don’t use GL_POLYGON  It’s the same thing as GL_TRIANGLE_FAN, but may not be as well optimized

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Performance 2 Display Lists are making a comeback  They used to be for getting data across an XWindows socket.  Now, OpenGL drivers are taking advantage of them to optimize the way the hardware is used. Minimize draw calls  Group together objects which use the same textures, shaders, other material properties  Use a Unified Shader Model – write one shader which can produce several different visual effects  Group objects which are always drawn together into a display list

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Performance 3 Cull out objects which aren’t visible  Quick test: if the bounding box is behind the camera…  Better tests will take into account field of view, distance, occlusion (can’t see that room if you’re in this room), etc. Precompute lighting for static lights and models Avoid round trips, like glReadBuffer  Completely stalls the graphics hardware  New GL extensions help you avoid them  Render directly to a texture  Asynchronous reads using pixel buffer objects

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Performance 4 Use texture formats supported by the hardware  GL_BGRA Use pixel buffer objects to load textures quickly  If possible, keep all your textures on the card  If not, use PBOs so the card can directly read the texture data Measure! Measure! Measure!  You never know what change you’re going to make which will kick you off the fast path, or even worse, require software rendering…

Computing & Information Sciences Kansas State University Lecture 19 of 42CIS 636/736: (Introduction to) Computer Graphics Learning More The Red Book: The OpenGL Programming Guide  A good tutorial and guide to OpenGL  The OpenGL Specification  GL Extensions  Lots of papers about how to draw pretty pictures quickly UPL GameSIG  Come meet other students and join projects