introduction to 3d graphics lecture 2 mathematics of the simple camera
Download
Skip this Video
Download Presentation
Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera

Loading in 2 Seconds...

play fullscreen
1 / 41

Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera - PowerPoint PPT Presentation


  • 99 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera' - nau


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introduction to 3d graphics lecture 2 mathematics of the simple camera

Introduction to 3D GraphicsLecture 2: Mathematics of the Simple Camera

Anthony Steed

University College London

overview
Overview
  • Basic Maths
    • Points
    • Vectors
  • Simple Camera
    • Scenes with spheres
    • COP on +z
  • Local illumination
    • Ambient
    • Diffuse
    • Specular
overview1
Overview
  • Basic Maths
    • Points
    • Vectors
  • Simple Camera
    • Scenes with spheres
    • COP on +z
  • Local illumination
    • Ambient
    • Diffuse
    • Specular
basic maths
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.
co ordinate systems
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)

points p x y z
Points, P (x, y, z)
  • Gives us a position in relation to the origin of our coordinate system
vectors v x y z
Vectors, V (x, y, z)
  • Is a direction in 3D space
  • Points != Vectors
    • Point – Point = Vector
    • Vector+Vector = Vector
    • Point + Vector = Point
    • Point + Point = ?
vectors v x y z1

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

vectors v
Vectors V
  • Length (modulus) of a vector V (x, y, z)
    • |V| =
  • A unit vector
dot product
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
cross product
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
parametric equation of a line ray

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 < 

equation of a sphere

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

equation of a sphere1

(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

equation of a sphere2
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:

overview2
Overview
  • Basic Maths
    • Points
    • Vectors
  • Simple Camera
    • Scenes with spheres
    • COP on +z
  • Local illumination
    • Ambient
    • Diffuse
    • Specular
view from the camera
View From the Camera

(xmax, ymax)

(xmin, ymin)

forming the rays
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)

forming the rays1
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)

forming the rays2
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)

ray casting
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

ray casting1
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)

ray casting2
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
overview3
Overview
  • Basic Maths
    • Points
    • Vectors
  • Simple Camera
    • Scenes with spheres
    • COP on +z
  • Local illumination
    • Ambient
    • Diffuse
    • Specular
ambient light
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
ambient light1
Ambient Light
  • Ambient light usually set for whole scene (Ia)
  • Each object reflects only a proportion of that (ka)
  • So far then

Ir = kaIa

lighting equation 1
Lighting Equation #1

But we use RGB so

Ir, red = ka,redIa,red

Ir,green = ka,greenIa,green

Ir,blue = ka,blueIa,blue

lambert s law
Lambert’s Law
  • Reflected intensity is proportional to cos 
  • L is the direction to the light
  • N is the surface normal
diffuse light
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)
lighting equation 2
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)

multiple lights
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

perfect specularity
Perfect Specularity
  • Would almost never see the specular highlight

imperfect specularity phong
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
specular component
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

lighting equation 3
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 )

conclusions
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
ad