82
COMP9018 - Advanced Graphics Welcome! Today: Administrative stuff. Introductory remarks. Voting on course arrangements. Basic graphics + OpenGL revision or curves & surfaces.

COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

  • View
    230

  • Download
    0

Embed Size (px)

Citation preview

Page 1: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

• Welcome!• Today:

– Administrative stuff.– Introductory remarks. – Voting on course arrangements.– Basic graphics + OpenGL revision or

curves & surfaces.

Page 2: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Administrivia• Web page:

– http://www.cse.unsw.edu.au/~cs9018– Includes a notice board + message

board.– Tim & I will read/contribute regularly. – Also lots of links and stuff.

Page 3: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Administrivia• People

– Waleed (that's me) ([email protected])– Tim (the smart guy)

([email protected])– Who to e-mail:

• Enrolments: waleed• Software problems: waleed• Web issues: waleed• Lecture material: whoever presented it• Tricky questions: lambert• Lecturer-in-charge/complex admin: lambert

Page 4: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Attitude to the course• Graphics is HUGE!• No one person can grasp all of it• Tim & I know stuff but we don't know

it all: guides rather than experts

Page 5: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Fourth year• This is a fourth year

subject/graduate subject• So rules are a little different.

– Smaller numbers = • more flexibility• higher standard (we hope)• more interactivity

Page 6: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Things we’d like you to do• Common sense:

– Doing the best you can in the subject– Respecting fellow students– Shutting up when you're not supposed to talk– Participating– Doing the preparation/homework we ask you to– Not cheating (we'll come down HARD on cheats)– Actually showing up to appointments/not

expecting us to be available all the time

Page 7: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Some basic rules• Questions allowed at any time ... but

raise your hands and wait for us to ask

• Open to suggestions• Academic etiquette: You’re allowed

to borrow or copy, but when you do, ACKNOWLEDGE it.

Page 8: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Anybody scared?• Can discontinue without failure until

end of week 4 (I think)

Page 9: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Run through handout• See handouts

Page 10: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Voting issues• Vote on lots of critical things• ... but you can't vote people out of

the course• Course isn't going to get smaller and

smaller as time goes on, 'til last person gets an HD

Page 11: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Issue 1• Language preference

– C/C++ vs Java– Any other bizarre languages? Fortran,

Perl, Python, Haskell?

• Examples in both? • Assignments: both allowed

Page 12: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Issue 2• Last time had a local games

company give a seminar/demo• Couldn’t organise film person; but

will try again this year … if you are interested

• Vote?

Page 13: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Issue 3• Syllabus material• Rough outline of what was covered

last time• Any topics from the list people feel

strongly about?• What to drop to include?

Page 14: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Week 13 demo night• Put it in your calendars• No lectures week 13• From 5pm to 10pm• Can bring in own equipment if you like• Do you guys want me to ask outsiders

(e.g. industry people) to attend?

Page 15: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Text

• Graphics has 2 properties:– Diverse – Fast-moving

• Generally means textbooks get out of date quickly

• The Net is a very good resource. • See links on Web page for online info.

Page 16: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

… but if you really want …• Textbooks

– Computer Graphics: Principles & Practice Brown et al. Known as “Old Testament”

– Advanced Animation & Rendering Techniques by Watt & Watt. Known as “New Testament”

– OpenGL Programming Guide by OpenGL ARB. Known as the “Red Book” or “Lego book”. Available online.

Page 17: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Labs• Have hardware acceleration (TNT2 cards

-- not great, but better than nothing)• Linux is official platform (not by choice,

really)• For compatibility: Only use standard Java

libraries + gl4java; for C/C++: standard libraries + OpenGL + GLU + GLUT + MUI ... must compile with gcc

• If you want something else, let us know.

Page 18: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Project possibilities• Write your own game• Write your own modeller• Extend an open source program with

some feature• Make a short CG movie• But be careful with your time

budget! Don’t want you to fail other subjects (almost happened last time)

Page 19: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Examples from last time• Some examples

– Movie scenes:• Lord of the Rings + modelling tools (4 ppl).• Story of a fly.

– Games:• 3D pool (2 ppl).• 3D tetris• 3D multiplayer networked robot/shooter/transfomer

game (2ppl).• Halflife level modelled on Ground & Basement of CSE. • Global thermonuclear war with Ronald Raygun,

Page 20: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

More examples– Interactive applications

• Origami tutor• CT-Scan lung visualiser• Photo-etching animation.• Artificial creatures lab• Lego modeller

– Screen savers:• Rollercoaster generator.• Rubik’s snake.

Page 21: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Special resources• Generally

