0% found this document useful (0 votes)
29 views10 pages

Object Representation and Ray Tracing

The document discusses different methods for representing 3D objects in computer graphics, including implicit functions, polygon meshes, and parametric surfaces. It also covers various primitives like points, vectors, triangles, and cubes. Vertex lists with pointers are presented as an efficient way to represent 3D geometry by avoiding duplicated vertices.

Uploaded by

Guilherme Vieira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views10 pages

Object Representation and Ray Tracing

The document discusses different methods for representing 3D objects in computer graphics, including implicit functions, polygon meshes, and parametric surfaces. It also covers various primitives like points, vectors, triangles, and cubes. Vertex lists with pointers are presented as an efficient way to represent 3D geometry by avoiding duplicated vertices.

Uploaded by

Guilherme Vieira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Object Representation Object Representation

• Implicitly f(x,y,z)=0 – i.e. all points in 3D space • Implicitly f(x,y,z)=0 – i.e. all points in 3D space
where some function is zero. where some function is zero.
• e.g. sphere (x2+y2+z2)=r2 • e.g. sphere (x2+y2+z2)=r2
• Any guesses for?: • Any guesses for?:

• It’s a cartoid (heart!)


• Implicits:
– Extremely compact storage

Object Representation Object Representation


• Parametrically • Polygon meshes (e.g. triangular mesh)
e.g. Bezier surface patch • Bruno Levy (Inria) of Michaelangelo’s David
2 billion polygons, 32GB

• Smooth joins, very good for curved surfaces


Triangular Meshes Terminology
• Advantages: • GPU (Graphics Processing Unit) – a chip dedicated
– Ray/triangle intersection for ray-tracing is easy
to the processing of vertices for the purposes of
display
– Can project triangles in GPU hardware (at millions
• OpenGL – Open Graphics Language – a language
per second (Computer Games)
for programming graphics applications. The
– Can easily manipulate subdivide triangular meshes language maps to GPU hardware and is OS
(e.g. for Level of detail models or radiosity) independent
• Direct3D – Microsoft’s graphical programming
language. The language maps to GPU hardware
and is OS dependent (Windows)

Modelling: 3D Primitives Modelling: 3D Primitives


• Point • Vector
• 3D location in space • 3D direction and magnitude (no position)
• Represented by coordinates y-axis class Vector {
private:
class Point { float dx, dy, dz;
private: (x,y,z) public: (dx, dy, dz)
float x, y, z; float Magnitude() const {
... return
}; sqrt(dx*dx+dy*dy+dz*dz));
x-axis }
...
};

z-axis
Modelling: 3D Primitives Explicit Representation
• Triangle • Quad • Cube (6 faces / quads) (0,1,1)
(1,1,1)
• These explicit representations class Quad{ • (0,0,0) (0,0,1) (1,0,1) (1,0,0) (1,1,0)
• (1,0,0) (1,1,0) (0,1,0) (0,0,0) (0,1,0)
lead to duplicated points private:
Point P1, P2, P3, P4; • (1,1,0) (1,1,1) (0,1,1) (0,1,0)
• This problem is examined in ...
• (1,1,1) (1,0,1) (0,0,1) (0,1,1)
the next slides };
(0,0,1)
• (1,0,0) (1,0,1) (1,1,1) (1,1,0) (1,0,1)
class Triangle { • (0,0,1) (0,0,0) (0,1,0) (0,1,1)
private: P2 P3 (0,0,0) (1,0,0)
Point P1, P2, P3; • Drawbacks:
... • 3D transformations of 24 vertices
P3
}; (not 8)
• Draw 24 edges (rather than 12)
• Rounding errors – consider
P1 P4
picking vertices
P1 P2

Pointers to Vertex List 3D Primitives


(0,1,1)
(1,1,1)
• Vertices / (1,1,0) • Pointers to Vertex List
Points (0,1,0)
widely used (although see
• 0=(0,0,0) • Polygons
triangle strips)
• 1=(0,0,1) / Quads
(0,0,1) • Each triangle vertex is a
• 2=(0,1,0) • 0154 (1,0,1)
pointer to a 3D point
• 3=(0,1,1) • 4 6 2 0 (0,0,0) (1,0,0)
• An object is a list of
• 4=(1,0,0) • 6 7 3 2 Advantages: triangles (or quads)
3D transformations of just 8
• 5=(1,0,1) • 7513 vertices. class Triangle {
• 6=(1,1,0) Rounding errors not a problem. private:
• 4 5 7 6 Drawbacks: Point *P1, *P2, *P3;
• 7=(1,1,1) Draw 24 edges (rather than 12) ...
• 1023 Extra memory };
Extra processing during modelling
Example Triangular Strips
• For example, the previous sphere consists of • Compact (n triangles
represented using n+2
382 vertices and 760 triangles vertices)
• Each vertex is 3 floats (3x4 bytes=12) • Therefore transmission
to GPU is lower
• Each triangle is a list of 3 pointers (3x4 • Very efficient when
bytes=12) drawing (particularly in
hardware)
• This model uses 13,704 bytes • Can be hard to create
• Using (next) triangular strip model uses triangle strips from
arbitrary geometry OpenGL
762x12=9,144 bytes

