Computer Graphics. Graphic pipeline OpenGL, DirectX etc

Size: px
Start display at page:

Download "Computer Graphics. Graphic pipeline OpenGL, DirectX etc"

Transcription

1 OpenGL, DirectX etc 1

2 Approach that is complementary to ray-tracing Lots of different implementations Software implementation e.g. Pixar Renderman Do a 2 hours movie in 1 year imposes leaves less than 3 minutes of CPU time per image (but it is easily run un parallel) Hardware implementations, e.g. PC graphic cards Goal here : speed but also some realistic rendering (very flexible) Almost realtime : rendering of many millions of triangles per second In what follows, we will restrict ourselves to an abstraction of an hardware implementation 2

3 Goal here : operations are easily parallelized or vectorized Groups of dedicated GPUs that are able to execute dozens to thousands ot operations in parallel explains why GPUs are so powerful ( many times that of generic CPUs à 1/5 of the clock speed) Dedicated high-bandwith memory 3

4 Bus performance (dates back to 2010 but ideas are same today) Nvidia 4

5 GPU specific architecture Nvidia 5

6 Pipeline Application Command flow vertex processing We are here «Langage» standards OpenGL, DirectX etc... 3D Transformations shading Transformed geometry Raster conversion Fragments ( ~ pixels + interpolated data) Operations on fragments (fragment processing) Conversion of primitives into fragments Compositing, mixing, (shading) framebuffer Display What the user sees 6

7 Primitives Points (in space) Line segments Triangles Polylines Triangle fans / strips That s all! Curves? Transformed into polylines Polygones? Decomposed into triangles Curved surfaces? Approximated with triangles The current «trend» is the restrict to a minimal number of primitives Simple, uniform, repetitive good for vectorial processing 7

8 Command flow : depends on the implementation e.g. OpenGL 1, DirectX, others Always somewhat similar See OpenGL labs OpenGL advantages : Multiplatform, simple, high performance, still evolving, and not attached to a specific architecture or company. It became a standard and is supported everywhere, even on smartphones 8

9 Pipeline Application Command flow vertex processing We are here «Langage» standards OpenGL, DirectX etc... 3D Transformations shading Transformed geometry Raster conversion Fragments ( ~ pixels + interpolated data) Operations on fragments (fragment processing) Conversion of primitives into fragments Compositing, mixing, (shading) framebuffer Display What the user sees 9

10 Pipeline of geometrical transformations 10

11 11

12 Clipping Rasterization expects that primitives are visible on the screen This is done in the 3D canonical space, after the application of the perspective projection (see course 2 ), but before the perspective division. All that is outside the volume limited by : w x w w y w w z w is discarded Cut by 6 planes 12

13 Clipping Basic operation : cut a triangle into 3 by a plane 4 cases : All vertices inside tr kept All verticels exterior triangle discarded 1 vertex in; 2 out 1 triangle remains 2 vertices in; 1 out 2 triangles remain 13

14 Hidden face removal We have seen how to geometrically transform the primitives to the screen The perspective projection gives a strong hint on depth Hidden face removal is another strong hint Allows to draw exclusively what is seen (goal : performance) 14

15 Hidden face removal Backface culling For closed and opaque shapes, one does not see the inside! 15

16 Hidden face removal Backface culling No need to draw the backward-facing faces v n n v 16

17 Hidden face removal Backface culling No need to draw the backward-facing faces v n v n 0 n v 17

18 Hidden face removal Backface culling Dépends ont the convention used to compute the normal to the shape Usually, exterior pointing vector Computation is easy if triangles are carefully oriented! s3 s1 s 2 s1 s 3 n= s1 s 2 s1 s 3 s1 s2 18

19 Hidden face removal How to care for this case? Painter s algorithm Binary space partitionning Z-buffer 19

20 Pipeline Application Command flow vertex processing We are here «Langage» standards OpenGL, DirectX etc... 3D Transformations shading Transformed geometry Raster conversion Fragments ( ~ pixels + interpolated data) Operations on fragments (fragment processing) Conversion of primitives into fragments Compositing, mixing, (shading) framebuffer Display What the user sees 20

21 Raster conversion First stage : enumerate pixels that are covered by a «continuous» primitive Second stage : Interpolate values that are known on the vertices of the primitive Example : the colour known at the vertices of a triangle may be distributed on each pixel covered by the triangle Other variables may also be interpolated. Normal vectors for instance... 21

22 Raster conversion Transformation of continuous primitives into discrete pixels Example : drawing of a line Difficulty : aliasing 22

23 Naïve algorithm Line = unit width rectangle One specifies beginning and end vertices Case here : black inside and white outside 23

24 Naïve algorithm Line = unit width rectangle One specifies beginning and end vertices Case here : black inside and white outside 24

25 Point sampling One approximates the rectangle by drawing every pixel whose center is inside the rectangle 25

26 Point sampling One approximates the rectangle by drawing every pixel whose center is inside the rectangle Problem : sometimes pixels with more that one adjacency are turned on 26

27 27

28 Bresenham algorithm (midpoint alg.) We will define the thickness with respect to the y axis... 28

29 Bresenham algorithm (midpoint alg.) We will define the thickness with respect to the y axis... One turns on only one pixel per column 45 slanted lines will appear thinner. 29

30 Bresenham algorithm (midpoint alg.) We will define the thickness with respect to the y axis... One turns on only one pixel per column 45 slanted lines will appear thinner. 30

31 31

32 Bresenham algorithm (midpoint alg.) Equation : Evaluated for everu column y=mx b One turns on only one pixel per column y=0.49x x 0 x 1 0 m 1 6 for x = ceil(x0) to floor(x1) y=b+m*x plot(x,round(y))

33 Optimization Multiply and rounding are rather slow operations (at least on primitive CPUs) y=mx b mx b y=0 For each pixel, the only options are E and NE One computes the error : d > 0.5 decides E or NE d =m x 1 b y 7 6 NE 5 4 x, y 3 E

34 Optimization d =m x 1 b y One must only update integer steps along x and y Exclusive use of the addition (no mult or divide) d > 0.5 decides E or NE d =d 1 d =d m

35 Optimization x=ceil(x0) y=round(m*x+b) d=m*(x+1)+b-y While (x<floor(x1)) { If d>0.5 { y=y+1 d=d-1 } x=x+1 d=d+m plot(x,y) } // round to ceil // round to nearest // round to floor

36 Generally, endpoints are given G x, y 0 dy y= x +b dx x0 y0 x1 y1 G x, y =0 G x, y 0 dx= x 1 x 0 dy= y 1 y 0 Implicit form : G x, y =dy x dx y dx b F x, y =2 dy x 2 dx y 2 dx b 36

37 What is the value of F at M? d i = F x i 1, y i 1/2 =2 dy x i 1 2 dx y i 1/2 2 dx b d i 0 : M is under the line go to NE d i 0 : M is above go to E NE? M xi, yi Q E? 37

38 First point: what is the value of d 0? d 0=F x 0 1, y 0 1/2 =2 dy x dx y 0 1/ 2 2 dx b =2 dy x 0 2 dx y 0 2 dx b 2 dy dx =F x 0, y 0 2 dy dx As x 0, y 0 belongs to the line : F x 0, y 0 =0 d 0=2 dy dx 38

39 Recursion : what is the value of d i 1? If d i 0 then go to E : x i 1, y i 1 = x i 1, y i d i 1= F x 2, y 1/ 2 =d i 2 dy Otherwise go to NE : x i 1, y i 1 = x i 1, y i 1 d i 1= F x 2, y 3/2 =d i 2 dy 2 dx 39