– Increased disk quota (+ 20Mb)– Increased IP quota (+ 200Mb)– Trying to arrange special access to

bongo lab.

Page 22: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Project-specific• With access to bongo:

– 6 Maya floating licenses. – VirTools. – May be able to arrange other tools, but

may be difficult.

Page 23: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Special resources• Available on request• Good for the project• Two clusters:

– vina: 18 machines, 1x866MHz, 256MB RAM, Linux

– tines: 17 machines, 2x450MHz, 512MB RAM, Linux

Page 24: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Software available• GLUT 3.7• OpenInventor• POVRay• Blue Moon Rendering Tools

(RenderMan compatible, radiosity support)

• Java3D• Blender

Page 25: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Break time• After break, revision of basic

graphics + OpenGLor

• Get straight into curves and surfaces.

• Vote!!

Page 26: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Graphics Revision• What is graphics?• About anything computer generated

that you see:– In print– On a monitor– On television– At the movies– At art exhibitions

Page 27: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Usual representation• Most common representation of an

image is a bitmap: A 2D array of pixels

• Each pixel holds a description of the colour of that point

• The bitmap that holds the current image on display is called the frame buffer

Page 28: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Representing colour• Usual way is as a combination of red green

and blue; but monochrome is also possible• Different approaches:

– Fixed set of colours (e.g. CGA, EGA). Colour represented by a bit value

– Each pixel stores an index into an array of customisable colours (e.g. VGA) aka colour index mode

– Each pixel directly represents its colour directly (e.g. HighColor, TrueColor) aka RGB mode.

Page 29: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Objects• Primitive objects in graphics:

– Points: A single coordinate.– Lines: usually a parametric

representation (a + tb; 0 < t < 1) or a pair of coordinates.

– Polygons: A sequence of points. Usually talk of closed polygons (end is same as beginning)

Page 30: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Concave polygon Convex polygon

But first ... what is a polygon?

• Sequence of points enclosing a plane.

• In 3D, we use polygons that only have one face ... there is no "back" of a polygon.

• How do you decide which way a polygon is facing?

Page 31: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

A

B

C

D

Into the page

A

B

C

D

Out of the page

Using the normal• If not specified, use the right hand

rule.

Page 32: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Types of polygon• Nasty polygons:

– Non-planar: Not all vertices are in the same plane.

– Self-intersecting: Polygons that intersect themselves are problematic.

– Concave: Have internal angles greater than 180 degrees. Complicate lots of things.

• We'll assume we don't have any of these.

Page 33: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Transformations• Frequently want to represent "doing" things to

objects. Doing things = "transformations".• Many useful transformations can be

represented as matrices applied to vectors• Homogeneous matrices are used so that

translations can be represented as matrices.• Homogenous means 1 more dimension than

underlying space: 3x3 for 2D, 4x4 for 3D

Page 34: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Why homogenous?• Allows us to represent translations

as a matrix multiply -- making almost all interesting modelling transforms

Page 35: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Example transforms• Rotate about origin in 2D • Scale• Translate• Rotation about y axis in 3D?• Perspective • etc etc etc

Page 36: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Window to Viewport mapping

• Maps part of the 2D plane of interest onto the monitor

• Usually includes an inversion because monitors are upside down

• Except with OpenGL, which maintains a Cartesian representation

Page 37: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Clipping• Finding bits outside the screen• Why?

– Speed ... don't render what we don't need to render

– Avoid overwriting random bits of memory

Page 38: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Graphics pipelines - 2D• Start with description of 2D objects

(lines, points, polygon)• Apply transformations to position

them• Apply window-to-viewport mapping • Clip• Rasterise

Page 39: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

OpenGL• Provides a general platform

independent graphics API that's a rich but thin and efficient layer over the hardware.

• About 150 commands• For real-time 2D and 3D point, line

and polygon based rendering• Also does 3D lighting and texturing

Page 40: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

What OpenGL doesn't do• Doesn't deal with windows or I/O• Doesn't handle curves or curved

surfaces• Doesn't have a file format or handle

complicated objects - only points lines and polygons

• Doesn't create image files

Page 41: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Companion libraries to OpenGL

• GLU (GL utility): Does tesselation of curved surfaces, some more flexible projections, etc

• GLUT (GL utility toolkit): A platform-independent window and I/O system (also now includes MUI - micro user interface for menus, dials etc)

• WGL, GLX: Platform-specific window and I/O systems

• OpenInventor: Provides high-level scene graph libraries

Page 42: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

OpenGL and Java• Too slow to have an OpenGL

implementation in Java.• So usual technique: use a Java native

interface to OpenGL and provide a Java interface to it.

• We’ll be using GL4Java

