Skip to content

Fix quadrics flipped near/far #1

Description

@mjy9088

*out_distance = (-eq.b - t_f_sqrt(discriminant)) / (2 * eq.a);
if (*out_distance > 0)
*out_is_front_face = true;
else
{
*out_distance = (-eq.b + t_f_sqrt(discriminant)) / (2 * eq.a);
if (*out_distance < 0)
return (false);
*out_is_front_face = false;
}

static t_err front(t_vars l, t_ray ray, t_ray_hit_records_builder *builder)
{
const t_f distance = (-l.y - l.sqrt_y2_4xz) / (2 * l.x);
const t_map_position point
= t_f3_add(ray.origin, t_f3_mul(ray.direction, distance));
t_map_normal normal;
t_f coord_x;
t_f coord_y;
if (distance <= 0)
return (false);
normal = t_ray_primitive_ellipsoid_normal(l, point);
t_ray_primitive_ellipsoid_coord(point, l.self.size, &coord_x, &coord_y);
return (
t_ray_hit_records_builder_add(builder, (t_ray_hit_record){
distance,
normal,
t_ray_material_from_color(l.self.material),
true,
coord_x,
coord_y,
})
);
}
static t_err back(t_vars l, t_ray ray, t_ray_hit_records_builder *builder)
{
const t_f distance = (-l.y + l.sqrt_y2_4xz) / (2 * l.x);
const t_map_position point
= t_f3_add(ray.origin, t_f3_mul(ray.direction, distance));
t_map_normal normal;
t_f coord_x;
t_f coord_y;
normal = t_ray_primitive_ellipsoid_normal(l, point);
t_ray_primitive_ellipsoid_coord(point, l.self.size, &coord_x, &coord_y);
return (
t_ray_hit_records_builder_add(builder, (t_ray_hit_record){
distance,
normal,
t_ray_material_from_color(l.self.material),
false,
coord_x,
coord_y,
})
);
}

l.n_distance = (-a.y - a.sqrt_y2_4xz) / (2 * a.x);
l.n = t_f3_add(ray.origin, t_f3_mul(ray.direction, l.n_distance));
l.n_hit = (l.n_distance >= 0 && l.n.z >= 0 && l.n.z <= a.self.size.z);
if (l.n_hit)
{
l.n_normal = t_ray_primitive_cylinder_side_normal(a, l.n);
l.n_x = t_f_rot(t_f_atan2(l.n.y, l.n.x));
l.n_y = l.n.z / a.self.size.z;
}
l.f_distance = (-a.y + a.sqrt_y2_4xz) / (2 * a.x);

l.n_distance = (-a.y - a.sqrt_y2_4xz) / (2 * a.x);
l.n = t_f3_add(ray.origin, t_f3_mul(ray.direction, l.n_distance));
l.n_hit = (l.n_distance >= 0 && l.n.z >= 0 && l.n.z <= a.self.size.z);
if (l.n_hit)
{
l.n_normal = t_ray_primitive_cone_side_normal(a, l.n);
l.n_x = t_f_rot(t_f_atan2(l.n.y, l.n.x));
l.n_y = l.n.z / a.self.size.z;
}
l.f_distance = (-a.y + a.sqrt_y2_4xz) / (2 * a.x);

If eq.a (or l.x, a.x) is negative, near/far is flipped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions