Cs3vr16 Graphics 5
Cs3vr16 Graphics 5
Lecture 5 – Aut 22
CS3VR16 – Virtual Reality – Graphics - 5
p1 RJM 17/08/23
© Prof Richard Mitchell 2023
Components for 3D
Graphics
Remaining Topics
Representation
• Planar Surfaces
• Constructive Solid Geometry
• Solids/Voxel modelling
Camera Models/Scene Views
• Perspective
Shading and Lighting
• Shading models
CS3VR16 – Graphics - 5
p2 RJM 17/08/23
© Prof Richard Mitchell 2023
Representation
A scene can contain different type of objects
Various representation models are available
Polygonal surfaces and quadrics
Spline surfaces
Solid modeling
Volumetric models
Procedural models
Physics based modeling
CS3VR16 – Graphics - 5
p3 RJM 17/08/23
© Prof Richard Mitchell 2023
Representation
Many ways to represent a surface
Each has advantages/disadvantages
3D
Models
Non-Polygonal Polygonal
Models Models
Constructive Parametric
Structured Polygon
Solid Surfaces
Soups
Geometry
Implicit
Surfaces Convex Non Convex
CS3VR16 – Graphics - 5
p4 RJM 17/08/23
© Prof Richard Mitchell 2023
Planar Surface Modelling: Polygon
Polygon mesh:
vertex, edges and polygons
each edge shared (max 2
polygons)
• vertex: point (x,y,z)
• edge: line joining two vertices
• polygon: closed seq. of edges
CS3VR16 – Graphics - 5
p5 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM - Polygonal
These can be represented as
• Explicit
• Pointers to list of vertices
• Pointers to list of edges
Criteria to evaluate different
representations
• Time
• Space
• Topological Information
CS3VR16 – Graphics - 5
p6 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM - Explicit
Explicit Representation Advantages
Each P list of vertex coords • Efficient rep. for
each polygon
𝑃 1 = { ( 𝑥1 , 𝑦 1 , 𝑧 1 ) ,... , ( 𝑥 𝑛 , 𝑦 𝑛 , 𝑧 𝑛 ) }
𝑃 2 = { ( 𝑥3 , 𝑦 3 , 𝑧 3 ) , ..., ( 𝑥 𝑚 , 𝑦 𝑚 , 𝑧 𝑚 ) }
Disadvantages
Vertices stored in order • High storage
Shared vertices cost
duplicated • To move
No explicit representation vertex,
traverse all Ps
for shared vertices /edges
• Shared edges
drawn twice
CS3VR16 – Graphics - 5
p7 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM – Pointers to vertex
list
Pointers to list of Advantages
vertices • Each V stored
Each V stored once in once
list • Coords easily
changed
P = list of V lists Disadvantages
• Difficult to find
𝑃 1 = { 𝑉 1 ,𝑉 2 ,𝑉 4 }
Ps that share an
𝑃 2 = { 𝑉 4 , 𝑉 2 ,𝑉 3 } V2 edge
V1 P 1 V3 • Shared edges
P2 drawn twice
V4
CS3VR16 – Graphics - 5
p8 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM Pointers to Edge list
Pointers to list of edges Advantages
Again, a list of vertices • Each V stored
P list of indexes to E once
• Shared edges
list
drawn once
Edges point to vertices • V coords easily
and polygons belong changed
to Disadvantages
V2 • Diff. to find
E1 edges which
E2
V1
P1 P2 V3 share a vertex
E5 E4
E3
V4
CS3VR16 – Graphics - 5
p9 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM – Polygonal Meshes
Polygonal Meshes – types of
Triangle Strip
• n vertices,
• (n-2) connected triangles
Triangle Fan
• n vertices,
• (n-2) connected triangles
Mesh of Quadrilaterals
• (n-1) (m-1) quadrilaterals
• for n m vertices
CS3VR16 – Graphics - 5
p10 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM Polygons - Characteristics
Many polygons, often triangles / quads
Concave or Convex Shapes
Varying levels of topological information:
none (soups) to complex connectivity
graphs
Convex Concave
CS3VR16 – Graphics - 5
p11 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM P - Characteristics
Characteristics
Re modelling solid shapes..
Poor for smooth curves,
need huge numbers of polygons
CS3VR16 – Graphics - 5
p12 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM – P - Issues
Issues to consider with models
• Which order to draw
• Do polygons collide?
• Relevant in animation
• How make algorithms efficient
• Concave / Convex affect tests
Convex objects quicker
CS3VR16 – Graphics - 5
p13 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM – Convex Polygons
Convex Polygons
An object is convex iff
“A line segment between any two points on an
object is on or within its boundary”
CS3VR16 – Graphics - 5
p14 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM – Polygon Collision
Polygons – collision test
Separating Axis Theorem (SAT)
CS3VR16 – Graphics - 5
p15 RJM 17/08/23
© Prof Richard Mitchell 2023
PSM – Polygonal
Non-Convex Polygons
So use convex decomposition
CS3VR16 – Graphics - 5
p16 RJM 17/08/23
© Prof Richard Mitchell 2023
GC – 2 phases re checks
Broad phase – put bounding boxes round
objects
(smallest box in which shape fits)
Narrow phase – do test only if
bounding boxes over lap
Objects comprising many elements
divide into tree of BBs
CS3VR16 – Graphics - 5
p17 RJM 17/08/23
© Prof Richard Mitchell 2023
Representation
More ways to represent a surface
3D
Models
Non-Polygonal Polygonal
Models Models
Constructive Parametric
Solid Surfaces Structured Polygon
Geometry Soups
Implicit
Surfaces Convex Non Convex
CS3VR16 – Graphics - 5
p18 RJM 17/08/23
© Prof Richard Mitchell 2023
Non-Polygonal Models – Implicit
Surfaces
Non-polygonal techniques to represent shapes
smoother,
less memory consuming
But distance and intersection much harder
An implicit surface defined by locus of points at
f(x,y,z) = 0
f is smooth
and has a non zero gradient at any point
CS3VR16 – Graphics - 5
p19 RJM 17/08/23
© Prof Richard Mitchell 2023
NPM – Implicit Surfaces - Sphere
Example – sphere
A sphere is a function in x, y and z such that:
CS3VR16 – Graphics - 5
p20 RJM 17/08/23
© Prof Richard Mitchell 2023
NPM – ISE - another
Implicit Surface Example
[x 2
+ y + z − a k ] − b [ ( z −k ) − 2x ][ ( z+ k ) − 2 y ] = 0
2 2 2 2 2 2 2
CS3VR16 – Graphics - 5
p21 RJM 17/08/23
© Prof Richard Mitchell 2023
NPM – Parametric Surfaces
2D planar shape mapped to 3D coordinates
→ a parametric surface (PS)
PS need not be a topological or closed surface
Generally used to define a surface boundary
Hence, parametric objects are usually made up
of many surface ‘patches’
CS3VR16 – Graphics - 5
p22 RJM 17/08/23
© Prof Richard Mitchell 2023
NPM – Parametric Surfaces
Non-Uniform Rational B-Splines widely used
Finding intersection between two not trivial
Precision affected by processing time
Often not suitable for real-time simulation
Tessellate into polygons, then collision detect
CS3VR16 – Graphics - 5
p23 RJM 17/08/23
© Prof Richard Mitchell 2023
NPM – Parametric Surfaces Example
CS3VR16 – Graphics - 5
p24 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling - CSG
Constructive Solid Geometry
Start with set of primitives
Blocks, cones, cylinders, spheres, etc
These can be scaled/rotated
Create new solid using logical
operations
Resultant shape can be scaled, rotated
CS3VR16 – Graphics - 5
p25 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – CSG
Constructive Solid Geometry
Use binary tree to define
CS3VR16 – Graphics - 5
p27 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – CSG – eg
1
Example 1
CS3VR16 – Graphics - 5
p28 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – CSG – eg
2
Example 2
CS3VR16 – Graphics - 5
p29 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – CSG – eg
3
Example 3
CS3VR16 – Graphics - 5
p30 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – CSG
Advantages
Powerful, high level commands
Easy to construct solid model
Concise description – less memory
Easy to assure objects solid or ‘water tight’
Disadvantages
Only Boolean operations : restricts possible
shapes
Comp. expensive to find boundaries, faces,
edges
Care ensure generate
p31 RJM 17/08/23 valid
© Prof shapes
CS3VR16 – Graphics - 5
Richard Mitchell 2023
Solid Modelling – CSG
Applications
CSG has a number of practical uses:
• Where simple geometric objects are desired
• Where mathematical accuracy is important
• Many graphics engines use CSG
• There are also libraries that add CSG to Unity
CSG popular
Important in manufacturing / engineering
CS3VR16 – Graphics - 5
p32 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – CSG Workflow
Different rules …
CS3VR16 – Graphics - 5
p33 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – CSG Code
PovRay – CSG models from code
Example:
cylinder { <0,-4,0> <0,4,0> 0.2 pigment { Yellow } }
difference {
box { <-1.5,-0.5,-0.5> <1.5,0.5,0> 0.1 }
cylinder { <-0.8,0,-3> <-0.8,0,3> 0.1 }
cylinder { <0.8,0,-3> <0.8,0,3> 0.1 }
pigment { Red }
}
Persistence Of Vision Raytracer – www.povray.com
CS3VR16 – Graphics - 5
p34 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling - Extrusion
Extrusion
• Useful if rotational or translational
symmetries
• Use 2D primitive and path in 3D Primitiv
space e
Linear
Extrusio
n
Circular
Extrusion
CS3VR16 – Graphics - 5
p35 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – Octtrees
Spatial Numbering (Octtrees)/Voxel
Modelling
Hierarchical tree structure, each node is 3D region
These regions are divided in octants (cubes),
8 elements are stored in each node of the tree
Nodes can be of 3 types:
white (out the object);
black (inside the object)
Grays (neither inside nor outside)
Individual elements of 3D space are called voxels
CS3VR16 – Graphics - 5
p36 RJM 17/08/23
© Prof Richard Mitchell 2023
Solid Modelling – Octtrees
Divide vol into smaller vols where need more
detail
Example
CS3VR16 – Graphics - 5
p37 RJM 17/08/23
© Prof Richard Mitchell 2023
Summary
In this lecture we have considered different ways of
representing surfaces and models
• Planar Surfaces
• Constructive Solid Geometry
• Solids/Voxel modelling
We can now model 3D different scenes
But we need to draw them on a 2D screen
So we need to think about perspective …
CS3VR16 – Graphics - 5
p38 RJM 17/08/23
© Prof Richard Mitchell 2023