Primary Rays
Shoot a primary ray through each pixel \((x,y)\) of the image plane:
- use eye point as origin \(\vec{o}\)
- compute 3D position \(\vec{p}\) of pixel \((x,y)\)
- compute direction \(\vec{d} = \frac{\vec{p}-\vec{o}}{\norm{\vec{p}-\vec{o}}}\)
© Andrew Glassner
diffraction
interference
polarization Images from Wikipedia
dispersion
fluorescence Images from Wikipedia
cgtrader.com
cgtrader.com
cgtrader.com
cgtrader.com
Autodesk
Autodesk
Autodesk
Source: A. H. Zewail,Phil. Trans. R. Soc. A 2010;368:1191-1204
What’s the problem with this approach?
Images from Wikipedia
Images from Wikipedia
ACM SIGGRAPH 1979 - An improved illumination model for shaded display
Implementing a ray tracer basically comes down to
three operators that we have to understand and implement.
void raytrace()
{
for (int x=0; x<width; ++x)
{
for (int y=0; y<height; ++y)
{
// generate primary ray through pixel (x,y)
ray = primary_ray(x,y);
// determine color through (recursive!) trace function
color[x,y] = trace(ray);
}
}
}
\[ \vec{r}(t) = \vec{o} + t \, \vec{d} \]
Shoot a primary ray through each pixel \((x,y)\) of the image plane:
\[ \vector{ \phi \\ \theta } \mapsto \vector{ \cos\phi \, \cos\theta \\ \sin\phi \, \cos\theta \\ \sin\theta } \]
\[ \vector{ \phi \\ \theta } \mapsto \vec{c} + r \, \vector{ \cos\phi \, \cos\theta \\ \sin\phi \, \cos\theta \\ \sin\theta } \]
Trigonometric functions make this
equation nonlinear and complicated!
Images from Wikipedia

color only
+diffuse
+specular
typedef struct{double x,y,z}vec;vec U,black,amb={.02,.02,.02};struct sphere{
vec cen,color;double rad,kd,ks,kt,kl,ir}*s,*best,sph[]={0.,6.,.5,1.,1.,1.,.9,
.05,.2,.85,0.,1.7,-1.,8.,-.5,1.,.5,.2,1.,.7,.3,0.,.05,1.2,1.,8.,-.5,.1,.8,.8,
1.,.3,.7,0.,0.,1.2,3.,-6.,15.,1.,.8,1.,7.,0.,0.,0.,.6,1.5,-3.,-3.,12.,.8,1.,
1.,5.,0.,0.,0.,.5,1.5,};yx;double u,b,tmin,sqrt(),tan();double vdot(A,B)vec A
,B;{return A.x*B.x+A.y*B.y+A.z*B.z;}vec vcomb(a,A,B)double a;vec A,B;{B.x+=a*
A.x;B.y+=a*A.y;B.z+=a*A.z;return B;}vec vunit(A)vec A;{return vcomb(1./sqrt(
vdot(A,A)),A,black);}struct sphere*intersect(P,D)vec P,D;{best=0;tmin=1e30;s=
sph+5;while(s-->sph)b=vdot(D,U=vcomb(-1.,P,s->cen)),u=b*b-vdot(U,U)+s->rad*s
->rad,u=u>0?sqrt(u):1e31,u=b-u>1e-7?b-u:b+u,tmin=u>=1e-7&&u<tmin?best=s,u:
tmin;return best;}vec trace(level,P,D)vec P,D;{double d,eta,e;vec N,color;
struct sphere*s,*l;if(!level--)return black;if(s=intersect(P,D));else return
amb;color=amb;eta=s->ir;d= -vdot(D,N=vunit(vcomb(-1.,P=vcomb(tmin,D,P),s->cen
)));if(d<0)N=vcomb(-1.,N,black),eta=1/eta,d= -d;l=sph+5;while(l-->sph)if((e=l
->kl*vdot(N,U=vunit(vcomb(-1.,P,l->cen))))>0&&intersect(P,U)==l)color=vcomb(e
,l->color,color);U=s->color;color.x*=U.x;color.y*=U.y;color.z*=U.z;e=1-eta*
eta*(1-d*d);return vcomb(s->kt,e>0?trace(level,P,vcomb(eta,D,vcomb(eta*d-sqrt
(e),N,black))):black,vcomb(s->ks,trace(level,P,vcomb(2*d,N,D)),vcomb(s->kd,
color,vcomb(s->kl,U,black))));}main(){printf("%d %d\n",32,32);while(yx<32*32)
U.x=yx%32-32/2,U.z=32/2-yx++/32,U.y=32/2/tan(25/114.5915590261),U=vcomb(255.,
trace(3,black,vunit(U)),black),printf("%.0f %.0f %.0f\n",U);}/*minray!*/