Post by sdiego on Mar 25, 2020 20:37:37 GMT
Hello! fails test №1
my world(scene):
w.s[0] = set_sphere(0);
w.max_obj = 1;
w.ar_count = 0;
push_obj((void*)(&w.s[0]), &normal_at_sp, &intersect_sp, &shade_hit_sp, &w, &w.s[0].m);
glass_sp(w.s[0]);
r = set_ray(set_v_p(0, 0, sqrt(2)/2, 1), set_v_p(0, 1, 0, 0));
xs.max_obj = 2;
xs.i[0].t = -sqrt(2)/2;
xs.i[0].obj = 0;
xs.i[1].t = sqrt(2)/2;
xs.i[1].obj = 0;
t_comps comps = prepare_computations(xs.i[1], r, w, xs);
double reflectance = schlick(comps);
my answer:
n1 = 1.000000
n2 = 1.000000
reflectance = 0.000000
comps.t 0.707107
my world(scene):
w.s[0] = set_sphere(0);
w.max_obj = 1;
w.ar_count = 0;
push_obj((void*)(&w.s[0]), &normal_at_sp, &intersect_sp, &shade_hit_sp, &w, &w.s[0].m);
glass_sp(w.s[0]);
r = set_ray(set_v_p(0, 0, sqrt(2)/2, 1), set_v_p(0, 1, 0, 0));
xs.max_obj = 2;
xs.i[0].t = -sqrt(2)/2;
xs.i[0].obj = 0;
xs.i[1].t = sqrt(2)/2;
xs.i[1].obj = 0;
t_comps comps = prepare_computations(xs.i[1], r, w, xs);
double reflectance = schlick(comps);
my answer:
n1 = 1.000000
n2 = 1.000000
reflectance = 0.000000
comps.t 0.707107
double schlick(t_comps c)
{
double cos;
double n;
double sin2_t;
double cos_t;
double r0;
cos = dot(c.eyev, c.normalv);
printf("n1 schlick = %f\n", c.n1);
printf("n2 schlick = %f\n", c.n2);
if (c.n1 > c.n2)
{
n = c.n1 / c.n2;
sin2_t = (n * n) * (1.0 - (cos * cos));
printf("sin2_t = %f\n", sin2_t);
if (sin2_t > 1.0)
{
return (1.0);
}
}
return (0.0);
}
t_comps prepare_computations(t_i i, t_ray r, t_world w, t_xs xs)
{
t_comps c;
t_vec normal;
c.t = i.t;
c.obj = i.obj;
c.point = position(r, c.t);
c.eyev = neg(r.d);
if ((*w.obj_ar[c.obj].loc_norm)(w.obj_ar[c.obj].obj, c.point, &normal) == 0)
printf("normal error");
else
c.normalv = normal;
if (dot(c.normalv, c.eyev) < 0)
{
c.inside = 1;
c.normalv = neg(c.normalv);
}
else
{
c.inside = 0;
}
c.over_point = add(c.point, mult(c.normalv, EPSILON));
c.reflectv = reflect(r.d, c.normalv);
c.under_point = sub(c.point, mult(c.normalv, EPSILON));
c = comps_n_calculate(w, i, xs, c);
return(c);
}
t_comps comps_n_calculate(t_world w, t_i i, t_xs xs, t_comps c)
{
t_arr containers;
containers.size = 0;
int aa = 0;
while (aa < xs.max_obj)
{
t_i curr_i = xs.i[aa];
if (curr_i.t == i.t && curr_i.obj == i.obj)
{
if (containers.size == 0)
{
c.n1 = 1.0;
}
else
{
c.n1 = w.obj_ar[containers.arr[containers.size - 1]].m->refractive_index;
}
}
int flag = -1;
int bb = 0;
while (bb < containers.size)
{
if (containers.arr[bb] == curr_i.obj)
{
flag = bb;
}
bb++;
}
if (flag > -1)
{
containers.arr[flag] = -1;
containers = removenull(containers);
}
else
{
containers.arr[containers.size] = curr_i.obj;
containers.size = containers.size + 1;
}
if (curr_i.t == i.t && curr_i.obj == i.obj)
{
if (containers.size == 0)
{
c.n2 = 1.0;
}
else
{
c.n2 = w.obj_ar[containers.arr[containers.size - 1]].m->refractive_index;
}
aa = xs.max_obj;
}
aa++;
}
return (c);
}