# Strange sphere reflection effects in ray tracing project. I cannot figure out what causes them

I started a ray tracing project in Python. I made a CUDA kernel and a trace() function for each pixel. It works perfectly when calculating intersections, shadows and lambert shading, however when I introduce a reflection from the surface of a sphere I get a 'band' around the edge of the projected sphere disk and I cannot figure out why.

Image results: https://imgur.com/a/LoXOyl5

## My reflection algorithm:

1. Find point P of the intersection.
2. Find normal vector N at the intersection with C being the sphere center:
    N = P - C
N = N / norm(N)

1. Find reflection vector R using (where D is the original ray direction:
    R = D - 2 * (D * N ) * N
R = R / norm(R)

1. Shift point P along R a little bit (to avoid reflection acne, adding this didn't solve the problem)
    P = P + 1e-4 * R

1. Call the ray trace function (only one more time) again as:
    color_refl = trace(ray_origin=P, ray_direction=R)

1. Add the reflected color using:
    color = color + color_refl * reflect_intensity


Notes:

• Between step 2 and step 3 I calculate the Lambert shading which works quite well.
• Reflections that bounce off a plane work perfectly.
• I use a CUDA kernel which does not support recursive function calls, so I made another trace function with a different name that doesn't calculate reflections. (that's why there is only one reflection call)

Here is the source code for the trace and reflection trace functions: https://github.com/Speterius/ray_tracing/blob/master/cuda_ray_tracing.py

R = D - 2 * dot(D, N) * N

R[i] = D[i] - 2 * (D[i] * N[i]) * N[i]