Ray Trace - Shadows

Shadow implementation process in Ray tracer:
To generate shadows, we need to traverse all the light sources and find if there is any object  between  currently intersected object and the light. If, there is an object then the object is in shadow and we do not need to calculate the color of that pixel.


bool inshadow = false;
for(int i = 0 ;i<numberoflights; i++){

     lightDirection  =normalise( light[i] - intersectionPoint);

     lightOrigin = intersectionPoint;
     lightDist = 100000.0f;
     for(int j = 0; j<numberOfObjects; j++){
          if( i != j && object[i]->intersect(lightorigin,lightdirection,lightDist)){
              inshadow = true;



Problems: The problem which I faced generating shadows was that there was an object at the position of light and hence, that was coming in between the light and the other objects. Hence the shadow was not perfectly generated.

Wrong shadow image:

Corrected Image:

No comments:

Post a Comment