40 Algorithm is valid only for one octant Bresenham( x1, y1, x2, y2 ) { dx = x2 x1 dy = y2 y1 d = 2*dy dx plot( x1, y1 ) while (x1 < x2 ) { if (d <= 0) // EAST d = d + 2*dy else // NORTH-EAST { d = d + 2*(dy-dx) y1 = y1 + 1 } x1 = x1 + 1 plot( x1, y1 ) } } 40

41 What to do if the line is not in the right octant? Exchange x and y Exchange start and end points Replace y by -y 41

42 Same type of algorithm do exist for other geometric shapes : e.g. circles (see litterature What about aliasing? Algorithm derived from Bresenham that avoid aliasing do exist, see algorithm of Xiaolin Wu Oversampling sampling on a finer grid then averaging on bigger pixels is also an option. Bresenham, Jack E. "Algorithm for computer control of a digital plotter", IBM Systems Journal, Vol. 4, No.1, pp , 1965 Wu, Xiaolin. "An efficient antialiasing technique". 25 (4): ,

43 43

44 Interpolation Some variable is known at the vertices of the triangle (color, normal vector, etc...) One wish to get a representative value of the same variable along the line for every pixel that is turned on. A progressive variation would be fine, thus a linear interpolation is the right tool here : f x = 1 f 0 f 1 1D : = x x 0 / x 1 x 0 2D,3D : a is simply the distance ratio to the endpoints. 44

45 Interpolation The pixels are not exactly on the line One defines a projection on the line It is linear One may use results obtained before to construct an interpolation P1 = v x / L P0 v = v y / L =v Q P 0 / L L=v P 1 P 0 45

46 Interpolation The pixels are not exactly on the line One defines a projection on the line It is linear One may use results obtained before to construct an interpolation P1 = v x / L P0 v = v y / L =v Q P 0 / L L=v P 1 P 0 46

47 Alternative meaning d and a are updated from pixel to the next pixel d tells us at which distance we are to the line a tells the position along the line d and a are coordinates in the natural frame of the line 47

48 Alternative meaning The loop means the pixels that we visit Interpolation of d and a at each pixel A fragment is emmitted if the pixel s center is in the band Interpolation becomes the main operator P1 P0 v u 48

49 Alternative meaning x=ceil(x0) y=round(m*x+b) d=m*(x+1)+b-y etc... while (x<floor(x1)) { if (d>0.5) { y=y+1 d=d-1 etc... } else { x=x+1 d=d+m etc... } If (-0.5 < d <= 0.5) plot(x,y, ) } P1 P0 v u 49

50 Triangle raster conversion Very common case With a good antialiasing, may be the only case! Some systems represent lines with two very thin triangles Triangle represented with 3 vertices The algorithm has the same philosophy as for lines : One walks from pixel to pixel Linear operators are evaluated for each step Those operators allow us to know if a pixel is inside or outside 50

51 Triangle raster conversion Input : Three 2D points x 0, y 0 ; x1, y 1 ; x 2, y 2 Variables to interpolate, at each vertex q 00,, q 0 n ; q10,, q1 n ; q 20,, q2 n Output : a list of fragments, with : Integer coordinates of pixels x, y Interpolated variables q 0,, qn 51

52 Triangle raster conversion Incremental evaluation of linear functions on a grid of pixels Functions are defined by the value at the vertices Use of additional functions to determine the set of fragments to return back Vertex Fragment x 0, y 0 q 00,, q 0 n x 2, y 2 q 20,, q 2 n (x, y) q 0,, q n x 1, y 1 q10,, q1 n 52

53 Incremental linear interpolation A linear affine function in the plane : q x, y =c x x c y y c k Evaluation on a grid is efficient : q x 1, y =c x x 1 c y y c k =q x, y c x q x, y 1 =c x x c y y 1 c k =q x, y c y +cy +cy... +cx+cx +cx... 53

54 Interpolation of variables known at vertices Determine c x, c y, c k defining the unique linear function that gives back the value at the vertices 3 parameters, 3 equations : c x x 0 c y y 0 c k =q 0 c x x 1 c y y 1 c k =q1 c x x 2 c y y 2 c k =q 2 x0 x1 x2 y0 1 cx q0 y1 1 c y = q1 y2 1 ck q2 Singular system if points are collinear 54

55 Interpolation of variables known at vertices Translation of the origin to x 0, y 0 q x, y =c x x x 0 c y y y 0 q 0 q x 1, y 1 =c x x 1 x 0 c y y 1 y 0 q 0 =q 1 q x 2, y 2 =c x x 2 x 0 c y y 2 y 0 q 0=q 2 2X2 linear system x 1 x 0 y 1 y 0 c x q 1 q 0 = x 2 x 0 y 2 y 0 c y q 2 q 0 Solution using Cramer s rule c x = q 1 y 2 q 2 y 1 / x 1 y 2 x 2 y 1 c y= q 2 x 1 q1 x 2 / x 1 y 2 x 2 y 1 55

56 What are the fragments to consider? Those for which the barycentric coordinates are positive Algebraically, on has c,, p= a b c =1 Inside iff 0 ; 0 ; 0 a b Pineda, Juan, " A parallel algorithm for polygon rasterization" 22 (4): 17-20,

57 Barycentric coordinates are interpolated variables Each barycentric c. yields 1 on a specific vertex and 0 on all others. They are an implicit representation of the sides of the triangle. 57

58 Pixel-per-pixel raster conversion (Pineda s algorithm 1998) One vists conservatively a superset of the pixels Use of interpolation of linear functions Use of barycentric coordinates to determine when to emit a fragment x 2, y 2 q 20,, q 2 n x 0, y 0 q 00,, q 0 n x 1, y 1 q10,, q1 n 58

59 Triangle raster conversion Beware of rounding and arbitrary decisions One has to visit every pixel at least once... (otherwise there may be a hole!) But not two times! (Those pixels would take an arbitrary colour that depend in which order things are drawn) Elegant solution : antialiasing... 59

60 Pipeline Application Command flow vertex processing We are here «Langage» standards OpenGL, DirectX etc... 3D Transformations shading Transformed geometry Raster conversion Fragments ( ~ pixels + interpolated data) Operations on fragments (fragment processing) Conversion of primitives into fragments Compositing, mixing, (shading) framebuffer Display What the user sees 60

61 Z-buffer (depth buffer) In many application, sorting with respect to depth is too costly The order changes with the viewpoint There exists the BSP tree Viewpoint independent but : Heavy datastructures (difficult to implement «in silico») Cutting of primitives Slow building Non-incremental (all data have to be known in advance) 61

62 Solution that is usually favoured : draw in any order and keep track of the closest drawn pixel Use an additional storage, that stores, for each pixel, the smallest depth to date When one ought to draw a new pixel, the actual depth is compared to the stored depth and if the latter is greater, then the pixel is drawn and the depth is updated. 62

63 Z-buffer This is an axemple of a «brute-force» approach, it works because memory is cheap and fast. Foley et al. 63

64 Z-buffer Evidently limited to bitmap images (not vectorial) Somewhat more difficult to implement with transparency (alpha channel) 64

65 Z-buffer and alpha channels One separates opaque objects and translucent ones 1) Opaque objects are drawn with an update of the z-buffer. 2) Then, use a BSP tree for partially transparent entities 3) Draw transparent entities using the BSP ordering, while takin the Z-buffer into account, but without updating it Thus, transparent faces behind opaque ones are not drawn (they are not visible) 65

66 Z-buffer : limited accuracy The supplementary channel is generally encoded as an integer, as are the color channels 0< z * < N 1 Cause : hardware implementation (simple and fast) It is possible to have distinct objects seen at the same depth if the value that is stored in the Z-buffer is the same The accuracy is spread between n (near plane) and f (far plane) These were used to define the observable volume, see course 2. 66

