Lambertian shading illuminates all the front of a sphere I've sucessfully implemented a ray tracer from scratch in C and it's marvelous:

The surface normal on this sphere is taken by computing the intersection point, A, and treating this as a euclidean vector with origin, B, the center of the sphere. To normalize it, I first subtracted A with B, yielding C:
C = (Ax-Bx,Ay-By)
From this, it's divided by the magnitude:
N = C/|C|
The illumination is calculated by taking the dot product of N and LIGHT_SOURCE and multiplying it with 255:
if (dot_product&lt;0.0) dot_product = 0.0;
illumination = (unsigned char)(dot_product*255.0);

When I tried setting the light source to (0.0, 0.0, -1.0), it produce something like this:

I expected the shade to be something like it's brighter on the middle and becoming more dimmer on the side.
Anyone know what's causing the problem?
Source code: https://gist.github.com/harieamjari/6297a35400460edbabbd8e39720ed0f5
This can be compiled if you already have libpng16.
I think there is a problem with your ray-sphere intersection.
It should go like this
sphere_normal = ray.origin - sphere_center;
b = dot(sphere_normal , ray.normalized_dir);
c = dot(sphere_normal , sphere_normal ) - sphere_radius*spheres_radius;
float disc = b * b - c;

float t = -1.0f;
if(disc &gt;= 0.0f)
t = -b +- sqrt(disc);

if(t &gt;= 0) // means ray intersects...
     

Check out scratchapixel to understand how I got this.
https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection