代写代考 CM0304 Graphics I Graphics Hardware I.1 Graphics Systems

CM0304 Graphics I Graphics Hardware I.1 Graphics Systems

CMT107 Visual Computing

Copyright By PowCoder代写 加微信 powcoder

Xianfang Sun

School of Computer Science & Informatics
Cardiff University

➢ Ray casting

➢ Ray tracing

15:15 2CMT107 Visual Computing

Graphics Pipeline Review

15:15 3CMT107 Visual Computing

➢ Properties of the graphics pipeline
• Primitives are processed one at a time (in sequence)
• All analytic processing done early on
• Scan conversion (Rasterisation) occurs last
• Minimal state required (immediate mode rendering)

15:15 4CMT107 Visual Computing

➢ An alternative to pipeline approach: ray casting
• Search along lines of sight (rays) for visible primitive(s)

➢ Properties:
• Go through all primitives at each pixel

(must have all primitives in a display list)

• Sample (rasterisation) first
• Do analytic processing later

➢ Inverse mapping approach

Global Illumination

15:15 5CMT107 Visual Computing

➢ Ray casting properties:
• Takes no advantage of screen space coherence
• Requires costly visibility computation
• Forces per pixel illumination evaluations
• Not suited for immediate mode rendering

➢ In 1980 T. Whitted introduced recursive ray casting (ray
tracing) to address global illumination

➢ For each ray from the viewing position:
• Compute visible object

along the ray
• Compute visibility of each

light source from the
visible surface point
using a new ray

• If there is an object between
the surface point and the light source,
ignore the light source; otherwise, Phong illumination
model is used to evaluate the light intensity

• Can easily add reflection and refraction, etc.

15:15 6CMT107 Visual Computing

➢ For each object we need to know how to
• reflect light (Phong’s illumination model)
• refract light (Snell’s law)
• emit light (for light sources)
• intersect object with a ray

15:15 7CMT107 Visual Computing

➢ Move up backwards in tree and combine intensities as
determined by Phong’s illumination model

15:15 8CMT107 Visual Computing

➢ Compute ray direction v(x, y) for raster coordinates (x, y)

From Pixels to Rays

15:15 9CMT107 Visual Computing

➢ plane-line intersection
• Ray: P = P0 + tV
• Plane: PTN + D = 0
• Substitute: (P0 + tV)

TN + D = 0

• Solution: t = – (P0
TN + D) /(VTN)

➢ For intersection with polygon, check if intersection point lies
inside polygon

Ray-Plane/Polygon Intersection

15:15 10CMT107 Visual Computing

➢ Intersect a sphere with the ray (algebraic)
• Ray parameterisation: P(t) = P0 + tV
• Sphere equation: ||P – O||2 – r2 = 0
• Substitute: ||P0 + tV – O||

2 – r2 = 0

• Solve: t2 + 2VT(P0 – O)t + (||P0 – O||
2 – r2) = 0

Ray-Sphere Intersection

15:15 11CMT107 Visual Computing

➢ Intersect a sphere with the ray (geometric)
• L= O – P0, tca = L

• if tca < 0, no intersection • d2= LTL - tca • if d > r , no intersection

Ray-Sphere Intersection

15:15 12CMT107 Visual Computing

➢ Input: viewing position v, look-at point a, up vector u
➢ For each pixel:

• Create a ray l from the viewing position v in direction d
such that it passes the pixel in the viewing plane
• Set the colour to be the return value of raytrace(v, d)

➢ Function raytrace (v, d):
• Initialise position t on ray l from v in direction d to infinity

and the nearest object n to empty
• For each object o in the scene

▪ Compute intersection p of l and o closest to v
▪ If p exists and is closer to v than t, set t to p and n to o

• If n is empty, return background colour, else …

15:15 13CMT107 Visual Computing

▪ If n is reflective and we haven’t reached the maximum

recursion depth level, compute perfect reflection vector r
of d at t and call raytrace(t, r) to obtain reflected colour cr

▪ If n is transparent and we haven’t reached the maximum
recursion depth level, compute refraction vector r’ of d at
t and call raytrace(t, r’) to obtain refracted colour ct

▪ For each light source k=1, …, m at position lk, cast ray
from t to lk. If this line segment intersects with any of the
other objects, t is in the shadow of this object. Otherwise
compute the amount of light ck reaching t from k

▪ Return combination of colours cr, ct and ck, k=1, …, m

Summary (cont.)

15:15 14CMT107 Visual Computing

15:15 15CMT107 Visual Computing

➢ Advantages

• Improved realism (shadows, reflections, transparency)

• Higher level rendering primitives

• Very simple design

➢ Disadvantages

• Very slow per pixel calculations

• Only approximate global illumination

(cannot follow all rays)

• Hard to accelerate with hardware

➢ Acceleration approach

• Try to reduce number of intersection computations

Properties of

15:15 16CMT107 Visual Computing

➢ Bounding volumes
• Check simple bounding volume for ray/surface

intersections before checking complex shapes
➢ Bounding volume hierarchies

• Construct and check hierarchical bounding volumes

Acceleration

15:15 17CMT107 Visual Computing

➢ Create a data structure aware of the spatial relations
• Partition space and place objects within subregions
• Only consider subregions that the ray passes through
• Avoid computing intersections twice if object lies inside

multiple subregions

Spatial Data Structures

15:15 18CMT107 Visual Computing

➢ Partition space using BSP Tree

BSP Trees in

15:15 19CMT107 Visual Computing

Rendered Examples

15:15 20CMT107 Visual Computing

Advanced Phenomena

15:15 21CMT107 Visual Computing

➢ Ray tracers can simulate (not always efficiently)
• Soft shadows
• Frequency dependent light
(Snell’s law is different for different wave-lengths)

➢ But can barely handle diffuse/ambient lighting
• Radiosity is a global illumination scheme complementing

ray-tracing for diffuse/ambient lighting

15:15 22CMT107 Visual Computing

(by , http://graphics.cs.ucdavis.edu/~okreylos/Private/RaytracingCorner/)

http://graphics.cs.ucdavis.edu/~okreylos/Private/RaytracingCorner/

15:15 23CMT107 Visual Computing

(by , http://graphics.cs.ucdavis.edu/~okreylos/Private/RaytracingCorner/)

http://graphics.cs.ucdavis.edu/~okreylos/Private/RaytracingCorner/

15:15 24CMT107 Visual Computing

(by , http://graphics.cs.ucdavis.edu/~okreylos/Private/RaytracingCorner/)

http://graphics.cs.ucdavis.edu/~okreylos/Private/RaytracingCorner/

15:15 25CMT107 Visual Computing

(by , http://graphics.cs.ucdavis.edu/~okreylos/Private/RaytracingCorner/)

http://graphics.cs.ucdavis.edu/~okreylos/Private/RaytracingCorner/

15:15 26CMT107 Visual Computing

➢ What is ray casting? What are its advantages and
disadvantages?

➢ What is ray tracing? What are its advantages and
disadvantages?

➢ How can we compute the rays through raster points for ray
tracing? How can we compute the intersections of such a
ray and a plane or a sphere? How is this done for other

➢How can ray tracing be accelerated?

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com