samedi 18 mars 2017

Can't achieve a beautiful transparence in my raytracer

I am working on a ray tracer for school, the result is not bad but I am not fully satisfied.

The reference image is this one: reference: Cornell box

And my render is like that: my render: Cornell box

As you can see in the second image (my one) the the left ball, who has a reflective indice of 1 (100 percent), has not the same kind of reflection than in the first image, the right ball, who is transparent with an indice of refraction of 1.6 in this render (I tried from 1.3 to 1.9) doesn't look like a glass ball.

I am now looking for where could come my problem since more than a week and I have still no idea, here is my recursive function:

t_color         reflection_refraction(t_env *e, t_ray *ray, int depth, float coef)
{
    t_ref       r;
    float       kr;
    t_color     composed_color;

    r.reflect_color = new_color(BLACK);
    r.refract_color = new_color(BLACK);
    ray->t = get_ray_intersection(e->scene->objects, ray);
    if (!(ray->hitpoint.object))
        return (e->scene->background_color);
    r.color = illuminate(e, ray);
    if (depth == MAX_DEPTH || coef < 0.02)
        return (r.color);
    r.reflect_ray = *ray;
    r.refract_ray = *ray;
    if (r.reflect_ray.hitpoint.object->material.property == REFLECTIVE)
    {
        reflected_ray(&(r.reflect_ray));
        r.color = add_color(r.color, reflection_refraction(e, &(r.reflect_ray), depth + 1, r.reflect_ray.hitpoint.object->material.reflexion * coef));
    }
    else if (r.refract_ray.hitpoint.object->material.property == TRANSMITIVE)
    {
        fresnel(ray, &kr);
        if (kr < 1)
        {
            if (!refracted_ray(&(r.refract_ray)))
                r.refract_color = reflection_refraction(e, &(r.refract_ray), depth + 1, r.refract_ray.hitpoint.object->material.refraction * coef);
        }
        reflected_ray(&(r.reflect_ray));
        r.reflect_color = reflection_refraction(e, &(r.reflect_ray), depth + 1, coef * r.reflect_ray.hitpoint.object->material.reflexion * coef);
        composed_color = add_color(scalar_color(kr, r.reflect_color), scalar_color(1 - kr, r.refract_color));
        r.color = add_color(r.color, composed_color);
    }
    return (scalar_color(coef, r.color));
}





Aucun commentaire:

Enregistrer un commentaire