1 / 41

Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera

Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera. Anthony Steed University College London. Overview. Basic Maths Points Vectors Simple Camera Scenes with spheres COP on +z Local illumination Ambient Diffuse Specular. Overview. Basic Maths Points Vectors

nau
Download Presentation

Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera

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. Introduction to 3D GraphicsLecture 2: Mathematics of the Simple Camera Anthony Steed University College London

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

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

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

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

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

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

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

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

  10. Dot Product • a · b = |a| |b| cos cos = a · b/ |a| |b| • a · b = xa ·xb + ya ·yb + za ·zb • what happens when the vectors are unit • if dot product == 0 or == 1? • This is purely a scalar number not a vector

  11. Cross Product • The result is not a scalar but a vector which is normal to the plane of the other 2 • direction is found using the determinant • i(yvzu -zvyu), -j(xvzu - zvxu), k(xvyu - yvxu) • size is a x b = |a||b|sin • cross product of vector with it self is null

  12. x(t) = x0 + t(x1 -x0) y(t) = y0 + t(y1 -y0) z(t) = z0 + t(z1 -z0) Parametric equation of a line (ray) Given two points P0 = (x0, y0, z0) and P1 = (x1, y1, z1) the line passing through them can be expressed as: P(t) = P0 + t(P1 -P0) = With -  < t < 

  13. hypotenuse c b a P r yp xp (0, 0) Equation of a sphere • Pythagoras Theorem: • Given a circle through the origin with radius r, then for any point P on it we have: a2 + b2 = c2 x2 + y2 = r2

  14. (x-xc)2 + (y-yc)2 = r2 So for the general case Equation of a sphere • If the circle is not centered on the origin: We still have yp P (xp,yp) a2 + b2 = r2 r b b but yc a (xc,yc) a = xp-xc b = yp-yc xp xc (0, 0) a

  15. Equation of a sphere • Pythagoras theorem generalises to 3D giving Based on that we can easily a2 + b2 + c2 = d2 prove that the general equation of a sphere is: (x-xc)2 + (y-yc)2 + (z-zc)2 = r2 x2 + y2 + z2 = r2 and at origin:

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

  17. Simple Camera (Cross Section) Y d ymax Z -Z COP ymin

  18. View From the Camera (xmax, ymax) (xmin, ymin)

  19. Forming the Rays • Map screen pixels (M by N window) to points in camera view plane (xmax, ymax) (M-1, N-1) (0,0) (xmin, ymin)

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

  21. Forming the Rays • 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*d-d)

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

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

  24. Ray Casting • 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 • Basic Maths • Points • Vectors • Simple Camera • Scenes with spheres • COP on +z • Local illumination • Ambient • Diffuse • Specular

  27. Ambient Light • Approximation to global illumination • Each object is illuminated to a certain extent by “stray” light • Constant across a whole object • 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 • Ambient light usually set for whole scene (Ia) • Each object reflects only a proportion of that (ka) • So far then Ir = kaIa

  29. Lighting Equation #1 But we use RGB so Ir, red = ka,redIa,red Ir,green = ka,greenIa,green Ir,blue = ka,blueIa,blue

  30. The Image - Ambient

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

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

  33. Lighting Equation #2 • Ambient and diffuse components • Again kd is wavelength dependent and we work with kd,red kd,green and kd, blue Ir = kaIa + kdIi (n.l)

  34. Multiple Lights? • Add the diffuse terms • Ii,j is the incoming intensity of light j • lj is the vector to light j m Ir = kaIa + kdIi,j (n.l j) j =1

  35. The Image - Diffuse

  36. Perfect Specularity • Would almost never see the specular highlight  

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

  38. Specular Component • m is the power of the light • High m implies smaller specular highlight • Low m makes the highlight more blurred ksIi (h.n)m

  39. Lighting Equation #3 • Ambient, diffuse&specular components • 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) Ir = kaIa + Ii (kd (n.l) + ks(h.n)m )

  40. The Image - Specular

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

More Related