Page 43: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Why not use Java3D?• Java3D is a high-level scene graph

library • More like OpenInventor than OpenGL• Java3D is implemented on top of

OpenGL!• Have a look at Java3D later• Grrr ...

Page 44: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

More about OpenGL• Funky thing about it: It's basically a

state machine - i.e. another computer• Most commands don't produce visible

output - they set up the state for what happens between glBegin and glEnd commands

• Interesting stuff happens between the glBegin and the glEnd

Page 45: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Open GL + C/Java• Anatomy of a simple OpenGL

program in C/GLUT - hello.c• ... from the OpenGL Programmer's

Guide• Java’s pretty much the same.

Page 46: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

The matrix stack• How OpenGL does transformations• A perfect fit for scene graph

traversal• How matrix stacks work

Page 47: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Basic operations• glMatrixMode(Mode)sets the matrix

stack we want to use. For now, only concerned with GL_MODELVIEW.

• glPushMatrix()copies current top of matrix stack and pushes on top of stack.

• glPopMatrix()pops off the top of the stack

• glLoadIdentity()loads identity matrix onto top of stack

Page 48: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

How matrix stack is used.• When you do glTranslatef(...)it

actually postmultiplies by the matrix on top of stack and puts it back on top of the stack.

• Means that last matrix op is done first.

Page 49: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Example - On blackboard• Initialise stack with

glMatrixMode(GL_MODELVIEW);glLoadIdentity();

• Scale by 2glScaled(1.0, 2.0, 1.0);

• Rotate around x by 90glRotated(90, 1, 0, 0);

• Push on stackglPushMatrix();

Page 50: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Example - cont'd• Translate by a

glTranslatef(a.x, a.y, a.z);• Draw a point on screen.

glBegin(GL_POINTS);glVertex3f(1,1,1);glEnd();would actually draw at S(2).R(90).Tr(a).(1,1,1)

• Pop off stackglPopMatrix();

Page 51: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

The scene graph• A representation of the scene

Page 52: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

World

Xwing1

R2D2 Pilot Torpedo

Left Arm Head

TIEFighter

Generalisation: A scene graph

• Can represent all objects in a scene as a graph Each node contains

geometry

Each edge storesa transformation

Page 53: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

World

Xwing1 Xwing2

R2D2 Pilot Torpedo

Left Arm Head

TIEFighter

Scene graph vs Scene tree• Previous was a scene tree. Can

easily generalise to scene graph, e.g.

Page 54: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Why is this cool?• Because it allows us to have libraries

of objects.• It's hierarchical, so we can have

objects within objects.• When we change the transform one

node in the scene graph, all its children move, too! Good for animation.

Page 55: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Example 2: Arm• Arm-> Forearm -> Hand -> Fingers• Transforming arm also moves

forearm, hands, fingers.• Transforming forearm also

transforms hands & fingers.

Page 56: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Scene graphs and the matrix stack

• Can use matrix stack for traversing the scene graph

• Algorithm:– Start at root node. Render this node's

geometry– For each child:

• Push the stack• Apply the modelling transform• Render the node (including children)• Pop the stack

Page 57: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

The scene graph• Why post multiply? • Because previous algorithm works

with it; and it represents the common case.

Page 58: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Viewing scene• Lots of pieces.• Projection (3D only)• Camera setting• Clipping• Visible surface determination (mostly

3D)• Window to viewport mapping

Page 59: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Projection• Two types:• Parallel: All objects are the same

size, regardless of distance• Perspective: Further away objects

are smaller• Both can be represented as matrices

Page 60: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Viewing• How set camera's position?• Lots of solid maths, but at end of the

day, you need:– A position for the camera (view

reference point)– A view-plane normal– An up vector

• Use this to construct the viewing matrix.

Page 61: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Clipping• 2D case is easy• 3D: Have to find the "view volume".

Area that can be seen. Also usually define a near and far plane.

• See demo viewvolpar.wrl and viewvolpersp.wrl

Page 62: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Visible surface determination

• Have to decide what goes in front of what.• Three common approaches in polygon

rendering:– Depth sorting– BSP Trees– Z Buffers

• Other approaches like raytracing handle it automatically.

Page 63: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

The OpenGL approach• Viewing transform: Goes on bottom

of modelview stack. • Projection & clipping combined -

essentially, a direct description of the view volume in camera coordinate system.

• Visible surface determination: do-it-yourself, or Z buffer.

Page 64: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

OpenGL Viewing Transform• gluLookat(eyex, eyey, eyez,

lookx, looky, lookz, upx, upy, upz)

• Eye position = VRP• VPN = eye -look• up = up• Remember: Goes at BOTTOM of

modelview stack• Think of it as an extra root node.

Page 65: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

View volume definition• Depends on projection.• Several functions for defining:• glOrtho

– parallel projection is also known as orthographic projection

– glOrtho(left, right, bottom, top, near, far)• glFrustum

– The truncated pyramid is called a frustum– glFrustum(left, right, bottom, top, near, far)

Page 66: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Where do they go?• A special stack for the projection

matrix called GL_PROJECTION. • Usually only two deep. • So usual code is

glMatrixMode(GL_PROJECTION)glLoadIdentity()glOrtho(...)

Page 67: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Convenience functions• GLU library has some convenient variants:• gluOrtho2D(left, right, bottom, top) =

glOrtho(left, right, bottom, top, -1, 1).• Proof: See Mesa source code. • gluPerspective(fovy, aspect, near, far)• Maths behind it: OpenGL source code.

Page 68: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

What do projections do?• The transform the view volume into

the canonical view volume.• Canonical = standard. • CVV is the standard cube.• Why? Easy to clip against; can be

done in hardware.

Page 69: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Window->Viewport• Window to viewport has its own matrix stack• glViewport(x, y, width, height)• WARNING: Viewport is not inverted as in java!• x, y are the lower left corners of the viewport

rectangle in pixels.• Note: in OpenGL, win->view does NOT kill the

z values; the z values are kept for the z buffer.

Page 70: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Z buffering• Set as part of the window

characteristics. • Handled by the windowing system;

e.g. GLUT or Java. • Called the depth buffer in OpenGL

terminology.• Must be cleared after every rendered

frame.

Page 71: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Lighting and shading• Different models.

– Ambient– Diffuse (uses Lambert's law)– Specular (includes diffuse component -

uses Phong illumination eqtn)

Page 72: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Different ways of rendering a scene

• Polygon rendering (like OpenGL)• Ray tracing (like POVRay)• Radiosity • Ray-trace/Radiosity hybrids (like

POVRay [experimental] and BMRT)• Polygon is the only realtime option

right now.

Page 73: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Polygon rendering ... cont'd

• Focus on polygon rendering for a while. • How to shade polygons?

– Flat shading: one normal per polygon, shade whole polygon one colour

– Gouraud shading: one normal per vertex (comes from model), interpolate colours between vertices

– Phong shading: one normal per vertex, interpolate normals between vertices

Page 74: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Light source and material• Lighting equations depend on:

– Light source intensities– Material properties

Page 75: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Light sources in OpenGL• glLightf(lightid,property,value)• All purpose lighting function• lightnum is the id of the light (GL_LIGHT0 to

GL_LIGHT7, but may be more). • Settable properties include:

– Light position (note! Modelview matrix applies!)– Diffuse intensity, ambient intensity, specular

intensity– Light attenuation with distance– Spotlight setting

Page 76: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Global properties• Global lighting is controlled by the

glLightModel() function• Properties include:

– Ambient light– Two-sided lighting– Local viewer

Page 77: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Material properties• glMaterial(face, property, value)• Applies to all subsequent values • face: front or back side of polygon• Properties:

– ambient, diffuse, specular and emissive colour components

– shininess (Phong exponent)

Page 78: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Other important functions• For polygons, must define normals.

So need glNormal() function• Just like material properties: normal

applies until you change it.

Page 79: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Texture mapping• Using images to add surface detail• Example: logopoly.wrl• Problem: How to "map" texture space to

polygon's surface.• Solution: Use texture coordinates for every

vertex and apply all that transformation stuff.

• More detail on texture mapping in Advanced OpenGL lecture.

Page 80: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Variants of texture mapping

• Procedural textures instead of images.• 3D vs 2D textures. • Using textures to model

– Surface perturbations: Bump map.– Reflections: Environment map.

• Textures are the "hot" area in graphics. Incredible number of nifty hacks possible using textures and variants.

Page 81: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Aliasing• Whenever we try to capture a high-

frequency (i.e. detail) reality with a low-frequency sample.

• Examples: Jaggies, texture collapse, etc.

• Approaches to fix: prefiltering, postfiltering, adaptive supersampling, jitter, mipmapping, bilinear interpolation, trilinear interpolation

Page 82: COMP9018 - Advanced Graphics Welcome! Today: –Administrative stuff. –Introductory remarks. –Voting on course arrangements. –Basic graphics + OpenGL revision

COMP9018 - Advanced Graphics

Brains full yet?• Good!• Want something interesting to read?• Subject Web page: Readings - 19

Pitfalls to avoid when programming OpenGL; by Mark Kilgard: Person who wrote GLUT, and a couple of other OpenGL books, now works at nVidia.