1 / 70

Image Synthesis

Image Synthesis. DirectX/OpenGL. Graphics APIs. Graphics APIs . Graphics APIs . Graphics-APIs. DX/GL concepts: Implements the graphics-pipeline Geometric primitives: Points, lines, polygons Image primitives: Images and bitmaps State machine: Colors, materials,...

rupali
Download Presentation

Image Synthesis

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. Image Synthesis DirectX/OpenGL

  2. Graphics APIs

  3. Graphics APIs

  4. Graphics APIs

  5. Graphics-APIs • DX/GL concepts: • Implements the graphics-pipeline • Geometric primitives: • Points, lines, polygons • Image primitives: • Images and bitmaps • State machine: • Colors, materials,... • Low-level and immediate mode API • Higher modeling and animation conceptsnot available, no scenegraph • Phong-Lighting, Gouraud-Shading, Textures, Mip-Mapping, Alpha-Blending, Z-Buffer, Stencil-Buffer, Accumulation-Buffer, ...

  6. The OpenGL Structure application program OpenGL Motif widget or similar GLUT GLX, AGLor WGL GLU GL X, Win32, Mac O/S software and/or hardware

  7. Introduction to OpenGL Overview (“A trip down the rendering pipeline”)

  8. The “fixed function” Rendering Pipeline Geometry Processing Modelview Transform Lighting Perspective Transform Clipping Geometry Scan Conversion Framebuffer Texturing Fragment Tests Blending Rasterization Fragment Processing

  9. GL_LINES GL_POLYGON GL_LINE_STRIP GL_LINE_LOOP GL_POINTS GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP OpenGL: Geometric primitives Every primitive defined by Vertices (in homogeneous coordinates)

  10. Geometric primitives Note:DX/GL break down everything to triangles • Trianglesare flat • A linear interpolationfunctionexistswithintriangles

  11. glVertex3fv( v ) Data Type Vector Number of components b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double omit “v” for scalar form glVertex2f( x, y ) 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) OpenGL: Geometric primitives

  12. OpenGL: Geometric primitives OpenGL commands • Commands and parameters are send to the graphics system • High performance applications use a different mode to send DX/GL primitives glBegin(GL_TRIANGLES); glVertex3f(x1, y1, z1); glVertex3f(x2, y2, z2); glVertex3f(x3, y3, z3); glVertex3f(x4, y4, z4); glVertex3f(x5, y5, z5); glVertex3f(x6, y6, z6); glEnd(); glBegin(GL_TRIANGLES); glVertex3fv(p1); glVertex3fv(p2); glVertex3fv(p3); glVertex3fv(p4); glVertex3fv(p5); glVertex3fv(p6);glEnd();

  13. Primitives and vertex-attributes • How to group primitives glBegin( primType); ...; glEnd(); • How to render primitives? Vertex-attributesglColor*(); glNormal*(); glTexCoord(); Global “fixed-function” statesglPointSize(size); glShadeModel(GL_SMOOTH);glEnable(GL_LIGHTING);...

  14. States • DX/GL Systems are state machines • State variables define the current state • Can be set and requested individually • Current state defines how things get rendered glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glBegin(GL_TRIANGLES); glColor3v(c1); glNormal3v(n1); glVertex3v(t1); glColor3v(c2); glVertex3v(t2); glVertex3v(t3);glEnd();

  15. The OpenGL Rendering Pipeline OpenGL rendering pipeline – Geometry data Per-vertexoperationsand primitive assembly Vertexdata • • • Textureassembly Fragment processing Rasterization Framebuffer

  16. Geometry processing • Vertex operations and primitve assembly • Coordinate/normal transformation • Lighting calculations • Texture coordinate generation & transformation • Perspective projection • Front/back face culling • Clipping • Result is geometric primitives with color, depth, texCoords etc.

  17. Geometry processing • Polygonal models (triangle meshes) Light and material properties: Light source type Color Reflectivity Tansparency ... Per-vertex: Coordinate (x,y,z) Color (RGB) Normal (Nx,Ny,Nz) TexCoords(u,v,w)

  18. Geometry processing Transformation – camera analogy • Modeling: move and scale model • Viewing: position and orientation of camera • Projection: adjust camera lens • Viewport: photograph viewing volume camera Model tripot

  19. Geometry processing normalized device eye object clip window • v • e • r • t • e • x • Modelview • Matrix • Projection • Matrix • Perspective • Division Viewport Transform Modelview • Projection Modelview l l l The transformation pipeline l l l • Matrix-Stacks: • Modelview • Projection • Texture

  20. Geometry processing • Transformation matrices • Choose matrix stackglMatrixMode(GL_MODELVIEW or GL_PROJECTION) • Load or multiply matrix (from right)glLoadMatrix(), glMultMatrix() • Manage stackglLoadIdentity(),glPushMatrix(), glPopMatrix() • Spezial Modelview-TransformationsglRotate(), glTranslate(), glScale()

  21. Geometry processing • Transformation matrices

  22. Geometry processing Transformations • Affine transformations in homogeneous coordinates Rotation Shear Scaling Translation Homogeneous part Projection

  23. Geometry processing Viewing and modeling • Camera movement (foward) is equivalent to movement of objects towards the camera • Viewing transformation equivalent to multiple modeling transformations glTranslatef( 0.0, 0.0, -5.0 );gluLookAt( 0.0,0.0,5.0, 0.0,0.0,0.0, 0.0,1.0,0.0);

  24. Geometry processing • Projective transformationsglFrustum(left,right,bottom,top,zNear,zFar)gluPerspective(fovy,aspect,zNear,zFar)glOrtho(left,right,bottom,top,zNear,zFar) • glFrustum allows for non-symmetric viewing pyramids

  25. RGBA-Color Lighting Texture Shading flat/smooth Color Clamping Geometry processing • Lighting and shading • Two ways to determine color of a vertex • Vertex attribut glColor() • Material color and illuminationglColorMaterial, glEnable(GL_LIGHTING)

  26. ambient diffuse specular attenuation ModelviewTransformation Matrix M Geometry processing Lighting and shading – Phong lighting Vertex P Light source- positioncolor Vertex color Material- colors globalambient Light Normal N

  27. R L + E H = N H L + E L E Geometry processing • Phong lighting • cos() = N * L • cos() = N * H (Blinn-Phong)

  28. Geometry processing Extended Phong lighting

  29. Geometry processing • Turn on lightglEnable( GL_LIGHTING )glEnable( GL_LIGHTn ) • Light source propertiesglLightf{v}( light, property, value ) • Material propertiesglMaterialfv( face, property, value ) • Light source types • Spotlight: • Local (point light): into all direction • At infinity (directional light; directed): w=0 in position • Front and back faces illuminatedglEnable( GL_LIGHT_MODEL_TWO_SIDE)

  30. Rasterization The graphics pipeline Geometry Processing Modelview Transform Lighting Perspective Transform Clipping Geometry Scan Conversion Framebuffer Texturing Fragment Tests Blending Rasterization Fragment Processing

  31. Rasterization • Conversion of geometric data into fragments • Fragment: • Represents a point of geometry • Has color, texCoord, depth etc. • Associated with a pixel • But not yet a pixel (not stored in the framebuffer) • Pixel: • Color of a pixel in the framebuffer

  32. Rasterization • Scan conversion of geometric primitives • For each covered pixel a fragment is generated • Attributes like color, depth, texture coordinates etc. are generated from projected vertex attributes • During fragment generation OpenGL states, e.g. shading model, line width, polygon mode etc. are taken into account

  33. Rasterization • Rasterization of geometric data Geometry processing Vertex transformation Lighting Clipping ... Rasterization Fragment Processing Texturing Per-fragment tests Per-fragment comparison Blending ... Screen coord (X,Y) Depth (z) Color (RGB) TexCoords (u,v,w) ...

  34. Rasterization Once a fragment is generated, per-vertex attributes need to be assigned properly • Determination of color and other properties for all pixels along a scanline is called Shading • This is done via interpolation (see exercise for more information) Rasterization v0 scanline v2 v1

  35. Rasterization – wire frame

  36. Rasterization – flat shading

  37. Rasterization Smooth or Gouraud shading (1971) Idea: better quality by respecting color variations on the polygon • Per vertex lighting • Linear interpolation of color using barycentric interpolation in triangles • In screen space during scan conversion

  38. Rasterization – Gouraud shading

  39. Rasterization Phong shading (1975): higher quality shading by interpolating normals rather than colors • Evaluates lighting model for every pixel • Not supported by OpenGL

  40. Phong shading

  41. Rasterization - OpenGL shading Phong lighting and shading Phong lighting Gouraud shading

  42. Rasterization • Scan conversion of primitives Rasterization Interpolation of per-vertex attributes along scanlines v0 scanline v2 z v1 Depth values: non-linear in [Znear, Zfar] due to perspective projection Zfar Znear

  43. Fragment processing Graphics APIs and the graphics pipeline Geometry Processing Modelview Transform Lighting Perspective Transform Clipping Geometry Scan Conversion Framebuffer Texturing Fragment Tests Blending Rasterization Fragment Processing

  44. Fragment Processing • Fragment operations (apply before fragments beome pixels) • Texturing • Fog calculation • Tests and comparisons • Blending • Dithering • Logical operations and masking

  45. Texture Mapping Texture mapping • For each vertex specify vertex position, normal, color andtexture coordinate glBegin(GL_TRIANGLES); glColor4f(R0,G0,B0,0); glColor4f(R1,G1,B1,1); glColor4f(R2,G2,B2,2); glNormal3f(N0x,N0y,N0z); glNormal3f(N1x,N1y,N1z); glNormal3f(N2x,N2y,N2z); glTexCoord3f(T0x,T0y,T0z); glTexCoord3f(T1x,T1y,T1z); glTexCoord3f(T2x,T2y,T2z); glVertex3f(V0x,V0y,V0z)); glVertex3f(V1x,V1y,V1z)); glVertex3f(V2x,V2y,V2z)); glEnd();

  46. Texture Mapping Hardware supported texture interpolation • For each fragment, the appropriate texture value is fetched from the texture array • Interpolation of texture values is supported by the hardware Texture elements Per-fragment sample point

  47. Texture Mapping Texture mapping • Shape (geometry) & appearance (texture)

  48. Texture Mapping Warping (texture coordinates outside (0,1)) clamp/clamp clamp/repeat repeat/clamp repeat/repeat

  49. Texture Mapping Texture filtering • Combining texels to determine pixel color • Minification: pixels are larger than one texel • Magnification: pixels are smaller than one texel • Filtering methods • Nearest: choose the texel closest to the pixel center • Linear: (bi/tri)-linear texture interpolation • MipMap: (bi/tri)-linear interpolation in a stack of textures of decreasing resolution

  50. Texture Mapping Texture filtering Pixel Pixel Textur Textur magnification minification

More Related