** (Curves) Geometry and drag equation**

**B- spline ( basis spline) : for 4 control points, given B0, B1, B2, and B3 as the weighting function**

0 <= U <= 1.0

*B-spline matrix: Bs, *

*with 4 control points Pi*

### Cubic B-Spline Curve

• Cubic B-Spline Curve, C^{2} continuous

• P(u) = u^{T}M p, where P is control
points [p^{i-2}, p^{i-1}, p^{i}, p^{i+1}]^{T}

• At first define it to be C^{2}continuous,
set up boundary conditions, and we
can get

if u is defined as [1,u, u^{2}, u^{3}] in this
order, P(u) = u^{T}*M** _{S}* p

*basis function = Ms*^{T}u = (1/6) [ (1-u)^{3}, 4-6u^{2}+3u^{3}, 1+3u+3u^{2}-3u^{3}, u^{3}]^{T}

1 3 3

1

0 3 6 3

0 3 0

3

0 1 4

1

6
*Ms* 1

### Curve DEMO

• DEMO 1: Bezier curve

http://math.hws.edu/eck/cs424/notes2013/canvas/bezier.ht ml (connected curve)

http://blogs.sitepointstatic.com/examples/tech/canvas-curves/bezier-curve.html (basic curve)

DEMO 2: B-spline curve demo

https://www.cs.utexas.edu/~teammco/research/bsplines/

DEMO 3: Bezier , Bsline, NURBS DEMO

(note: manually add more control points)

### Bezier Patch demo

• DEMO 3:

Youtube video:

https://www.youtube.com/watch?v=2tLC0oIbKS 0

DEMO 4: Bezier Surfaces (patch)

http://www.ibiblio.org/e-notes/Splines/bezier3d.html Fighter plane demo:

http://www.ibiblio.org/e-notes/webgl/deflate/yf23.html

### WebGL Interactive models

•

http://www.ibiblio.org/e-notes/webgl/models.htm#spline

• (including animated horse, fox, eagle, shark,

human elbow bones, and more static 3D models, such as bike, etc.)

DEMO 5: more control points for B-spline curve http://nurbscalculator.in/ (need to add more control points)(Q1: make the first three control

points to be at the same position, what happens?)

### Ray tracing: Turner Whitted

• Key to success, from light to eye or from eye to screen?

Concept: how to win? (shooting ball game below)

### The Rendering Equation: Jim Kajiya, 1986

(渲染方程式)

I(x, x’): light (intensity) from patch x’ to patch x g(x,x’): visibility geometry, o: invisible, 1: visible

e(x, x’): the rate at which light is emitted from patch x’ to x, when x’ is an emitter.

**ρ (x, x’, x’’): patch’s reflectivity,**

### Definitions

• where

I(x, x’): light (intensity) from patch x’ to patch x g(x,x’): visibility geometry, o: invisible, 1: visible e(x, x’): the rate at which light is emitted from patch x’ to x, when x’ is an emitter.

**ρ (x, x’, x’’): patch’s reflectivity, light from x’’ to x’ **

and the ratio reflected to x

Another detailed definition of the Rendering Equation

The rendering equation describes the total amount of light
**emitted from a point x along a particular viewing direction, **
given a function for incoming light and a BRDF.

### Explanation

1. Conservation of energy.

2. Assuming that L denotes radiance, we have that at each particular position and direction, the outgoing light (Lo) is the sum of the emitted light (Le) and the reflected light.

3. The reflected light itself is the sum from all

directions of the incoming light (Li) multiplied by the surface reflection and cosine of the incident angle.

### The Rendering Equation

### Terminology

Radiance: 輻射, 光芒, light or heat that comes from something.

Illumination, ^{照明, light}

Illuminance: 照度: 單位面積上的光通量,

單位: LUX, 1 LUX = 1 流明/平方米, Lumen (lm) :流明, luminous flux, 1 lm = 1 cd.sr,

1 cd: Candela, 燭光 (一瓦的白燈光, 約等於一燭光),

1 sr: steradian, 球面度, 立體角 (半徑 , 若張開的面積為 r^{2},
則角度為 1立體角, 1 sr)

### Ray tracing(1)

### Simple recursive ray tracing

L_{i}: shadow ray
R_{i}: reflected ray
N_{i}: normal

T_{i}: transmitted ray
whether

1. L_{1}=R_{1}+T_{1}? or

2. f^{1}(L_{1})=f(R_{1})+f(T_{1})? or
3. Color=f(L_{1},R_{1},T_{1} )

### Shadow in ray tracing

### Faster: ray tracing

• halfway vector

### From known data to unknown

### Ray Tracing Algorithm

**Trace(ray)**

**For each object in scene**
**Intersect(ray, object)**
**If no intersections**

**return BackgroundColor**
**For each light**

**For the object in scene**

**Intersect(ShadowRay, object)**
**Accumulate local illumination**
**Trace(ReflectionRay)**

**Trace(TransmissionRay)**

**Accumulate global illumination**

### Ray Tracing Algorithm

### Code example: A simple ray tracer

• Author: Turner Whitted

– famous for his implementation of recursive ray tracer.

• Simplified version:

– input: quadric surfaces only

i.e. f(x,y,z)=ax^{2} + by^{2} + cz^{2} + 2dxy + 2eyz + 2fxz + 2gx +
2hy + 2jz + k = 0

– Shading calculation: as simple as possible

• Surface normal

[df/dx, df/dy, df/dz]

= [ 2ax+2dy+2fz+2g, 2by+2dx+2ez+2h, 2cz+2ey+2fx+2j ]

### Sample program

**Color trace_ray( Ray original_ray )**
{

**Color point_color, reflect_color, refract_color**
**Object obj**

**obj = get_first_intersection( original_ray )**
**point_color = get_point_color( obj )**

if ( object is reflective )

**reflect_color = trace_ray( get_reflected_ray( original_ray, obj ) ) **
if ( object is refractive )

**refract_color = trace_ray( get_refracted_ray( original_ray, obj ) )**
**return ( combine_colors( point_color, reflect_color, refract_color )) **
}

### Code example: A simple ray tracer

• The simple ray tracer is complete and free to copy [need modification to be term project]

• Input surface properties

– r, g, b, relative_index_of_refraction, reflection_coef, transmission_coef, object_type

– number_of_objects, number_of_surfaces, number_of_properties

• How to calculate the intersection of a ray and a quadric surface?

### Ray to quadric surface intersection

• intersection calculation:

– let direction=(D_{x}, D_{y}, D_{z}), origin=(O_{x}, O_{y}, O_{z})
line ==> (x,y,z)=(O_{x}, O_{y}, O_{z}) + t*(D_{x}, D_{y}, D_{z})
– quadric surface

f(x,y,z) = ax^{2} + by^{2} + cz^{2} + 2dxy + 2eyz +
2fxz + 2gx + 2hy + 2jz + k = 0

– replace (x,y,z) in (2) by (1),

acoef*t^{2} + bcoef*t + ccoef = 0, solve for t

• for example:

acoef = a*D_{x}^{2} + b*D_{x}*D_{y} + c*D_{x}*D_{z} + e*D_{y}^{2} + f*D_{y}*D_{z} + h*D_{z}^{2}

**(1)**

**(2)**

### Special notice:

1. Avoid to intersect a surface twice within a tiny triange

– e.g. t1=100, t2=100.001

– This may happen because of numeric percision

2. If a ray doesn't hit anything, give it a non-offensive background color, (20,92,192).

– This is the sky color(assume it is day time, of course).

– Otherwise, choose twilight or dark sky color.

3. How to modify this program to accept triangles?

Grid methods?

– Each grid center contains a pointer to the list of triangles which are(partly) contained in the grid.

### Special notice:

4. Shading model

5. ^{I}^{I}

###

^{N}

^{L}###

^{K}*S*

^{S}

^{K}*T*

^{T}*n*

*j*

*j*

*a*

###

1

• Ultimately, this yields the following pseudo code:

• For more info, please see my document Ray_Tracing.bw

### Ray-object intersection acceleration

### More about Ray-Tracing: Photon Mapping

**• Photon mapping** is a two-pass global

illumination rendering algorithm developed by Henrik Wann
Jensen between 1995 and 2001^{[1]} that approximately solves
the rendering equation for integrating light radiance at a given
point in space. Rays from the light source (like photons) and rays
from the camera are traced independently until some termination
criterion is met, then they are connected in a second step to

produce a radiance value.

• Progressive photon mapping (PPM) starts with ray tracing and then adds more and more photon mapping passes to provide a progressively more accurate render.

### Photon Mapping: result

**Global illumination using photon maps, EuroRendering 1996, by Henrik Wann **
Jensen

•

More about Ray-Tracing: Photon Mapping

Photon: A Modular, Research-Oriented Rendering System, Siggraph 2019 poster

Figure 1: Several visualization techniques implemented using the building blocks provided by our system. In the center, the buddha features Belcour’s BSDF model [Belcour 2018], while the left one, the glass brick induces caustics that can be rendered efficiently using particle tracing methods.

### Radiosity (熱輻射法)

Donald Greenberg and Tomoyuki Nishita (1985)

What is Radiosity in Computer Graphics?

(DEMO)

### Turner Whitted (

upper middle### , ray tracing), Donald Greenberg(

lower right,### radiosity)

129

### Tomoyuki Nishita,

Rendering, 2011/11Steven Coons Award 2005, major Asian CG researcher

130

### What is still missing in ray-traced images?

• Diffuse to diffuse reflection?

### The Rendering Equation: Jim Kajiya, 1986

(渲染方程式)

I(x, x’): light (intensity) from patch x’ to patch x g(x,x’): visibility geometry, o: invisible, 1: visible

e(x, x’): the rate at which light is emitted from patch x’ to x, when x’ is an emitter.

**ρ (x, x’, x’’): patch’s reflectivity,**

134

E. Angel and D. Shreiner: Interactive Computer Graphics 6E ©

Addison-Wesley 2012

### Rendering Equation: Another version

**Consider light at a point p arriving from p’**

**i(p, p’) = υ(p, p’)(ε(p,p’)+ ∫ ρ(p, p’, p’’)i(p’, p’’)dp’’**

occlusion = 0 or 1/d^{2} **emission from p’ to p**

**light reflected at p’ from all **
**points p’’ towards p**

135

E. Angel and D. Shreiner: Interactive Computer Graphics 6E ©

Addison-Wesley 2012

### Radiosity

• Consider objects to be broken up into flat patches (which may correspond to the

polygons in the model)

• Assume that patches are perfectly diffuse reflectors

• Radiosity = flux = energy/unit area/ unit time leaving patch

136

E. Angel and D. Shreiner: Interactive Computer Graphics 6E ©

Addison-Wesley 2012

### Patches

### Radiosity

### A

^{k}

### Definitions

• where

B^{i}: B are the radiosity of patches i and j
E^{i}: the rate at which light is emitted from
patch i

P^{i}: patch i's reflectivity

F^{ji}:formfactor (configuration factor ) , which
specifies the fraction of energy leaving the
patch j that arrives at patch i.

A^{i}, A^{j} areas of patch i and j.

### Reciprocity in radiosity

^{(互換, 互惠)}

Total energy

passing through Ai and Aj should be the same!

(2)

(3)Simplified Eq from (1)

互惠 互惠

## A

^{i}

^{A}

^{j}

140

E. Angel and D. Shreiner: Interactive Computer Graphics 6E ©

Addison-Wesley 2012

### Radiosity Equation

energy balance

### b

_{i}

### a

_{i}

### = e

_{i}

### a

_{i}

### + ρ

_{i}

### ∑ f

_{ji}

### b

_{j}

### a

_{j}

reciprocity

### f

_{ij}

### a

_{i}

### = f

_{ji}

### a

_{j }

radiosity equation

### b

_{i}

### = e

_{i}

### + ρ

_{i}

### ∑ f

_{ij}

### b

_{j}

141

E. Angel and D. Shreiner: Interactive Computer Graphics 6E ©

Addison-Wesley 2012

### Notation

n patches numbered 1 to n
b_{i} = radiosity of patch I

a_{i }= area patch I

total intensity leaving patch i = b_{i }a_{i}
e_{i }a_{i} = emitted intensity from patch I
ρ_{i }= reflectivity of patch I

f_{ij} = form factor = fraction of energy leaving
patch j that reaches patch i

142

E. Angel and D. Shreiner: Interactive Computer Graphics 6E ©

Addison-Wesley 2012

### Matrix Form

**b = [b**

_{i}

### ] **e = [e**

_{i}

### ]

**R = [r**

_{ij}

### ] r

_{ij}

### = ρ

_{i}

^{if}

### i ≠ j r

_{ii}

### = 0

**F = [f**

_{ij}

### ]

143

E. Angel and D. Shreiner: Interactive Computer Graphics 6E ©

Addison-Wesley 2012