110 likes | 112 Vues
Project 3 Help Session:. Ray Tracing. Getting Started. Download the starter pack. sample_ray.exe ray-skel directory scenes directory Look at the Road Map Try tracing some scenes with sample_ray.exe. Scenes. Examples (in scenes/simple/) Syntax (and how to extend the parser).
E N D
Project 3 Help Session: Ray Tracing
Getting Started • Download the starter pack. • sample_ray.exe • ray-skel directory • scenes directory • Look at the Road Map • Try tracing some scenes with sample_ray.exe
Scenes • Examples (in scenes/simple/) • Syntax (and how to extend the parser)
Materials • emissive: ke, the emissive color. • ambient: ka, the ambient color. • specular: ks, the specular color. • reflective: kr, the reflective color. Defaults to ks if not specified. • diffuse: kd, the diffuse color. • transmissive: kt, the ability for this material to transmit light in each channel (as a 3-tuple). • shininess: ns, the shininess (between 0 and 1). • index: the material's index of refraction.
Casting Rays • Two steps: • Create the ray. ray r( Vec3d(0,0,0), Vec3d(0,0,0),ray::VISIBILITY ); 2. Then cast it by calling traceRay(r). isect i; // an intersection object. if( scene->intersect( r, i ) ) { // There was an intersection with an object in the scene. // Do something with i. (Perhaps cast more rays from the point // of intersection. }else{ // There is no intersection, the ray is shot into the black void of space. }
ray Class • ray r (start position, direction, RayType) enum RayType{VISIBILITY, REFLECTION, REFRACTION, SHADOW}; • r.at(t), a method that determines the position of the ray r as a function of t, the distance from the start position.
isect Class • An isect represents the location where a ray intersects a specific object. • Important member variables: const SceneObject *obj; // the object that was intersected. double t; // the distance along the ray where it occurred. Vec3d N; // the normal to the surface where it occurred Vec2d uvCoordinates; // texture coordinates on the surface. [1.0,1.0] Material *material; // non-NULL if exists a unique material for this intersect. const Material &getMaterial() const; // return the material to use *red ones are important
The Skeleton Code • Intersection for boxes and spheres is missing. (Box::intersectLocal()) • Implement the Phong shading model. (Material::shade()) • Implement recursive ray tracing! This includes Shadow Attenuation, Reflection, Refraction, and Antialiasing. ( RayTracer::traceRay())
intersectLocal() • The ray and object are transformed back to the origin. • Only write intersect code for the geometry in canonical form! (i.e. the unit sphere and the box extending 0.5 in all directions.)
The Complexities of Refraction • Indices of refraction • Remember Snell’s Law? • How can you use the normal to determine whether you are entering or exiting?? nair=1.00029 nglass=1.5
RAY_EPSILON • To avoid round-off error, add RAY_EPSILON (=0.0001) to the start position of rays fired from points of intersection. given isect i and ray r: new_position = r.at(i.t + RAY_EPSILON) RAY_EPSILON