buffers textures and more rendering paul taylor & barry la trobe university 2009

28
Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Upload: buddy-little

Post on 12-Jan-2016

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Buffers Textures and more Rendering

Paul Taylor & BarryLa Trobe University 2009

Page 2: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Clearing up the OpenGL Perspective Functions

OpenGL uses a Right Handed Coordinate SystemThis means that the Z axis is positive out of the screen

Unfortunately for our heads the OpenGl functionsglOrtho(left, right, bottom, top, near, far)AndGluPerspective(…)glFrustrum(…) All take znear and zfar in positive values as the forward distance from the COP(Center of Projection) 0,0,0

What it all means is that remembering Z is negative into the screen:To create an Orthogonal Clipping Box that goes from z = -1 (1 unit infront of you) back to z=-10 (10 units infront of you) means calling glOrtho(left, right, bottom, top, 1.0f, 10.0f)

Page 3: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Your OpenGL Objects

• Basically your OpenGL Objects should still have a central point of 0,0,0 in Object Coordinates

• Your Render Function should translate all Objects into the MODELVIEW Matrix using a Translation Matrix that pushes the objects backwards and into the clipping Plane

• glTranslatef(x,y,-5.0f) // Middle of a z=0-10 clipping Box

Page 4: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Normal

• A Normal is a Vector is a Perpendicular vector to the Surface, Pixel or Vertex it relates to

• They are extremely useful for many, many reasons in Graphics

• They are easily calculated by the Cross Product of 2 non-parallel sides of a polygon

http://mathworld.wolfram.com/NormalVector.html

Page 5: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Unit Vector

• A Unit vector is exactly 1 unit long!Any Vector can be tuned into a Unit vector by dividing all

components of the vector by its MagnitudeNormal V = x/|v| + y / |v| + z / |v|Where |v|2 = (x2 + y2 + z2)Unit Vectors are very useful as they are non scalar, and

results from operations will always continue to be unit length

In the Matrix world the Dot Product of 2 Unit Vectors is equal to their cosine

Page 6: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Single Face Rendering

www.freakyzoo.com/2Headed%20Turtle.html

Page 7: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Finishing off your Basic Polygons

• Clockwise Polygons• Counter-Clockwise Polygons• Polygon Normals– RHS Polygons– LHS Polygons

• Z-Positive is typically the Polygon Normal (In Object Coordinates)

Page 8: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

So Far our Polygons have been 2-faced

Front Back

Page 9: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

So Far our Polygons have been 2-faced

Front Back

Page 10: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

This is the front and back view of a 1 faced Polygon

Front Back

Page 11: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

• To make rendering more efficient we should only consider the front faces of polygons

• This reduces the rendering load very quickly when you consider a complex 3D scene

Page 12: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

http://www-graphics.stanford.edu/courses/cs348b-competition/cs348b-05/forest/index.html

Page 13: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Fast Culling

http://www.soc.staffs.ac.uk/pal2/QMT/Formula/astc.gif

Remember the Dot Product of 2 Vectors is the Cosine Angle

Combining the Polygon Normal and the Viewport DirectionIf A.B < 0 Polygon is facing away

Page 14: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Basic Texturing

• There are 2 types of Buffer in you video card*• Color and Depth Buffers• Only Color Buffers can be drawn to your output

device• So far we have been using 3 Buffers– A Front Buffer– A Back Buffer– A Depth Buffer (Z Buffer)* According to OpenGL

Page 15: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Buffers and Formats

• A Buffer is an X x Y array of Values where X and Y are the resolution of the screen– In this course typically Values will be 32bit floats

• Bits Pixels and Bitplanes– Firstly in OpenGL a Bitmap is an X x Y array (or

image) with a 1 bit depth!• Bit Block Transfers (BitBlt) are covered in other subjects

so we’ll skip them

Page 16: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Pixel Maps

These are much more like what most would consider a ‘Bitmap’ (Windows Type)– An array X x Y of Pixels

Here is a 24bit Image / Texture declarationGlubyte stupidImage[512][512][3]To create a 32bit version we just need to extend

the depth to 4 bytes.

Page 17: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Using the Images / Textures in OpenGL

Texture MapsBump Maps

Normal MapsEnvironment Maps(Reflection Maps)

www.zanir.szm.sk/dx10-19.htmlwww.bencloward.com/tutorials_normal_maps12.shtml

http://www.lavaproductions.com/ChurchStone1Bump.jpg

Page 18: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Texture Formats

• 1D, 2D or 3D Textures can be used• Typically you will only be using 2D Textures, as

a 3D Texture can create an incredible load on the graphic Processing (And Video / Hardware Memory Use)

Page 19: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Texture Mapping

• In OpenGl Texture Coordinates range [0.0f->1.0f]

These are known as the Parametric Surface Coordinates and commonly reffered to as UV Coordinates

www.codersger.de/mags/cscene/CS8/CS8-02.html

Page 20: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Theoretically….

OpenGL Takes the XYZ Coordinates of a Vertex, then uses the related U,V coordinates of the Texture to apply it to the Object in World Coordinates. This object is then rendered to the Screen Buffer

Actually the Texture is NOT mapped onto the object up until writing the Pixel Buffer (After Perspective Transformation)

Page 22: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

UV Mapping For Complex Objects

www.highend3d.com/.../texturing/248-2.html

Page 23: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

The End (for now)

Page 24: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Mip Maps

Page 25: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Texturing Odd shaped Geometry

Page 26: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Using Intermediate Objects

Page 27: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Using UV Maps

Page 28: Buffers Textures and more Rendering Paul Taylor & Barry La Trobe University 2009

Aliasing

• Aliasing is when the data representing your 3D world becomes corrupted with artifacts