The globe.cpp demo - PowerPoint PPT Presentation

About This Presentation
Title:

The globe.cpp demo

Description:

Globe: a sphere of radius 100, center=(0,0,0) Table: a plane tangent to sphere at (0,-100,0) ... Exercise: Add color to the globe and table ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 21
Provided by: ProfessorA
Learn more at: https://www.cs.usfca.edu
Category:
Tags: cpp | demo | globe

less

Transcript and Presenter's Notes

Title: The globe.cpp demo


1
The globe.cpp demo
  • An introduction to the application of basic
    raytracing principles

2
Setting the scene
  • Our example depicts a sphere and a plane
  • A single monochromatic point light-source
  • Objects are
  • Globe a sphere of radius 100, center(0,0,0)
  • Table a plane tangent to sphere at (0,-100,0)
  • Light a point source located at (600,800,-800)
  • Eye a viewer who is positioned at (0,0,-1800)
  • Poly a square, for tables edges (side 670)

3
Positioning the screen-image
  • Graphics display-mode is 259 ( 0x103)
  • int hres 800, vres 600
  • unsigned char vram (256 colors)
  • Move coordinate-origin to screens center
  • float transX hres/2, transY vres/2
  • Magnify image by 25 (i.e., divide by 0.8)
  • float scaleX 0.8, transY -0.8
  • scale-factor for Y negative flips up/down

4
Illumination coefficients
  • 8bpp color allows 64 different intensities
  • We apportioned these as follows
  • Iambient 16.0 ( 1/4 of range 64)
  • Idiffuse 24 .0 ( 3/8 of range 64)
  • Ispecular 24.0 ( 3/8 of range 64)
  • We decided proportions by trial-and-error

ambient
diffuse
specular
Maximum of 64 distinct intensity-levels
5
Front view
light-source
y-axis
globe
x-axis
table
6
Top view
light
globe
x-axis
table
eye
z-axis
7
Light-beam hits table
light
eye
table
screen-pixel
view-plane
8
Light-beam hits globe
light
screen-pixel
eye
table
view-plane
shadow
9
Ambient intensity
  • The idea of ambient light is that its a low
    level of background illumination, traveling in
    all directions with equal intensity
  • We model this component as a constant

10
Diffuse reradiation
  • The idea is that the light rays which arent
    absorbed when they hit a matte surface are
    redirected away from that surface in a manner
    which obeys Lamberts Law
  • Intensity is proportional to area subtended

11
Illustration of Law
this angle is smaller (so less energy reaches
pixel)
light-energy radiates outward in all directions
pixels of equal area
this angle is larger (so more energy reaches
pixel)
12
Area proportional to cosine
surface-normal
ray-direction
pixel-area
vector-angle
A bigger vector-angle would have a smaller cosine
13
Diffuse reflectivity
Fewer rays are incident with a given surface-area
if the surface is tilted at an angle with respect
to the incoming lights direction
A
A cos ?
?
So where there is less light-energy that reaches
a surface, there will be less light-energy for
this surface to reradiate
14
Specular reflection
  • The idea is that a surface thats shiny will
    reflect light-rays in roughly the same way as a
    mirror does, obeying Fermats Law (but also
    allowing for some scallering)
  • Angle-of-incidence Angle-of-reflection

mirror-like surface
angle-of-incidence
angle-of-reflection
15
Reflecting a vector
r s 2p
n
surface-normal
vector toward light-source
vector reflected off shiny surface
s
r
p
surface
p is projection of s along n
16
Vector-projection
  • From elementary linear algebra
  • p projn( s ) ( sn / nn )n
  • So we can compute r from s and n r -s
    2( sn / nn )n

17
Scattering
semi-shiny surface
very shiny suface
18
Use a power of the cosine
  • Remember that (for acute angles) we have 0 lt
    cos(?) lt 1
  • So powers of cos(?) are between 0 and 1
  • But higher powers have sharper graphs!
  • We can model the shinyness of surfaces by the
    power of the cosine we choose the higher the
    power, the shininer the surface

19
Summing up
  • Intensity of achromatic light at a pixel is a sum
    of three illumination components intensity
    ambient diffuse specular
  • ambient (this will just be a constant)
  • diffuse (proportional to dot-product sn)
  • specular (proportional to cos5(?)(rrse)5)

20
In-class experimentation
  • The globe.cpp demo-program produces a
    monochromatic (i.e., gray-scale) image
  • A range of the DAC controllers 256 color
    registers is programmed for 64 different
    intensities of white illunimation
  • But we can also create varying intensities of
    some other RGB color-combinations
  • Exercise Add color to the globe and table
Write a Comment
User Comments (0)
About PowerShow.com