1 / 36

G53GRA – Computer Graphics cs.nott.ac.uk /~bai/graphics/gra.html

G53GRA – Computer Graphics http://cs.nott.ac.uk /~bai/graphics/gra.html. Bai Li Room 37 Computer Science Building bai@cs.nott.ac.uk. Module Aim. U nderstand the principles and techniques of 3D computer graphics D evelop programming skills for computer graphics in OpenGL

nitsa
Télécharger la présentation

G53GRA – Computer Graphics cs.nott.ac.uk /~bai/graphics/gra.html

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. G53GRA – Computer Graphicshttp://cs.nott.ac.uk/~bai/graphics/gra.html Bai Li Room 37 Computer Science Building bai@cs.nott.ac.uk

  2. Module Aim • Understand the principles and techniques of 3D computer graphics • Develop programming skills for computer graphics in OpenGL • If you have any problems acheiving these aims feel free to contact either • Lecturer: Li Bai bai&cs.nott.ac.uk • Tutors: Ben Haines www.cs.nott.ac.uk/~bxh Louis Parsonsonwww.cs.nott.ac.uk/~lqp

  3. Methods • Lectures and practicals • Lectures 1pm-3pm Tuesdays, in JC-EXCHGE-B.LT1 • Lab sessions from Week Two - 1pm-2pm Fridays, in A32, using OpenGL (www.opengl.org) • Learning materials – any graphics books, e.g., • Interactive Computer Graphics: A Top-Down Approach with OpenGL, by Edward Angel • Computer Graphics using OpenGL, by F.S.Hill • http://cs.nott.ac.uk/~bai/graphics/gra.html • Moodle • Assessment: 50% exam, 50% coursework.

  4. Computer Graphics • Computer graphics is the discipline of producing realistic images on a computer • 3D computer graphics is about creating 3D objects/scenes and viewing them as 2D images, analogous to taking a photograph with a camera • Computer graphics has a wide range of applications, including games and entertainment, media production, computer-aided design, virtual reality / augmented reality for education, medicine, etc • http://www.archiform3d.com/

  5. Content • Introduction to a graphics pipeline • Basic 3D Modelling • 3D Transformation • Hierarchical 3D Modelling • Viewing • Projection • Lighting Models • Texture Mapping • Clipping & Hidden Surface Removal

  6. 3D Graphics Pipeline • All computer graphics applications follow a pipeline, from the initial design of objects/scene, to a realistic 2D image • We start by describing our 3D scene, this is then passed through each stage of the pipeline turning our description of the scene into a realistic 2D image • The pipeline can vary, however in this module we will follow the most widely used pipeline and focus on the processes of this pipeline

  7. 3D Graphics Pipeline • Creating objects/scene • 3D modeling and/or transformation • Determining how objects/scene can be viewed • Specification of camera view volume • Transformation of objects to camera coordinate system • Clipping against view volume to determine visible objects • Projection of visible objects to obtain a 2D image • Determining which pixels should be filled • Rasterization from vectors/polygons to pixels • Determining color/texture/lighting at each pixel • Texture mapping and lighting models • Hidden surface removal

  8. Modelling • Scene = list of objects • Object = list of surfaces • Surface = list of polygons • Polygon = list of vertices scene vertices object surfaces polygons

  9. Polygon Mesh • Each polygon is planar (flat). We need a large number of small polygons to give the impression of curved surfaces. This is termed Level Of Detail (LOD): 48 polygons 120 polygons 300 polygons 1000 polygons

  10. Polygon Data Structure

  11. 3D Graphics Pipeline • Creating objects/scene • 3D modeling and/or transformation • Determining how objects/scene can be viewed • Specification of camera view volume • Transformation of objects to camera coordinate system • Clipping against view volume to determine visible objects • Projection of visible objects to obtain a 2D image • Determining which pixels should be filled • Rasterization from vectors/polygons to pixels • Determining color/texture/lighting at each pixel • Texture mapping and lighting models • Hidden surface removal

  12. Viewing Coordinate System camera (viewing) coordinate world coordinate camera setup

  13. 3D Viewing

  14. Clipping view frustum outside view so must be clipped

  15. 3d models viewport Projection Orthogonal projection Perspective projection

  16. 3D Graphics Pipeline • Creating objects/scene • 3D modeling and/or transformation • Determining how objects/scene can be viewed • Specification of camera view volume • Transformation of objects to camera coordinate system • Clipping against view volume to determine visible objects • Projection of visible objects to obtain a 2D image • Determining which pixels should be filled • Rasterization from vectors/polygons to pixels • Determining color/texture/lighting at each pixel • Texture mapping and lighting models

  17. Rasterization Solid polygons are broken down into fragments, one for each pixel it fills. Colour is interpolated across the fragments Rasterise 1 Fragment ~ Pixel

  18. 3D Graphics Pipeline • Creating objects/scene • 3D modeling and/or transformation • Determining how objects/scene can be viewed • Specification of camera view volume • Transformation of objects to camera coordinate system • Clipping against view volume to determine visible objects • Hidden surface removal • Projection of visible objects to obtain a 2D image • Determining which pixels should be filled • Rasterization from vectors/polygons to pixels • Determining color/texture/lighting at each pixel • Texture mapping and lighting models • Hidden surface removal

  19. Lighting and Texture

  20. Texture Each Fragment Texture

  21. A B y z2 z1 x z Hidden Surface Removal

  22. Output Fragments Texture + Colour + Lighting + -> Hidden Surface Removal Displayed Pixels Fragment

  23. Theoretical 3D Graphics Pipeline State Set static parameters: describe each object in object coordinate and where they will be in the scene, what colours and textures they are, where are the light is in the scene .. Turn vertices into geometry by joining them into polygons and transform their object space coordinates to view space Geometry Define which pixels the polygon falls into and create fragments and colour for each fragment Rasterization Each fragment is textured and blended with the colour of the fragment Texture Depth test all the fragments to decide which fragment should be displayed in which pixel Fragment Convert the digital color value to a visual pixel colour on the screen Display

  24. OpenGL Fixed Function Pipeline Make OpenGL calls to set the state: where the lights are, which textures are used, describe the objects in object space and where they are in the scene. OpenGL then takes over and transforms the scene into view space Object Rasterization OpenGL takes over and automatically makes fragments Image OpenGL automatically lights and textures the fragments based on the parameters you set inside the object pipe Display OpenGL automatically displays the fragments on the screen

  25. Shader based Pipeline It is possible to override fixed functionality for better performance and different effects, using shaders Vertex Shaders Set state, describe scene Write vertex shader to transform the scene Rasterization OpenGL creates fragments Fragment Shaders Write a fragment shader to light and texture each fragment Display OpenGL displays the fragments on the screen

  26. Pipelines are Equivalent State Object Vertex Shaders Geometry Rasterization Rasterization Rasterization Texture Image Fragment Shaders Fragment Display Display Display Theoretical Fixed Function Programmable

  27. Matrix Math

  28. Matrix Math

  29. Vector Math • Point is a location in a coordinate system y o x A z

  30. Vector Math • Position vector of a point goes to the point from the coordinate origin, it describe where the point is in space • Direction Vector has a direction and a magnitude, but not location y o x A = (x1,y1, z1) z

  31. Vector Math • Subtract one point from another, you get a vector linking the points: V = B-A is the vector from A to B: y B = (x2,y2, z2) V o x A = (x1,y1, z1) z V = (x2 – x1, y2-y1, z2-z1)

  32. Vector MathDot Product • A.B = |A||B|cos(θ) • A.B =x1x2+y1y2+z1z y B = (x2,y2, z2) |A| = √(x12+y12+z12) θ o x A = (x1,y1, z1) z cos(θ) = A.B / |A||B| = (x1x2, y1y2, z1z2) / |A||B| θ = cos-1( (x1x2, y1y2, z1z2) / |A||B| )

  33. Vector MathCross Product • A x B is the normal vector to both A and B, i.e. the one that is at right angles to both • |A x B| = |A||B|sin(θ) y B = (x2,y2, z2) n = (nx, ny, nz) θ o x z A = (x1,y1, z1) n = ( y1z2-z1y2, z1x2-x1z2, x1y2-y1x2)

  34. Vector MathCross Product • You can calculate cross product using the formula, or by calculating determinants of square matrices: y | i j k | | x1 y1 z1 | | x2 y2 z2 | = |y1 z1| i –|x1 z1 | j + |x1 y1| k |y2 z2| |x2 z2 | |x2 y2| e.g., |y1 z1| = y1z2 - y2z1 |y2 z2| n = (nx, ny, nz) B = (x2, y2, z2) θ o x z A = (x1, y1, z1) n = ( y1z2-y2z1, x2z1-x1z2, x1y2-y1x2 )

  35. Parametric Line Equation • A line parameterized by its start position and direction. • We can get to any point along the line by changing the value of λ (0<= λ<=1) y B = (x2,y2, z2) P = StartPosition + λ x Direction P = A + λ(B-A) P o x A = (x1,y1, z1) z

  36. Line Intersection • Objective: Find the point t, where lines P and Q intersect • Lines must have the same (x,y,z) value at the intersection point, that is, P=Q, so we have following simultaneous equations to solve for λ: • x1 + λ(x2-x1) = x3 + α(x4-x3) • y1 + λ(y2-y1) = y3 + α(y4-y3) P = (x1,y1) + λ (x2-x1,y2-y1) Q = (x3,y3) + α (x4-x3,y4-y3) Or P = (x1 + λ(x2-x1), y1 + λ(y2-y1) ) Q = (x3 + α(x4-x3), y3 + α(y4-y3) ) (x2,y2) (x4,y4) P Q t (x1,y1) (x3,y3)

More Related