67 Z-buffer Plane n * Plane f z *= N 1 z =0 67

68 Z-buffer Let us choose an integer with b bits (8 or 16...) What is then the accuracy of the z-buffer? If the z that is stored is proportional to the actual distance (case of orthogonal projections): We have N=2b layers for a distance equal to f-n Therefore, the accuracy (independent to the distance!) is Δ z= ( f n) 2b : to maximize the accuracy, f-n must be kept small. If a perspective projection is used, the z stored in the z-buffer is proportional to the result obtained after the perspective division. Therfore, the size of the layers depends on depth By how much? 68

69 Z-buffer Plane n * z =0 Plane f z *= N 1 Orthographic proj. Perspective proj. 69

70 Z-buffer In the second course, we have computed zc after the perspective divide : 2 n r l 0 x, y, z,1 r l r l n 0 0 f n 2 f n t b = X,Y, z, z n f n f t b f n 1 t b n f f n 2 f n 2 f n z c= 0 0 n f f n z f n M proj _ persp _ OpenGL z c= f n 2fn f n z f n 70

71 Z-buffer The interval for zc is 2 ( -1 to 1) and one still have N layers. z c= f n 2fn f n z f n z c 2 z f n 2 = 2 z f n N What is the size of the layers? Need to solve for z (invert) The largest layer is for z=f : 2 z f n z= N fn z max = f f n Nn 71

72 Z-buffer Example: n = 1 m, f = 100 m, the z-buffer has 8 bits N=256, what is the actual size of the layers? 2 z f n Δ z = f ( f n) = =39 m (0.15 m with 16 bits) z= max Nn N fn n f n 1 99 z min = = = m N f With n=10 : f ( f n) Δ z max = = =3.5 m (0.013 m with 16 bits) Nn n f n z min = = =0.035 m 72 N f

73 Z-buffer For a good accuracy, it is best to increase n and decrease f. Never ever set n=0 cancels the z-buffer Generally, the number of bits b is fixed by the hardware (usually 16, 24 or 32 bits) The more the better but takes as much memory as the picture (usually 24 bits) 73

74 Interpolation in perspective projection projection plane eye Projections of the endpoints 74

75 Interpolation in perspective projection projection plane p2 eye p 1 p 2 2 p1 Projection of the middle of the line middle point of the projected line Linear interpolation in screen coordinates interpolqtion in eye space 75

76 Interpolation in perspective projection projection plane eye Projects in the middle... z1 z 1 z 2 /2 z2 Projection of the middle of the line middle point of the projected line Linear interpolation in screen coordinates interpolqtion in eye space 76

77 Interpolation in perspective projection Projection plane eye equidistant on z Projection of the middle of the line middle point of the projected line Linear interpolation in screen coordinates interpolqtion in eye space 77

78 Interpolation in perspective projection Projection plane eye This projects in the middle z c1 z c1 z c2 / 2 z c2 Projection of the middle of the line middle point of the projected line Linear interpolation in screen coordinates interpolqtion in eye space 78

