Simple Texture Mapping and Simple RayTracing Texture Map

  • Slides: 22
Download presentation
Simple Texture Mapping and Simple Ray-Tracing

Simple Texture Mapping and Simple Ray-Tracing

Texture Map • Each pixel in a texture map is called a Texel •

Texture Map • Each pixel in a texture map is called a Texel • Each Texel is associated with a (s, t) 2 D 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 Texture Coordinates Projection Coordinates

Simple Mapping Texture Coordinates Projection Coordinates

Simple Mapping

Simple Mapping

Basic File Structure • Add texture coordinates v 1 x 1 y 1 z

Basic File Structure • Add texture coordinates v 1 x 1 y 1 z 1 u 1 v 2 x 2 y 2 z 2 u 2 v 3 x 3 y 3 z 3 u 3 v 4 x 4 y 4 z 4 u 4 v 4 f 1 1 3 2 f 1 1 4 3 f 1 1 2 4 f 1 2 3 4

Texture Filtering Get an interpolated value from near four neighbors

Texture Filtering Get an interpolated value from near four neighbors

Bilinear Interpolation

Bilinear Interpolation

Perspective Correction Linear Interpolation of Texture Coordinate Corrected 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

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 Compare linear interpolation in screen space

Perspective Correction

Perspective Correction

Perspective Correction • We can interpolate arbitrary parameters of a surface on the screen

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/graphics 16. htm – http:

Perspective Correction • Further reading – http: //www. whisqu. se/per/docs/graphics 16. htm – http: //p 205. ezboard. com/fyabasicprogrammingfrm 20. show. Me ssage? topic. ID=20. topic • (Perspective correction with Z-buffering) – http: //easyweb. easynet. co. uk/~mrmeanie/tmap. htm

Ray Tracing Concept eye view plane Binary Tree

Ray Tracing Concept eye view plane Binary Tree

Ray Tracing Procedure For each ray r from eye to pixel, color the pixel

Ray Tracing Procedure For each ray r from eye to pixel, color the pixel the value returned by the function: 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

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) – Evaluate the Phong reflection model for

Ray Tracing Procedure • phong(p, s, r) – 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 reflected

Reflection and Refraction • Reflected and refracted rays are computed using Snell’s Law reflected ray surface normal incident ray surface refracted ray

Shadowing • If any object intersects the shadow ray between the surface and the

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 ath p y ra

Surface Intersection • Ray equation ath p y ra

Surface Intersection • For sphere, If the discriminant is negative, the ray does not

Surface Intersection • For sphere, If the discriminant is negative, the ray does not intersect the sphere. Otherwise, intersection coordinates are obtained using smaller s.