What shall we use?


Direct3D Drawing Primitives (Answers in lecture)
• D3D_POINTLIST
A list of isolated points (n vertices=n points)
• D3D_LINELIST
A list of isolated lines (each pair of points are the ends of a
line) (2n vertices=n lines)
• D3D_LINESTRIP
The vertices make a continuous line (n+1 vertices=n lines)
• D3D_TRIANGLELIST
Each group of 3 points define an isolated triangle (3n
vertices=n triangles)
• D3D_TRIANGLESTRIP
(Previous slide) (n+2 vertices=n triangles)
• (Direct3D allows pointers to a vertex list using VERTEX
BUFFERS)
Rendering Modelling via capture

Rendering • Framestore’s Walking


with Dinosaurs
Transformation
of 3D space

Model / scene comprised of


geometric primitives in 3D Raster image
coordinate space

Animation Textures
Lighting Rendering
• We will study two forms of rendering – rasterization (briefly)
and ray tracing (in detail)
• Rasterization consists of several steps:
– Transformation, clipping and scan conversion
• Matrices for scaling, translation and rotation are applied to
each vertex within the object during transformation
• After transformation each vertex (x,y) gives the screen
• Range coordinate, and z gives the depth
• Clipping removes any part of the scene not visible within the
• Light source and intensity image
• Scan conversion colours pixels according to the object’s colour
and the lighting model

Rendering Camera Model


World coordinates are For both Rasterization and Ray Tracing, we need to define
transformed into view a camera model. We explore which parameters are needed
Everything coordinates (x,y,z)
outside is
clipped View up vector (VUV)

View right vector (VRV)

Such that (x,y) give the position View reference point (VRP)
Object and within the view (image) and z
camera are gives the depth to that position.
defined in “World The depth can be used to make
Space” sure that occluded surfaces are
View plane normal (VPN) (vector). This
hidden by closer surfaces
can be calculated from the position
GPUs provide hardware support for transformation, (point) the camera looks at minus the
clipping and rasterization allowing scenes of millions of view reference point of the camera
triangles to be rendered in real-time
Transformation Ray Tracing
• The transformation matrix can be calculated from the
view plane normal (=look at – vrp), the view up vector
and the view right vector
• For rasterization, each vertex is multiplied by the
matrix (in GPU hardware)
• The resulting (x,y,z) points can be clipped and scan
converted
• In ray tracing, rays are sent out from the view plane,
into the scene to detect which objects are hit
• Ray tracing is studied in more detail in the next
lectures Eyepoint Screen Scene

Ray Tracing Ray Tracing - 1979


• Similar diagram (but in 3D) • Shadows, refraction, reflection and texture
mapping
• What about a 3rd year
project in ray tracing?
• The first image most
people see!
• Intersection between 3D
line p=o+dt and sphere
(p-c)^2=r^2

Ray/Sphere intersection Ray/Sphere intersection


• Ray p=o+dt, sphere (p-c)2=r2 • d2t2+2d(o-c)t+(o-c)2-r2=0
• Substitute ray p into sphere • but to solve at2+bt+c=0, we use
• ((o+dt)-c)2=r2 • t=(-b+-sqrt(b2-4ac))/2a
• Expand • where a=d2, b=2d(o-c), c=(o-c)2-r2
• (o-c)2+(dt)2+2dt(o-c)=r2 • The line starts at the eyepoint (o), and goes in
• Rearrange a direction (d) through each pixel
• d2t2+2d(o-c)t+(o-c)2-r2=0
World Coordinates Code (for reference)
procs=omp_get_num_procs();
omp_set_num_threads(procs);
#pragma omp parallel private(tid, i, j, C, ray_orig, my_RayTri)
{
tid=omp_get_thread_num();
for (j = tid; j < tex_h; j+=procs) {
for (i = 0; i < tex_w; i++) {
/*** Calculate ray origin ***/
ray_orig=my_camera.Ray(((double)(i-
centreX))/((double) tex_w), ((double)(j-centreY))/((double)
tex_h));
my_RayTri.SetOrigin(ray_orig);
my_RayTri.SetDir(my_camera.VPN);
C=my_RayTri.TraceRay();
*(*Image+i*4+j*tex_w*4)=(GLubyte) C.x;
*(*Image+i*4+j*tex_w*4+1)=(GLubyte) C.y;
*(*Image+i*4+j*tex_w*4+2)=(GLubyte) C.z;
*(*Image+i*4+j*tex_w*4+3)= (GLubyte) 255;
}
}
}

You might also like