situation:

I've implemented a Whitted style ray tracing in C. Everything appear to works except the shadow cast by small object on big far objects

The problem :

red sphere have radius 0.5 orange sphere have radius 200 zooming: more: increasing the distance and the radius of the orange sphere:

Question:

So fare, I could only suspect rounding error due to the fact that I use float. In "normal" situation, the shadows work great. Have you already encounter that kind of error ? Is my guess correct, or could that be something else ?

Not sure the code could help because messy, but there it is:

static inline uint8_t   diffuse(const struct s_bvh *bvh,
const t_lght *lght, const t_hinfo *hi, t_vec3f diff)
{
t_vec3f         light;
struct s_hit    h;
float           dp;
float           length;

//make the [hit_pts -> light_pts] vector
sub_(lght->pts, hi->r->o, hi->r->d);
length = norm(hi->r->d);
//minimum to avoid self intersection
h.min = 0.001f;
//maximum
h.t = length;
normalize(hi->r->d);
dp = dotp(hi->n, hi->r->d);
if (dp > 0.0f)
{
//invertion fo the ray_direction and traverse the BVH tree
invert_(hi->r->d, hi->r->inv_d);
traverser(bvh, hi->r, &h, 1);
if (h.t < length)
return (0);
// else apply the light
s_scale(lght->color, dp, light);
return (1);
}
return (0);
}

void    diffusel(const struct s_bvhl *s, const t_hinfo *hi, t_vec3f color)
{
t_vec3f         ambi;
t_vec3f         diff;
uint32_t        i;

i = 0;
mult_(s->lghts.amb, color, ambi);
set_vector(diff, 0.f, 0.f, 0.f);
//for each light
while (i < s->lghts.count)
{
diffuse(&s->bvh, s->lghts.lghts + i, hi, diff);
++i;
}
mult_(color, diff, color);