79 Interpolation in perspective projection Projection plane eye equidistant on z c (screen depth) The depth variable that has to be interpolated (at the pixel level is zc (screen depth) obtained after perspective divide, and not z, the real coordinate 79

80 The perspective correction (use of zc instead of z ) aims to avoid problems for e.g. textures applied on slanted surfaces F0 wikipedia F1 F u = 1 u F 0 u F 1 F0 1 u u z c0 F u= 1 1 u u z c0 F1 z c1 1 z c1 80

81 Minimal pipeline «Vertex» stage (input : 3D positions / vertices and colors / triangle) Position transformation (object space eye space) Position transformation (eye space screen space) Transmission of the color (no interpolation = constant on the triangle) Raster conversion Pixel list Transmission of the color «Fragment» stage (output : color) Display pixels with right colors on the frambuffer 81

82 82

83 Minimal pipeline with z-buffer «Vertex» stage (input : 3D positions / vertices and colors / triangle) Position transformation (object space eye space) Position transformation (eye space screen space) Transmission of the color (no interpolation = constant on the triangle) Raster conversion Interpolation of zc (z in screen space) Transmission of the color «Fragment» stage (output : color, zc) Display pixels with right colors on the frambuffer and update z-buffer only if z c < current zc 83

84 84

85 Flat shading Uses the «real» normal to the triangle Faceted appearance Most realistic view of the real geometry (as defined) Foley et al.85

86 Minimal pipeline with z-buffer and flat shading «Vertex» stage (input : 3D positions / vertices and colors / triangle + normal) Position transformation (object space eye space) Color computation (flat shading) with the normal (one color / tri) Position transformation (eye space screen space) Transmission of the color (no interpolation = constant on the triangle) Raster conversion Interpolation of zc (z in screen space) Transmission of the color «Fragment» stage (output : color, zc) Display pixels with right colors on the frambuffer and update z-buffer only if z c < current zc 86

87 Flat shading 87

88 Observer and illumination : close vs. far Phong illumination require some geometric info Light vector (depends on position) Obsever vector (depends on position) Normal to the surface (computed beforehand) Observer & light vectors are changing Must be computed & normalized for every facet light observer 88

89 Observer and illumination : close vs. far Case where observer and source are far away Almost parallel light rays Almost orthographic projection Light & observer vectors do not change much A frequent optimization is to consider they do not change even though it is generally false 89

90 Directional light (e.g. sun) Light vector is constant light [ x y z 0] observer In many cases, it increases dramatically the throughput of the pipeline by simplifying computations 90

91 Observer at the infinite Orthographic projection? Constant projection angle One may also do that for the perspective projection, only for shading computations The observer vector is considered constant (for instance, it is normal to the image plane) Yield strange results if a wide angle view is used Blinn-Phong shading: observer, light, and bisector vector all constant (see course 4) 91

92 Directional light & far observer light [ x y z 0] observer [ x o y o z o 0] Only the normal changes. Means the shading of every facet is the same if the orientation is the same. 92

93 Gouraud interpolation One wants a smooth shading eventhough the geometry is faceted Remember mapping : sensitivity to the normals much greater than the sensitivity to positions Idea : colour is computed at the facet s vertices Then, an interpolation is performed to get the color everywhere, at same time than the raster conversion. 93

94 Gouraud interpolation Foley et al.94

95 Pipeline with z-buffer and Gouraud interpolation «Vertex» stage (input : 3D positions / vertices and color per triangle + normal per vertex) Position transformation (object space eye space) Color computation made per vertex Position transformation (eye space screen space) Raster conversion Interpolation of zc (z in screen space), rgb color «Fragment» stage (output : color, zc) Display pixels with right colors on the frambuffer and update z-buffer only if z c < current zc 95

96 Pipeline with z-buffer and Gouraud interpolation 96

97 Gouraud interpolation Normals at vertices Mathematically undefined If the tessellation (triangulation) is obtained from a smooth surface (sphere, B-Spline, etc..), one may take the exact normal on that surface at the vertex If not, just do as if by averaging neigboring triangle normals N1 Ni N5 Ns N4 N3 N s= N2 i Ni i 97

98 Gouraud interpolation May be applied to any shading model Diffuse Blinn-Phong Etc... However, for specular shading, it does not work well There are strong variations of the shading with respect to the position, even on a single triangle. A linear interpolation is just too basic to reproduce these variations. 98

99 Blinn shading and with Gouraud interpolation 99 Foley et al.

100 Phong interpolation Why not interpolate normals and compute shading at the pixel (fragment) level? As easy as interpolating colors The shading will be computed are every pixel, from information that have been interpolated (colors, normals, etc... In the, it means that we move the shading computation from the «Vertex» stage to the «fragment» stage. 100

101 Pipeline Application Command flow vertex processing We are here «Langage» standards OpenGL, DirectX etc... 3D Transformations shading Transformed geometry Raster conversion Fragments ( ~ pixels + interpolated data) Operations on fragments (fragment processing) Conversion of primitives into fragments Compositing, mixing, (shading) framebuffer Display What the user sees 101

102 Pipeline with z-buffer and Phong interpolation «Vertex» stage (input : 3D positions / vertices, triangle, + normal/color per vertex) Position transformation (object space eye space) Position transformation (eye space screen space) Raster conversion Interpolation of zc (z in screen space), rgb color, xyz normal «Fragment» stage (output : color, zc) Shading computation using interpolated data (including normal) Display pixels with right colors on the frambuffer and update z-buffer only if z c < current zc 102

103 Phong interpolation 103

104 OpenGL Some shading models are part of the standard (typically : Phong, Lambert, Gouraud, Blinn-Phong ), Nothing has to be done. For specific shading computations, there is an API that allows defining exactly what has to be done at each stage : Either at the «vertex shader» stage, vertex per vertex Or, at the «fragment shader» stage, pixel per pixel Recent graphic cards (and the software driver embedded in the operating system) allow to litterally program in pseudo C-language either the «vertex shader» or the «fragment shader» (see e.g. Nvidia CUDA, OpenCL) 104

105 Programmable! Not very versatile 105

106 GPGPU GPGPU Use of computing power of GPUs to do other things that just shading... Recent GPUs are somewhat versatile (but less than generic CPUs) Branching became possible Random memory access But they are designed for vector computing (i.e. same operations applied to different data, SIMD) There are standards to drive these GPUs : Open Computing Language (OpenCL, open) Common Unified Device Architecture (CUDA, Nvidia) Direct Compute (Microsoft) 106

107 GPGPU OpenCL pseudo-c language Host program may be in C++, and runs on the CPU The OpenCL code is stored as a character string (char[] or std::string ) The OpenCL code is then compiled by the graphic card s «driver» (the CPU does the job), result is uploaded on the GPU by dedicated system calls To access to the machine code, system calls allow to pass parameters and memory chunks to the GPU The computation is made on the GPU Results are given back to the host program using memory transfer. 107

108 GPGPU OpenCL sample code kernel void VectorAdd( global float* c, global float* a, global float* b, constant float *cst { // Index of the elements to add unsigned int n = get_global_id(0); unsigned int nl = get_local_id(0); unsigned int gsz = get_global_size(0); unsigned int lsz = get_local_size(0); unsigned int gid = get_group_id(0); // do some math from vectors a and b and store in c private float res; res=0.; int i; for (i=0;i<100;++i) // not a loop over elements of the arrays { res=a[n]+sin(a[n])+b[n]; if (res>5.5) res=a[n]* (*cst) ; } c[n] = res; 108 }

109 GPGPU In the host program init std::string Src ; // Source code (see preceding slide) std::vector<cl::platform> platforms; cl::platform::get(&platforms); cl_context_properties properties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; cl::context context(cl_device_type_all, properties); std::vector<cl::device> devices = context.getinfo<cl_context_devices>(); cl::program::sources source(1,std::make_pair(src.c_str(),src.size())); cl::program program = cl::program(context, source); program.build(devices); // compilation! 109

110 GPGPU In the host program system calls cl::commandqueue queue(context,devices[0],0,&err); cl::buffer GPUOutVec(context, CL_MEM_WRITE_ONLY,sizeof(float)*SIZE, NULL, &err); float cst=1; cl::buffer GPUVec1(context,CL_MEM_READ_ONLY CL_MEM_COPY_HOST_PTR,sizeof(float)*SIZE,HostVec1,&err); cl::buffer GPUVec2(context,CL_MEM_READ_ONLY CL_MEM_COPY_HOST_PTR,sizeof(float)*SIZE,HostVec2,&err); cl::buffer GPUCst1(context,CL_MEM_READ_ONLY CL_MEM_COPY_HOST_PTR,sizeof(float),&cst,&err); cl::event event1; cl::kernel kernel(program_, "VectorAdd", &err); kernel.setarg( 0, GPUOutVec);kernel.setArg( 1, GPUVec1); kernel.setarg( 2, GPUVec2);kernel.setArg( 3, GPUCst1); queue.enqueuendrangekernel(kernel,cl::nullrange, cl::ndrange(size_test),cl::nullrange,null,&event1); event1.wait(); // at this point, the computation has been made. 110

111 GPGPU In the host program collecting data back // at this point, the computation has been made. cl::event event2; queue.enqueuereadbuffer(gpuoutvec,cl_true,0, SIZE_TEST*sizeof(float),HostOutVec, NULL, &event2); event2.wait(); // HostOutVec contains the results for (int Rows = { for (int c = std::cout std::cout << } 0; Rows < SIZE_TEST/32; Rows++) 0; c <32; c++) << HostOutVec[Rows * 32 + c] << " " ; std::endl; Complete code sample on the website of the course 111

112 GPGPU OpenCL is a multiplateform paradigm The above code sample may be compiled on any computer (having a GPGPU enabled driver) It can even be executed on a... CPU (when no GPU is available) There exist «dummy» drivers that will simply compile and execute the code on the same CPU. Useful to debug and benchmark Performance : factor 2 to 100 in favor of the GPU for vector operations (e.g. on big arrays) Core i7 with 6 cores 3,33 Ghz vs. Nvidia Quadro FX 580 (not very powerful) : 110 s. vs 55 s. On a specialized GPGPU graphic card : Nvidia Tesla C2075 : 11 s. 112

113 Painter s algorithm Idea : display every primitive in the right order Everything «below» is overwritten, like when painting 113

114 Painter s algorithm Idea : display every primitive in the right order Everything «below» is overwritten, like when painting 114

115 Painter s algorithm Idea : display every primitive in the right order Everything «below» is overwritten, like when painting D B A F A E C Amounts to define a topological sorting Find a path in an oriented graph D B E C F ABCDEF ABDCFE CAEBDF

116 Painter s algorithm Impossible if cycles are present... A A B B C C ABC??? 116

117 Painter s algorithm Impossible if cycles are present k a j b,l c m h k f d,g a l b c e o i,n d m h i Solution : cut all! o g e n 117

118 Painter s algorithm Useful when an order is easy to define Works with vector graphics May be very CPU intensive (cut;sort..) Foley et al. 118

119 Painter s algorithm The ordering depends on the point of view Sorting primitives is costly ( nlog(n) to the best ) and have to be done every time the observer moves Primitives must be cut if forming cycles (how to detect?) A response to these drawbacks is the binary space partition tree (BSP Tree) 119

120 BSP Tree Input data : Segments in 2D Triangles in 3D same idea b a c d e 120

121 How to build the BSP Tree (1) b.1 a + + c - b.2 c d e Take one of the segments and define a line cutting the plane in two separate half-planes Classify the other segments with respect to the boundary. If a segment is crossing, partition it and classify its parts On each subdomain, if there are more than one 121 segment, repeat the procedure recursively

122 How to build the BSP Tree (2) b.1 a + b.2 c + c - d e.1 d e.2 e Take one of the segments and define a line cutting the plane in two separate half-planes Classify the other segments with respect to the boundary. If a segment is crossing, partition it and classify its parts On each subdomain, if there are more than one 122 segment, repeat the procedure recursively

123 How to build the BSP Tree (3) - + b.1 a + b.2 c + c d e.1 b.1 a d e.2 e Take one of the segments and define a line cutting the plane in two separate half-planes Classify the other segments with respect to the boundary. If a segment is crossing, partition it and classify its parts On each subdomain, if there are more than one 123 segment, repeat the procedure recursively

124 How to build the BSP Tree (4) - + b.1 a + b.2 c + c d + e.2 e.1 b.1 a d e.2 e b.2 Take one of the segments and define a line cutting the plane in two separate half-planes Classify the other segments with respect to the boundary. If a segment is crossing, partition it and classify its parts On each subdomain, if there are more than one 124 segment, repeat the procedure recursively

125 How to choose the right segment at each step? A random choice is not that bad... Complete algorithm : Let S be a set of line segments (or triangles in 3D) Build(S,BSP) { If (Card(S) <=1) BSP is a tree with only one node that contains the only segment of S or nothing Else { Use a random segment s belonging to S as a cutting line and cut all the other segments S+ = segments belonging to H+ («positive» halfspace) (without s) S- = segments belonging to H- («negative» halfspace) (without s) Call recursively Build(S+,BSP+) Call recursively Build(S-,BSP-) Build a tree with BSP as a root, and BSP+ and BSP- as children. The root contains s. } } 125

126 Use of the BSP Tree How to scan the tree to get the right display order? - + b.1 a + b.2 c + c d + e.2 e.1 b.1 a d b.2 e.2 e Let O c+ a point (the observer) it is clear that entities from c- must be displayed before entities from c, that must be displayed before those of c+. Observer O 126

127 Use of the BSP Tree How to scan the tree to get the right display order? - + b.1 a + b.2 c + c d + e.2 e b a d b.2 e.2 e c- c c+ The same remark arises for c- (then c+) O b.1- thus entities of b.1+ must be displayed before those on b.1, and before those in b.1observer O 127

128 Use of the BSP Tree How to scan the tree to get the right display order? b.1 a + b.2 c + c d + e.2 e b a d b.2 e.2 e a b.1 (b.1-) c c+ For c+ : O d+ thus the order is d- d d+ Observer O 128

129 Use of the BSP Tree How to scan the tree to get the right display order? b.1 a + b.2 c d 8 c b.1 e.2 e a d b.2 e.2 e a b.1 (b.1-) c d- d d+ Observer O 129

130 Use of the BSP Tree How to scan the tree to get the right display order? b.1 a + b.2 c + + d e.2 e.1 d c 7 e.2 e.1 11 b b a 10 a b.1 (b.1-) c e.1 d d+ For d+ : O e.2+ thus order is e.2- e.2 e.2+ Observer O 130

131 Use of the BSP Tree How to scan the tree to get the right display order? b.1 a + b.2 c + + d e.2 e.1 d c b.2 5 b.1 e.2 e a 10 a b.1 (b.1-) c e.1 d b.2 e.2 (e.2+) Final order : a b.1 c e.1 d b.2 e.2 Observer O 131

132 Recusive scanning algorithm Draw(BSP,ViewPoint) { If BSP is a leaf (no children) Draw the primitives contained in BSP Else { Let BSP+ and BSP- - children of BSP If ViewPoint is in H- («negative» halfspace) { Call Draw(BSP+,ViewPoint) Draw the primitives contained in BSP Call Draw(BSP-,ViewPoint) } Else If ViewPoint is in H+ («positive» halfspace) { Call Draw(BSP-,ViewPoint) Draw the primitives contained in BSP Call Draw(BSP+,ViewPoint) } Else (we are exactly on the plane...) { (Draw the primitives contained in BSP) / but not necessary Call Draw(BSP+,ViewPoint) Call Draw(BSP-,ViewPoint) } } } BSP BSP+ BSP- 132

133 The BSP tree is generally not directly used in graphic cards Building a BSP tree is relatively slow (nlogn to the best), and the datastructure is not well adapted to vector/parallel treatment. Z-buffer : see further It can however be used in certain cases in software to ease the work of graphic cards e.g. «FPS» video games where the environnment is mostly fixed «Doom» is an old video game which used this principle. Il can be used for ray-tracing

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6 Surface shading: lights and rasterization Computer Graphics CSE 167 Lecture 6 CSE 167: Computer Graphics Surface shading Materials Lights Rasterization 2 Scene data Rendering pipeline Modeling and viewing

More information

Pipeline and Rasterization. COMP770 Fall 2011

Pipeline and Rasterization. COMP770 Fall 2011 Pipeline and Rasterization COMP770 Fall 2011 1 The graphics pipeline The standard approach to object-order graphics Many versions exist software, e.g. Pixar s REYES architecture many options for quality

More information

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline The graphics pipeline Pipeline and Rasterization CS4620 Lecture 9 The standard approach to object-order graphics Many versions exist software, e.g. Pixar s REYES architecture many options for quality and

More information

Rasterization. CS4620 Lecture 13

Rasterization. CS4620 Lecture 13 Rasterization CS4620 Lecture 13 2014 Steve Marschner 1 The graphics pipeline The standard approach to object-order graphics Many versions exist software, e.g. Pixar s REYES architecture many options for

More information

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16 Rasterization CS 4620 Lecture 16 1 Announcements A3 due on Thu Will send mail about grading once finalized 2 Pipeline overview you are here APPLICATION COMMAND STREAM 3D transformations; shading VERTEX

More information

Pipeline Operations. CS 4620 Lecture 14

Pipeline Operations. CS 4620 Lecture 14 Pipeline Operations CS 4620 Lecture 14 2014 Steve Marschner 1 Pipeline you are here APPLICATION COMMAND STREAM 3D transformations; shading VERTEX PROCESSING TRANSFORMED GEOMETRY conversion of primitives

More information

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11 Pipeline Operations CS 4620 Lecture 11 1 Pipeline you are here APPLICATION COMMAND STREAM 3D transformations; shading VERTEX PROCESSING TRANSFORMED GEOMETRY conversion of primitives to pixels RASTERIZATION

More information

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1 graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1 graphics pipeline sequence of operations to generate an image using object-order processing primitives processed one-at-a-time

More information

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1 graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1 graphics pipeline sequence of operations to generate an image using object-order processing primitives processed one-at-a-time

More information

Pipeline Operations. CS 4620 Lecture 10

Pipeline Operations. CS 4620 Lecture 10 Pipeline Operations CS 4620 Lecture 10 2008 Steve Marschner 1 Hidden surface elimination Goal is to figure out which color to make the pixels based on what s in front of what. Hidden surface elimination

More information

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored. From Vertices to Fragments: Rasterization Reading Assignment: Chapter 7 Frame Buffer Special memory where pixel colors are stored. System Bus CPU Main Memory Graphics Card -- Graphics Processing Unit (GPU)

More information

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621.

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621. CS4620/5620: Lecture 12 Rasterization 1 Announcements Turn in HW 1 PPA 1 out Friday lecture History of graphics PPA 1 in 4621 2 The graphics pipeline The standard approach to object-order graphics Many

More information

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline Last Time? The Traditional Graphics Pipeline Participating Media Measuring BRDFs 3D Digitizing & Scattering BSSRDFs Monte Carlo Simulation Dipole Approximation Today Ray Casting / Tracing Advantages? Ray

More information

CS4620/5620: Lecture 14 Pipeline

CS4620/5620: Lecture 14 Pipeline CS4620/5620: Lecture 14 Pipeline 1 Rasterizing triangles Summary 1! evaluation of linear functions on pixel grid 2! functions defined by parameter values at vertices 3! using extra parameters to determine

More information

CHAPTER 1 Graphics Systems and Models 3

CHAPTER 1 Graphics Systems and Models 3 ?????? 1 CHAPTER 1 Graphics Systems and Models 3 1.1 Applications of Computer Graphics 4 1.1.1 Display of Information............. 4 1.1.2 Design.................... 5 1.1.3 Simulation and Animation...........

More information

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline Last Time? The Traditional Graphics Pipeline Reading for Today A Practical Model for Subsurface Light Transport, Jensen, Marschner, Levoy, & Hanrahan, SIGGRAPH 2001 Participating Media Measuring BRDFs

More information

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU FROM VERTICES TO FRAGMENTS Lecture 5 Comp3080 Computer Graphics HKBU OBJECTIVES Introduce basic implementation strategies Clipping Scan conversion OCTOBER 9, 2011 2 OVERVIEW At end of the geometric pipeline,

More information

Line Drawing. Foundations of Computer Graphics Torsten Möller

Line Drawing. Foundations of Computer Graphics Torsten Möller Line Drawing Foundations of Computer Graphics Torsten Möller Rendering Pipeline Hardware Modelling Transform Visibility Illumination + Shading Perception, Interaction Color Texture/ Realism Reading Angel

More information

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline Final Projects Proposals due Thursday 4/8 Proposed project summary At least 3 related papers (read & summarized) Description of series of test cases Timeline & initial task assignment The Traditional Graphics

More information

CS 130 Exam I. Fall 2015

CS 130 Exam I. Fall 2015 S 3 Exam I Fall 25 Name Student ID Signature You may not ask any questions during the test. If you believe that there is something wrong with a question, write down what you think the question is trying

More information

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines COMP30019 Graphics and Interaction Scan Converting Polygons and Lines Department of Computer Science and Software Engineering The Lecture outline Introduction Scan conversion Scan-line algorithm Edge coherence

More information

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller Line Drawing Introduction to Computer Graphics Torsten Möller / Mike Phillips Rendering Pipeline Hardware Modelling Transform Visibility Illumination + Shading Perception, Color Interaction Texture/ Realism

More information

Hidden surface removal. Computer Graphics

Hidden surface removal. Computer Graphics Lecture Hidden Surface Removal and Rasterization Taku Komura Hidden surface removal Drawing polygonal faces on screen consumes CPU cycles Illumination We cannot see every surface in scene We don t want

More information

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives. D Graphics Primitives Eye sees Displays - CRT/LCD Frame buffer - Addressable pixel array (D) Graphics processor s main function is to map application model (D) by projection on to D primitives: points,

More information

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005 INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Renderer Implementation: Basics and Clipping David Carr Virtual Environments, Fundamentals Spring 2005 Feb-28-05 SMM009, Basics and Clipping 1

More information

Computer Graphics and GPGPU Programming

Computer Graphics and GPGPU Programming Computer Graphics and GPGPU Programming Donato D Ambrosio Department of Mathematics and Computer Science and Center of Excellence for High Performace Computing Cubo 22B, University of Calabria, Rende 87036,

More information

Hidden Surfaces II. Week 9, Mon Mar 15

Hidden Surfaces II. Week 9, Mon Mar 15 University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Hidden Surfaces II Week 9, Mon Mar 15 http://www.ugrad.cs.ubc.ca/~cs314/vjan2010 ews yes, I'm granting the request

More information

Rasterization. COMP 575/770 Spring 2013

Rasterization. COMP 575/770 Spring 2013 Rasterization COMP 575/770 Spring 2013 The Rasterization Pipeline you are here APPLICATION COMMAND STREAM 3D transformations; shading VERTEX PROCESSING TRANSFORMED GEOMETRY conversion of primitives to

More information

Computer Graphics. - Rasterization - Philipp Slusallek

Computer Graphics. - Rasterization - Philipp Slusallek Computer Graphics - Rasterization - Philipp Slusallek Rasterization Definition Given some geometry (point, 2D line, circle, triangle, polygon, ), specify which pixels of a raster display each primitive

More information

CEng 477 Introduction to Computer Graphics Fall 2007

CEng 477 Introduction to Computer Graphics Fall 2007 Visible Surface Detection CEng 477 Introduction to Computer Graphics Fall 2007 Visible Surface Detection Visible surface detection or hidden surface removal. Realistic scenes: closer objects occludes the

More information

Introduction to Visualization and Computer Graphics

Introduction to Visualization and Computer Graphics Introduction to Visualization and Computer Graphics DH2320, Fall 2015 Prof. Dr. Tino Weinkauf Introduction to Visualization and Computer Graphics Visibility Shading 3D Rendering Geometric Model Color Perspective

More information

CS 130 Final. Fall 2015

CS 130 Final. Fall 2015 CS 130 Final Fall 2015 Name Student ID Signature You may not ask any questions during the test. If you believe that there is something wrong with a question, write down what you think the question is trying

More information

Chapter 8: Implementation- Clipping and Rasterization

Chapter 8: Implementation- Clipping and Rasterization Chapter 8: Implementation- Clipping and Rasterization Clipping Fundamentals Cohen-Sutherland Parametric Polygons Circles and Curves Text Basic Concepts: The purpose of clipping is to remove objects or

More information

CS 130 Exam I. Fall 2015

CS 130 Exam I. Fall 2015 CS 130 Exam I Fall 2015 Name Student ID Signature You may not ask any questions during the test. If you believe that there is something wrong with a question, write down what you think the question is

More information

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization. Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática Chap. 2 Rasterization Rasterization Outline : Raster display technology. Basic concepts: pixel, resolution,

More information

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care? Where does a picture come from? Rasterization and Graphics Hardware CS559 Course Notes Not for Projection November 2007, Mike Gleicher Result: image (raster) Input 2D/3D model of the world Rendering term

More information

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic. Shading Models There are two main types of rendering that we cover, polygon rendering ray tracing Polygon rendering is used to apply illumination models to polygons, whereas ray tracing applies to arbitrary

More information

Graphics Pipeline 2D Geometric Transformations

Graphics Pipeline 2D Geometric Transformations Graphics Pipeline 2D Geometric Transformations CS 4620 Lecture 8 1 Plane projection in drawing Albrecht Dürer 2 Plane projection in drawing source unknown 3 Rasterizing triangles Summary 1 evaluation of

More information

The Rasterization Pipeline

The Rasterization Pipeline Lecture 5: The Rasterization Pipeline Computer Graphics and Imaging UC Berkeley CS184/284A, Spring 2016 What We ve Covered So Far z x y z x y (0, 0) (w, h) Position objects and the camera in the world

More information

Visibility: Z Buffering

Visibility: Z Buffering University of British Columbia CPSC 414 Computer Graphics Visibility: Z Buffering Week 1, Mon 3 Nov 23 Tamara Munzner 1 Poll how far are people on project 2? preferences for Plan A: status quo P2 stays

More information

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing EECE 478 Rasterization & Scenes Rasterization Learning Objectives Be able to describe the complete graphics pipeline. Describe the process of rasterization for triangles and lines. Compositing Manipulate

More information

From Ver(ces to Fragments: Rasteriza(on

From Ver(ces to Fragments: Rasteriza(on From Ver(ces to Fragments: Rasteriza(on From Ver(ces to Fragments 3D vertices vertex shader rasterizer fragment shader final pixels 2D screen fragments l determine fragments to be covered l interpolate

More information

Adaptive Point Cloud Rendering

Adaptive Point Cloud Rendering 1 Adaptive Point Cloud Rendering Project Plan Final Group: May13-11 Christopher Jeffers Eric Jensen Joel Rausch Client: Siemens PLM Software Client Contact: Michael Carter Adviser: Simanta Mitra 4/29/13

More information

Realtime 3D Computer Graphics Virtual Reality

Realtime 3D Computer Graphics Virtual Reality Realtime 3D Computer Graphics Virtual Reality From Vertices to Fragments Overview Overall goal recapitulation: Input: World description, e.g., set of vertices and states for objects, attributes, camera,

More information

CS452/552; EE465/505. Clipping & Scan Conversion

CS452/552; EE465/505. Clipping & Scan Conversion CS452/552; EE465/505 Clipping & Scan Conversion 3-31 15 Outline! From Geometry to Pixels: Overview Clipping (continued) Scan conversion Read: Angel, Chapter 8, 8.1-8.9 Project#1 due: this week Lab4 due:

More information

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012 CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012 Announcements Homework project #2 due this Friday, October

More information

Rendering. Basic Math Review. Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers.

Rendering. Basic Math Review. Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers. Rendering Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers Basic Math Review Slope-Intercept Formula For Lines Given a third point on the line: P = (X,Y)

More information

Graphics and Interaction Rendering pipeline & object modelling

Graphics and Interaction Rendering pipeline & object modelling 433-324 Graphics and Interaction Rendering pipeline & object modelling Department of Computer Science and Software Engineering The Lecture outline Introduction to Modelling Polygonal geometry The rendering

More information

Computer Graphics Fundamentals. Jon Macey

Computer Graphics Fundamentals. Jon Macey Computer Graphics Fundamentals Jon Macey jmacey@bournemouth.ac.uk http://nccastaff.bournemouth.ac.uk/jmacey/ 1 1 What is CG Fundamentals Looking at how Images (and Animations) are actually produced in

More information

Rasterization. MIT EECS Frédo Durand and Barb Cutler. MIT EECS 6.837, Cutler and Durand 1

Rasterization. MIT EECS Frédo Durand and Barb Cutler. MIT EECS 6.837, Cutler and Durand 1 Rasterization MIT EECS 6.837 Frédo Durand and Barb Cutler MIT EECS 6.837, Cutler and Durand 1 Final projects Rest of semester Weekly meetings with TAs Office hours on appointment This week, with TAs Refine

More information

Martin Kruliš, v

Martin Kruliš, v Martin Kruliš 1 GPGPU History Current GPU Architecture OpenCL Framework Example Optimizing Previous Example Alternative Architectures 2 1996: 3Dfx Voodoo 1 First graphical (3D) accelerator for desktop

More information

The Rendering Pipeline (1)

The Rendering Pipeline (1) The Rendering Pipeline (1) Alessandro Martinelli alessandro.martinelli@unipv.it 30 settembre 2014 The Rendering Pipeline (1) Rendering Architecture First Rendering Pipeline Second Pipeline: Illumination

More information

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into 2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into the viewport of the current application window. A pixel

More information

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL International Edition Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL Sixth Edition Edward Angel Dave Shreiner Interactive Computer Graphics: A Top-Down Approach with Shader-Based

More information

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal Overview Pipeline implementation I Preliminaries Clipping Line clipping Hidden Surface removal Overview At end of the geometric pipeline, vertices have been assembled into primitives Must clip out primitives

More information

CS559: Computer Graphics. Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008

CS559: Computer Graphics. Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008 CS559: Computer Graphics Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008 Antialising Today Hidden Surface Removal Reading: Shirley ch 3.7 8 OpenGL ch 1 Last time A 2 (x 0 y 0 ) (x 1 y 1 ) P

More information

- Rasterization. Geometry. Scan Conversion. Rasterization

- Rasterization. Geometry. Scan Conversion. Rasterization Computer Graphics - The graphics pipeline - Geometry Modelview Geometry Processing Lighting Perspective Clipping Scan Conversion Texturing Fragment Tests Blending Framebuffer Fragment Processing - So far,

More information

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane Rendering Pipeline Rendering Converting a 3D scene to a 2D image Rendering Light Camera 3D Model View Plane Rendering Converting a 3D scene to a 2D image Basic rendering tasks: Modeling: creating the world

More information

CS Rasterization. Junqiao Zhao 赵君峤

CS Rasterization. Junqiao Zhao 赵君峤 CS10101001 Rasterization Junqiao Zhao 赵君峤 Department of Computer Science and Technology College of Electronics and Information Engineering Tongji University Vector Graphics Algebraic equations describe

More information

Spring 2011 Prof. Hyesoon Kim

Spring 2011 Prof. Hyesoon Kim Spring 2011 Prof. Hyesoon Kim Application Geometry Rasterizer CPU Each stage cane be also pipelined The slowest of the pipeline stage determines the rendering speed. Frames per second (fps) Executes on

More information

Display Technologies: CRTs Raster Displays

Display Technologies: CRTs Raster Displays Rasterization Display Technologies: CRTs Raster Displays Raster: A rectangular array of points or dots Pixel: One dot or picture element of the raster Scanline: A row of pixels Rasterize: find the set

More information

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura Computer Graphics Lecture 9 Hidden Surface Removal Taku Komura 1 Why Hidden Surface Removal? A correct rendering requires correct visibility calculations When multiple opaque polygons cover the same screen

More information

Spring 2009 Prof. Hyesoon Kim

Spring 2009 Prof. Hyesoon Kim Spring 2009 Prof. Hyesoon Kim Application Geometry Rasterizer CPU Each stage cane be also pipelined The slowest of the pipeline stage determines the rendering speed. Frames per second (fps) Executes on

More information

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students) TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students) Saturday, January 13 th, 2018, 08:30-12:30 Examiner Ulf Assarsson, tel. 031-772 1775 Permitted Technical Aids None, except

More information

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object... Rendering approaches 1.image-oriented foreach pixel... 2.object-oriented foreach object... geometry 3D rendering pipeline image 3D graphics pipeline Vertices Vertex processor Clipper and primitive assembler

More information

Institutionen för systemteknik

Institutionen för systemteknik Code: Day: Lokal: M7002E 19 March E1026 Institutionen för systemteknik Examination in: M7002E, Computer Graphics and Virtual Environments Number of sections: 7 Max. score: 100 (normally 60 is required

More information

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside CS230 : Computer Graphics Lecture 4 Tamar Shinar Computer Science & Engineering UC Riverside Shadows Shadows for each pixel do compute viewing ray if ( ray hits an object with t in [0, inf] ) then compute

More information

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz Computing Visibility BSP Trees Ray Casting Depth Buffering Quiz Power of Plane Equations We ve gotten a lot of mileage out of one simple equation. Basis for D outcode-clipping Basis for plane-at-a-time

More information

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves CSC 418/2504: Computer Graphics Course web site (includes course information sheet): http://www.dgp.toronto.edu/~elf Instructor: Eugene Fiume Office: BA 5266 Phone: 416 978 5472 (not a reliable way) Email:

More information

Graphics Hardware and Display Devices

Graphics Hardware and Display Devices Graphics Hardware and Display Devices CSE328 Lectures Graphics/Visualization Hardware Many graphics/visualization algorithms can be implemented efficiently and inexpensively in hardware Facilitates interactive

More information

The Graphics Pipeline

The Graphics Pipeline The Graphics Pipeline Ray Tracing: Why Slow? Basic ray tracing: 1 ray/pixel Ray Tracing: Why Slow? Basic ray tracing: 1 ray/pixel But you really want shadows, reflections, global illumination, antialiasing

More information

3D Rasterization II COS 426

3D Rasterization II COS 426 3D Rasterization II COS 426 3D Rendering Pipeline (for direct illumination) 3D Primitives Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Viewport Transformation

More information

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series PG Examination 2013-14 COMPUTER GAMES DEVELOPMENT CMPSME27 Time allowed: 2 hours Answer any THREE questions. (40 marks each) Notes are

More information

Graphics (Output) Primitives. Chapters 3 & 4

Graphics (Output) Primitives. Chapters 3 & 4 Graphics (Output) Primitives Chapters 3 & 4 Graphic Output and Input Pipeline Scan conversion converts primitives such as lines, circles, etc. into pixel values geometric description a finite scene area

More information

OXFORD ENGINEERING COLLEGE (NAAC Accredited with B Grade) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS

OXFORD ENGINEERING COLLEGE (NAAC Accredited with B Grade) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS OXFORD ENGINEERING COLLEGE (NAAC Accredited with B Grade) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS YEAR/SEM.: III/V STAFF NAME: T.ELANGOVAN SUBJECT NAME: Computer Graphics SUB. CODE:

More information

Scan Conversion. Drawing Lines Drawing Circles

Scan Conversion. Drawing Lines Drawing Circles Scan Conversion Drawing Lines Drawing Circles 1 How to Draw This? 2 Start From Simple How to draw a line: y(x) = mx + b? 3 Scan Conversion, a.k.a. Rasterization Ideal Picture Raster Representation Scan

More information

COMP371 COMPUTER GRAPHICS

COMP371 COMPUTER GRAPHICS COMP371 COMPUTER GRAPHICS LECTURE 14 RASTERIZATION 1 Lecture Overview Review of last class Line Scan conversion Polygon Scan conversion Antialiasing 2 Rasterization The raster display is a matrix of picture

More information

Topic #1: Rasterization (Scan Conversion)

Topic #1: Rasterization (Scan Conversion) Topic #1: Rasterization (Scan Conversion) We will generally model objects with geometric primitives points, lines, and polygons For display, we need to convert them to pixels for points it s obvious but

More information

MET71 COMPUTER AIDED DESIGN

MET71 COMPUTER AIDED DESIGN UNIT - II BRESENHAM S ALGORITHM BRESENHAM S LINE ALGORITHM Bresenham s algorithm enables the selection of optimum raster locations to represent a straight line. In this algorithm either pixels along X

More information

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18 CS 498 VR Lecture 18-4/4/18 go.illinois.edu/vrlect18 Review and Supplement for last lecture 1. What is aliasing? What is Screen Door Effect? 2. How image-order rendering works? 3. If there are several

More information

CS 563 Advanced Topics in Computer Graphics QSplat. by Matt Maziarz

CS 563 Advanced Topics in Computer Graphics QSplat. by Matt Maziarz CS 563 Advanced Topics in Computer Graphics QSplat by Matt Maziarz Outline Previous work in area Background Overview In-depth look File structure Performance Future Point Rendering To save on setup and

More information

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner GLOBAL EDITION Interactive Computer Graphics A Top-Down Approach with WebGL SEVENTH EDITION Edward Angel Dave Shreiner This page is intentionally left blank. Interactive Computer Graphics with WebGL, Global

More information

Previously... contour or image rendering in 2D

Previously... contour or image rendering in 2D Volume Rendering Visualisation Lecture 10 Taku Komura Institute for Perception, Action & Behaviour School of Informatics Volume Rendering 1 Previously... contour or image rendering in 2D 2D Contour line

More information

TSBK03 Screen-Space Ambient Occlusion

TSBK03 Screen-Space Ambient Occlusion TSBK03 Screen-Space Ambient Occlusion Joakim Gebart, Jimmy Liikala December 15, 2013 Contents 1 Abstract 1 2 History 2 2.1 Crysis method..................................... 2 3 Chosen method 2 3.1 Algorithm

More information

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches: Surface Graphics Objects are explicitely defined by a surface or boundary representation (explicit inside vs outside) This boundary representation can be given by: - a mesh of polygons: 200 polys 1,000

More information

Graphics for VEs. Ruth Aylett

Graphics for VEs. Ruth Aylett Graphics for VEs Ruth Aylett Overview VE Software Graphics for VEs The graphics pipeline Projections Lighting Shading VR software Two main types of software used: off-line authoring or modelling packages

More information

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading: Reading Required: Watt, Section 5.2.2 5.2.4, 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading: 18. Projections and Z-buffers Foley, et al, Chapter 5.6 and Chapter 6 David F. Rogers

More information

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops. OpenGl Pipeline Individual Vertices Transformed Vertices Commands Processor Per-vertex ops Primitive assembly triangles, lines, points, images Primitives Fragments Rasterization Texturing Per-fragment

More information

Homework #2. Shading, Ray Tracing, and Texture Mapping

Homework #2. Shading, Ray Tracing, and Texture Mapping Computer Graphics Prof. Brian Curless CSE 457 Spring 2000 Homework #2 Shading, Ray Tracing, and Texture Mapping Prepared by: Doug Johnson, Maya Widyasari, and Brian Curless Assigned: Monday, May 8, 2000

More information

CS451Real-time Rendering Pipeline

CS451Real-time Rendering Pipeline 1 CS451Real-time Rendering Pipeline JYH-MING LIEN DEPARTMENT OF COMPUTER SCIENCE GEORGE MASON UNIVERSITY Based on Tomas Akenine-Möller s lecture note You say that you render a 3D 2 scene, but what does

More information

Shadows in the graphics pipeline

Shadows in the graphics pipeline Shadows in the graphics pipeline Steve Marschner Cornell University CS 569 Spring 2008, 19 February There are a number of visual cues that help let the viewer know about the 3D relationships between objects

More information

Computer Graphics 7 - Rasterisation

Computer Graphics 7 - Rasterisation Computer Graphics 7 - Rasterisation Tom Thorne Slides courtesy of Taku Komura www.inf.ed.ac.uk/teaching/courses/cg Overview Line rasterisation Polygon rasterisation Mean value coordinates Decomposing polygons

More information

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k Idea 1 m 0 candidates last pixel Note that line could have passed through any part of this pixel Decision variable: d = x(a-b) d is an integer d < 0 use upper pixel d > 0 use lower pixel Incremental Form

More information

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14 Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14 Scan Converting Lines, Circles and Ellipses Hello everybody, welcome again

More information

CS 464 Review. Review of Computer Graphics for Final Exam

CS 464 Review. Review of Computer Graphics for Final Exam CS 464 Review Review of Computer Graphics for Final Exam Goal: Draw 3D Scenes on Display Device 3D Scene Abstract Model Framebuffer Matrix of Screen Pixels In Computer Graphics: If it looks right then

More information

EF432. Introduction to spagetti and meatballs

EF432. Introduction to spagetti and meatballs EF432 Introduction to spagetti and meatballs CSC 418/2504: Computer Graphics Course web site (includes course information sheet): http://www.dgp.toronto.edu/~karan/courses/418/fall2015 Instructor: Karan

More information

Deferred Rendering Due: Wednesday November 15 at 10pm

Deferred Rendering Due: Wednesday November 15 at 10pm CMSC 23700 Autumn 2017 Introduction to Computer Graphics Project 4 November 2, 2017 Deferred Rendering Due: Wednesday November 15 at 10pm 1 Summary This assignment uses the same application architecture

More information

3D Programming. 3D Programming Concepts. Outline. 3D Concepts. 3D Concepts -- Coordinate Systems. 3D Concepts Displaying 3D Models

3D Programming. 3D Programming Concepts. Outline. 3D Concepts. 3D Concepts -- Coordinate Systems. 3D Concepts Displaying 3D Models 3D Programming Concepts Outline 3D Concepts Displaying 3D Models 3D Programming CS 4390 3D Computer 1 2 3D Concepts 3D Model is a 3D simulation of an object. Coordinate Systems 3D Models 3D Shapes 3D Concepts

More information

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space. Utah School of Computing Spring 13 Class of Algorithms Lecture Set Visible Surface Determination CS56 Computer Graphics From Rich Riesenfeld Spring 13 Object (Model) Space Algorithms Work in the model

More information

CS 498 VR. Lecture 19-4/9/18. go.illinois.edu/vrlect19

CS 498 VR. Lecture 19-4/9/18. go.illinois.edu/vrlect19 CS 498 VR Lecture 19-4/9/18 go.illinois.edu/vrlect19 Review from previous lectures Image-order Rendering and Object-order Rendering Image-order Rendering: - Process: Ray Generation, Ray Intersection, Assign

More information