Simple Texture Mapping and Simple Ray-Tracing
Texture Map Each pixel in a texture map is called a Texel Each Texel is associated with a (s,t) 2D texture coordinate The range of s, t is [0.0,1.0] due to normalization
Simple Mapping Texture Coordinates Projection Coordinates
Simple Mapping Texture Coordinates Projection Coordinates
Simple Mapping
Basic File Structure Add texture coordinates v1 x1 y1 z1 u1 v1
Texture Filtering Get an interpolated value from near four neighbors
Bilinear Interpolation
Perspective Correction Linear Interpolation of Texture Coordinate Corrected Interpolation
Perspective Correction Let’s assume that the viewport is located 1 unit away from the projection center
Perspective Correction Compare linear interpolation in screen space
Perspective Correction
Perspective Correction We can interpolate arbitrary parameters of a surface on the screen coordinates in the linear fashion Use s instead t ! (ex) Gouraud shading, Phong normal . . etc
Perspective Correction Further reading http://www.whisqu.se/per/docs/graphics16.htm http://p205.ezboard.com/fyabasicprogrammingfrm20.showMessage?topicID=20.topic (Perspective correction with Z-buffering) http://easyweb.easynet.co.uk/~mrmeanie/tmap/tmap.htm
Ray Tracing Concept eye view plane Binary Tree
Ray Tracing Procedure For each ray r from eye to pixel, color the pixel the value returned by the function: ray_cast(r) ray_cast(r) { s nearest_intersected_surface(r); p point_of_intersection(r, s); u reflect(r, s, p); v refract(r, s, p); c phong(p, s, r) + s.kreflect ray_cast(u) + s.krefract ray_cast(v); return(c); }
Ray Tracing Procedure s nearest_intersected_surface(r); Use geometric searching to find the nearest surface s intersected by the ray r p point_of_intersection(r, s); Compute p, the point of intersection of ray r with surface s u reflect(r, s, p); v refract(r, s, p); Compute the reflected ray u and the refracted ray v using Snell’s Laws
Ray Tracing Procedure phong(p, s, r) s.kreflect ray_cast(u) Evaluate the Phong reflection model for the ray r at point p on surface s, taking shadowing into account s.kreflect ray_cast(u) Multiply the contribution from the reflected ray u by the specular-reflection coefficient kreflect for surface s s.krefract ray_cast(v) Multiply the contribution from the refracted ray v by the specular-refraction coefficient krefract for surface s
Reflection and Refraction Reflected and refracted rays are computed using Snell’s Law surface normal reflected ray incident ray surface refracted ray
Shadowing If any object intersects the shadow ray between the surface and the point light source, the surface is in shadow w.r.t. that light source blocked ! u L N r
Surface Intersection Ray equation ray path
Surface Intersection For sphere, If the discriminant is negative, the ray does not intersect the sphere. Otherwise, intersection coordinates are obtained using smaller s.