Thursday, January 8, 2015

Hard and Soft Shadows

HARD SHADOWS
UMBRA - Fully Shadowed Region.
When the light is Point Light or Directional Light Source then we have only umbra
PENUMBRA - Partially Shadowed Region
When the light is Area Light Source then we have both umbra and penumbra
Definition OF SHADOWS: comparative darkness given by shelter from direct light; patch of shade projected by a body intercepting light
PSEUDO CODE:
for each light source
  if face is a back face with respect to light source i.e Check N.L < 0
     inShadow = TRUE;
  else
    inShadow = FALSE;
    p = p + εL // L is the light ray and ε is epsilon value and is near to 
zero so that image look clear otherwise there will be black spots on the
image
    shadowRay = from intersection point p to light source;
    for each object in the scene
       inShadow = intersectObject(shadowRay);
       if inShadow is TRUE
       break out of loop;//if even a single object is in the way then why
do we need to check for other objects in the scene
return inShadow;
C++ CODE:
if(normal.dot(L) < 0){
  inShadow = true;
}
else{
  inShadow = false;
  float epsilon = 0.000009;
  SbVec3f shadowRayDirection = lights[j].getLocation() - point;
  SbVec3f shadowRayStart = point + epsilon * shadowRayDirection ;
  for(int z =0 ; z<(int)objects.size();z++){
    if(objects[z].getTransparency() > 0){
    }
    else{
      float shadowT=objects[z].intersection(shadowRayStart,shadowRayDirection);
      if(shadowT >= 0){
        inShadow = true;
        break;
      }
    }
  }
}
NOTE: I am considering if the object is transparent then it will not 
cause shadow

No comments:

Post a Comment