Thursday, January 8, 2015

Reflection and Glossy Reflection

Reflection: When the object is shiny (example mirror) we see the reflection of other object in the shiny one. I hope everyone know the definition of reflection :)
ALGORITHM:    

1. For each light source in the scene if object is shiny construct a 
reflective ray from intersection point and recursively call your shade
or whatever you call with the reflective ray passed to it.

PSEUDO CODE: 

for each light source
  compute reflective ray R (or H);
  c += diffuse;
  c += specular components;
if ( recursionDepth < MAXRECURSION)
  if (object is shiny)
    compute reflection of the ray, R1;
    c += Ks * shade( R1, recursionDepth + 1 );

C++ CODE:

float shine = 0.19;
if(recursionDepth < 3){      
   if(spheres[locSphere].getShininess() > 0){
      SbVec3f V = point - rayStart;
   reflectionRay = -2*((V.dot(normal))*normal) + V;
      pixelColor += shine * shade(point,reflectionRay, recursionDepth+1);
   }
}
 
NOTE: float shine means how much the object is shiny or what is the value 
of shininess of that object. recursiveDepth is how many times you want 
reflection of the same object 
GLOSSY REFLECTION: Distributed Ray Tracing
Some surfaces, like metal, are somewhere between an ideal mirror and a
diffuse surface. Some discernible image is visible in the reflection but it is blurred. We can simulate this by randomly perturbing ideal reflection rays.

Only two details need to be worked out: how to choose the vector r', and what to do when the resulting perturbed ray is below the surface from which the ray is reflected. The latter detail is usually settled by returning a zero color when the ray is below the surface.

The reflection ray is perturbed to a random vector r’. To choose r', we again sample a random square. This square is perpendicular to r and has width a which controls the degree of blur. We can set up the square’s orientation by creating an orthonormal basis with w = r using the techniques we used in soft shadows. Then, we create a random point in the 2D square with side length 'a' centered at the origin. If we have 2D sample points
(ξ, ξ') ∈ [0, 1]^2, then the analogous point on the desired square is

(u) = −a/2 + ξa,
(v) = −a/2 + ξ'a

Because the square over which we will perturb is parallel to both the u and v vectors, the ray r' is just

r' = r + (u) u + (v) v.

Note that r' is not necessarily a unit vector and should be normalized if your code requires that for ray directions.

REFERENCE: The Utah University computer graphics ray tracer. 

No comments:

Post a Comment