CS488 - Introduction to Computer Graphics - Lecture 10
Public Service Announcements
- Assignment 3 due 18 June, one week from today.
- PDF that covers colour
Hierarchical Models
What we have
How to render any polygon anywhere
- Put the polygon where you want it to be in world coordinates
- Transform to view coordinates
- Perspective transform
- Clip in normalized device coordinates.
- Scan convert each polygon in any order, using z-buffer to remove
occuded pixels
What we want to have
Objects made of polygons that we can feed into the rendering pipeline.
- Making the objects is called modelling.
- Here we discuss the data structures and algorithms associated with
hierarchical modelling
- Hierarchical is a synonym for `divide and conquer'.
Argument by example
- A Forest consists of many trees, each at a different location, scale
and orientation
- Use only two or three different trees, each defined with respect to
a tree-centred coordinate system (TCS)
- With respect to the world coordinate system (WCS) define, for each
tree, a matrix that expressed the relationship between the TCS and
the WCS.
- Each Tree has a Trunk (in a TkCS) and a Root (in an RCS)
- Trunks and roots come in various versions
- Choose one trunk and one root, making sure that they are
compatible.
- Define matrices that define RCS and TkCS with respect to the
TCS
- The matrices may include scaling.
- Each Trunk has several branches, each with a BCS
- Branches come in various versions
- Choose branches of compatible versions.
- Define a BCS/TkCS matrix for each.
- The matrices may include scaling.
- Each branch has many twigs, each having a TgCS
- Choose a few twigs from the various versions of twigs
- Define a TgCS/BCS for each
- The matrices may include scaling
- Each twig has several leaves, LCS
- Leaves come in a variety of shapes
- Choose some leaves that have compatible shapes.
- Define the LCS/TgCS of each
Aside. It seems to me that we have, rather glibly, required a lot of
choosing and defining
- We defined one polygon mesh for each version of a tree element: 5(types
of element) x 10(versions per type) = 50 meshes to model.
- We choose a set of each type from the versions: 10(elements per set) x
10(choices per element) = 100
- We define a matrix for each element: 1(trunk) x 1(root) x 10(branches)
x 10(twigs) x 10(leaves) = 1000
This should seem like a lot of work, because it is. Remember this when I
tell you that your project has too much modelling.
This seems like work a computer could do better than a human. Much
research has been done with -- usually -- disappointing results. We have not
yet found good algorithms that put in the right amounts of randomness and
order. The human visual system seems to be very finally tuned to expect a
correct
How do we render a leaf?
- Transform points from LCS to TgCS (MLTg)
- Transform points from TgCS to BCS (MTgB)
- Transform points from BCS to TkCS (MBTk)
- Transform points from TkCS to TCS (MTkT)
- Transform points from TCS to WCS (MTW)
- Transform points to view coordinates (MWV)
- Perspective Transform points to the image plane (MVIp)
Make up the matrix M = MVIp * MWV * MTW * MTkT * MBTk * MTgB * MLTg1
- and use it on each point (probably polygon vertex) in the leaf
How do we render the second leaf?
- Multiply again: M2 = MVIp * MWV * MTW * MTkT * MBTk * MTgB * MLTg2
Too much work.
- Do less work: M2 = M * (MLTg1)^-1 * MLTg2
Accumulating round-off error.
- Keep around
- MVIp * MWV * MTW * MTkT * MBTk * MTgB,
- MVIp * MWV * MTW * MTkT * MBTk,
- MVIp * MWV * MTW * MTkT,
- MVIp * MWV * MTW,
- MVIp * MWV
We like this approach because we can do it with a stack.
Scene Graph
Render a scene using a matrix stack.
Render a forest
proc forest( )
unitMatrix( )
multMatrix(MVP)
multMatrix(MWV)
pushMatrix( )
multMatrix(MTW1)
tree1( )
popMatrix( )
pushMatrix( )
multMatrix(MTW2)
tree2( )
popMatrix( )
etc.
Render trees
proc tree1( )
pushMatrix( )
multMatrix(MTTk11)
trunk1( )
popMatrix( )
pushMatrix( )
multMatrix(MTR12)
root2( )
popMatrix( )
proc tree2( )
pushMatrix( )
multMatrix(MTTk21)
trunk1( )
popMatrix( )
pushMatrix( )
multMatrix(MTR22)
root2( )
...
We don't want always to write a program, so we encapsulate the program as
data.
Traverse a DAG
traverse( root )
proc traverse( node ) {
if ( drawable( node ) ) {
draw( node )
}
for each child {
traverse( child )
}
return
}
Build a DAG
- This is done by a modelling tool, or program
- DAG lets us use whole subtrees more than once.
scene = gr.transform( )
tree1 = gr.transform( )
gr.add_child( tree1, scene )
gr.set_transform( tree1, gr.translation(...)*gr.rotation(...)*...)
...
root = gr.transform( )
rootshape = gr.cylinder( )
gr.add_child( root, tree1 )
gr.set_transform( root, gr.scaling(...)*... )
gr.addchild( rootshape, root )
gr.setmaterial( rootshape, rough_bark )
trunk = gr.transform( )
gr.add_child( trunk, tree1 )
gr.set_transform( trunk, gr.scaling(...)*... )
trunkshape = gr.cylinder( )
gr.add_child( trunkshape, trunk )
gr.add_material( trunkshape, roughbark )
// The code below is repeated for each branch
branch = gr_transform( )
gr.add_child( branch, trunk )
gr.set_transform( branch, gr... )
branchshape = gr_cylinder( )
gr.add_child( branch, branchshape)
gr.setmaterial( branchshape, mediumbark )
twig = grtransform( )
...
column1 = gr.transform( )
gr.add_child( temple1, column1 )
gr.set_transform( column1, gr.translation(...)*gr.scaling(...)
...
which generates the DAG:
forest
|
tree1------------------------------tree2----------tree3--...
| | |
trunk1--root1 trunk2--root2
| |
branch11--branch12--branch13--... branch21--...
| |
twig111--twig112--twig113--... twig211--...
| |
leaf1111--leaf1112--leaf1113--... leaf2111--...
Colour -- pdf
What is needed for colour?
- An eye.
- A source of illumination.
- A surface.
How is colour created?
- Source of illumination emits light (photons of differing
wavelength).
- Surface modifies light.
- Eye compares surfaces and notices different modifications.
How do we represent colour?
- As some kind of sum of photons?
- As a distribution of photons (over wavelength)?
- As a ratio of distributions of photons?
To the rescue,
But,
- Only approximately correct
- but to within 1-2% for most humans,
- only describes matching, not appearance
- Doesn't describe non-additive colour mixture
More precise requires illumination as well
Terminology
- Illumination
- Ambient illumination
- Notes terminology
- l - the ray from the light osurce to the surface
- n - the normal to the surface
- v - the direction to the eye
- r - the specular reflection direction
- Lin, Lout
Lambertian Surfaces
Model of body reflection
How much light hits the surface?
- Idealize light sources as points emitting light
- How much light does a source emit?
- How much light is there at a distance r from the source?
- Segregate the light by direction
- How much light per unit angle?
- How much light per square metre?
- Falls off with distance.
- How? Think how big the surface of a sphere is.
- How much of the surface does a square metre of the sphere cover?
- Depends on the angle
- How?
- What if the lights were (infinite) lines?
- Why is an infinite line the same as a circle?
- What if the lights were (infinite) planes?
- Why is an infinite surface the same as a sphere?
- In computer graphics this is called ambient light.
- What do we do in practice?
Comment. Two general aspects of the above are very important to getting
things right in computer graphics
- The scaling arguments from dimensionality
- The geometric derivations of angular facts from small areas
How much light leaves the surface?
This material is described with diagrams here.
We are only interested in the light leaving the surface in a particular
direction. Why?
The light divides into two parts at the surface
- part is reflected: `surface reflectance'
- part enters the surface: `body reflectance'
The simplest model of body reflectance is Lambert's cosine law. Surfaces
with body reflectance following Lambert's cosine law are called
Lambertian.
What makes a Lambertian surface Lambertian?
- Half-sphere within the body, centred at the bit of surface
- Half-sphere above the body, bottom at the surface
- Draw a little cylinder passing through the centre.
- Whatever goes in the bottom comes out the top
- modified by the angular size of the hole
- cosine factor
What goes into the eye
- Same geometry as illumination, only backward
- Cosine factors cancel one another
Important point
- The ubiquitous cosine terms (l.n, v.n, etc.) occur whenever we
translate between areas on a plane and areas on a sphere.
What colour is the light?
Highlights
Part of the light didn't enter the body of the surface, but was
reflected
- Called `surface reflection'
- Where does it go to?
Suppose the surface is smooth
- It is reflected, called `spectular'
- which means out = in - 2 * (in.normal) normal
- what is the colour?
- does it enter the eye?
Suppose we roughen the surface just a little
- The light spreads a little, centred on the specular direction.
- Called `gloss'.
- Amount entering the eye depends on the angle between the eye ray and
the specular direction
And if we roughen the surface a lot
- The light goes out all over the place
- This is called a matte surface
Here is the hack
- Named Phong lighting after Phong Bui-Tuong
- Let the specular term be ( r.v )^p
- small p - matte
- large p - highly specular
How is the incoming light divided between ambient, surface and body
reflection?
L(\lambda) = Ia * ka(\lambda) + Id * (l.n) * kd(\lambda) + Is * ( r.v )^p
* ks
- Implicit v.n / v.n in the second term
- Missing 1 / v.n in the third term
Return to: