Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera Anthony Steed University College London.

Similar presentations


Presentation on theme: "Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera Anthony Steed University College London."— Presentation transcript:

1 Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera Anthony Steed University College London

2 Overview n Basic Maths –Points –Vectors n Simple Camera –Scenes with spheres –COP on +z n Local illumination –Ambient –Diffuse –Specular

3 Overview n Basic Maths –Points –Vectors n Simple Camera –Scenes with spheres –COP on +z n Local illumination –Ambient –Diffuse –Specular

4 Basic Maths n In computer graphics we need mathematics both for describing our scenes and also for performing operations on it, such as projecting and transforming it. n Coordinate systems (right- and left- handed), serves as a reference point. n 3 axis labelled x, y, z at right angles.

5 Co-ordinate Systems X Y Z Right-Handed System (Z comes out of the screen) X Y Z Left-Handed System (Z goes in to the screen)

6 Points, P (x, y, z) n Gives us a position in relation to the origin of our coordinate system

7 Vectors, V (x, y, z) n Is a direction in 3D space n Points != Vectors –Point – Point = Vector –Vector+Vector = Vector –Point + Vector = Point –Point + Point = ?

8 Vectors, V (x, y, z) v w v + w Vector addition sum v + w v 2v (-1)v (1/2)V Scalar multiplication of vectors (they remain parallel) v w Vector difference v - w = v + (-w) v w v - w x y Vector OP P O

9 Vectors V n Length (modulus) of a vector V (x, y, z) –|V| = n A unit vector –

10 Dot Product n a · b = |a| |b| cos   cos  = a · b/ |a| |b| n a · b = x a ·x b + y a ·y b + z a ·z b n what happens when the vectors are unit n if dot product == 0 or == 1? n This is purely a scalar number not a vector

11 Cross Product n The result is not a scalar but a vector which is normal to the plane of the other 2 n direction is found using the determinant –i(y v z u -z v y u ), -j(x v z u - z v x u ), k(x v y u - y v x u ) n size is a x b = |a||b|sin  n cross product of vector with it self is null

12 Parametric equation of a line (ray) Given two points P 0 = (x 0, y 0, z 0 ) and P 1 = (x 1, y 1, z 1 ) the line passing through them can be expressed as: P(t) = P 0 + t(P 1 - P 0 ) x(t) = x 0 + t(x 1 - x 0 ) y(t) = y 0 + t(y 1 - y 0 ) z(t) = z 0 + t(z 1 - z 0 ) = With -  < t < 

13 Equation of a sphere a b c hypotenuse a 2 + b 2 = c 2 P xpxp ypyp (0, 0) r x 2 + y 2 = r 2 n Pythagoras Theorem: n Given a circle through the origin with radius r, then for any point P on it we have:

14 Equation of a sphere  If the circle is not centered on the origin: (0, 0) P xpxp ypyp r xcxc ycyc a b a b a 2 + b 2 = r 2 We still have but a = x p - x c b = y p - y c So for the general case (x- x c ) 2 + ( y- y c ) 2 = r 2 (x p,y p ) (x c,y c )

15 Equation of a sphere  Pythagoras theorem generalises to 3D giving a 2 + b 2 + c 2 = d 2 Based on that we can easily prove that the general equation of a sphere is: (x- x c ) 2 + ( y- y c ) 2 + ( z- z c ) 2 = r 2 and at origin: x 2 + y 2 + z 2 = r 2

16 Overview n Basic Maths –Points –Vectors n Simple Camera –Scenes with spheres –COP on +z n Local illumination –Ambient –Diffuse –Specular

17 Simple Camera (Cross Section) Z-Z Y d COP y max y min

18 View From the Camera (x min, y min ) (x max, y max )

19 Forming the Rays n Map screen pixels (M by N window) to points in camera view plane (0,0) (M-1, N-1) (x min, y min ) (x max, y max )

20 Forming the Rays n Consider pixel i,j n It corresponds to a rectangle width = (xmax-xmin)/M height = (ymax-ymin)/N n Our ray goes through the center of the pixel n Thus the ray goes through the point (xmin + width*(i+0.5), ymin + height*(j+0.5), 0.0)

21 Forming the Rays n Thus the ray from the COP through pixel i,j is defined by p(t) = (x(t), y(t), z(t)) = ( t*(xmin + width*(i+0.5)), t*(ymin + height*(j+0.5)), t*(ymin + height*(j+0.5)), t*d-d) t*d-d)

22 Ray Casting n Intersection of Sphere and line (sphere at origin) n Substitute the ray equation in the sphere equation and solve! n Get an equation in t of the form At 2 + 2Bt + C = 0 At 2 + 2Bt + C = 0

23 Ray Casting If b 2 – AC < 0 then the ray doesn’t intersect the sphere. If b 2 -AC = 0 the ray graze (is tangent to the sphere) If b 2 – AC > 0 then there are two roots given by t = (-b   (b 2 – AC))/A chose the highest value one (the one closest to the COP)

24 Ray Casting n Intersection of Sphere and line (general case) –Sphere is centred at (a,b,c) –Translate the start of the ray by (-a,-b,-c) –Proceed as before

25 The Image - Detection

26 Overview n Basic Maths –Points –Vectors n Simple Camera –Scenes with spheres –COP on +z n Local illumination –Ambient –Diffuse –Specular

27 Ambient Light n Approximation to global illumination –Each object is illuminated to a certain extent by “stray” light –Constant across a whole object n Often used simply to make sure everything is lit, just in case it isn’t struck by light direct from a light source

28 Ambient Light n Ambient light usually set for whole scene (I a ) n Each object reflects only a proportion of that (k a ) n So far then I r = k a I a

29 Lighting Equation #1 But we use RGB so I r, red = k a,red I a,red I r,green = k a,green I a,green I r,blue = k a,blue I a,blue

30 The Image - Ambient

31 Lambert’s Law n Reflected intensity is proportional to cos  n L is the direction to the light n N is the surface normal

32 Diffuse Light n The normalised intensity of the light incident on the surface due to a ray from a light source n The light reflected due to Lambert’s law n The proportion of light reflected rather than absorbed (k d )

33 Lighting Equation #2 n Ambient and diffuse components n Again k d is wavelength dependent and we work with k d,red k d,green and k d, blue I r = k a I a + k d I i (n.l)

34 Multiple Lights? n Add the diffuse terms n I i,j is the incoming intensity of light j n l j is the vector to light j I r = k a I a +  k d I i,j (n.l j ) j =1 m

35 The Image - Diffuse

36 Perfect Specularity n Would almost never see the specular highlight  

37 Imperfect Specularity (Phong) n E is the direction to the eye n N is the normal n L is the direction to the light n H bisects E and L

38 Specular Component n m is the power of the light –High m implies smaller specular highlight –Low m makes the highlight more blurred k s I i (h.n) m

39 Lighting Equation #3 n Ambient, diffuse&specular components n Again if there are multiple lights there is a sum of the specular and diffuse components for each light (This is the time to worry about clamping values to 0,1 required for monitor display) I r = k a I a + I i (k d (n.l) + k s (h.n) m )

40 The Image - Specular

41 Conclusions n We can now draw images –Forming rays from the camera –Intersecting those rays with objects in the scene –Colouring the pixels n Immediate work required –More interesting scenes –A useful camera n At the moment we must move the objects in front of the camera to be able to see them


Download ppt "Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera Anthony Steed University College London."

Similar presentations


Ads by Google