title: Ray Tracing - Reflection
body: <p>I'm now working on the ray tracer, reflection part. I have everything working correctly, including creating a sphere with shadow. Now, I'm implementing the reflection part. However, I couldn't get it. My algorithm is below:</p>
  
  <pre><code>traceRay(Ray ray, int counter){
  // look through the intersection between ray and list of objects
  // find the final index aka the winning index, (if final index == -1, return background color)
  // then calculate the intersection point
  
  // perform reflection calculation here
  if(counter &gt; 1  &amp;&amp; winning object's reflectivity &gt; 1 ){
    //get the intersection normal, vector N
    //Calculate the reflection ray, R
    // let I is the inverse of direction of incoming ray
    //Calculate R = 2aN - I (a = N dotProduct I)
  
    // the reflection ray is origin at the point of intersection between incoming ray and sphere with the R direction
    Ray reflecRay (intersection_poisition, R);
  
    Color reflection = traceRay(reflecRay, counter + 1);
    // multiply by fraction ks
    reflection = reflection * ks;
  }
  
  
  // the color of the sphere calculated using phong formula in shadeRay function
  Color prefinal = shadeRay();
  
  
  // return the total color of prefinal + reflection
  
  }
  </code></pre>
  
  <p>I trying to get the reflection but couldn't get it, can anyone please let me know if my algorithm for traceRay function is correct?</p>