More timing functions
This commit is contained in:
parent
6331a2bf79
commit
321c677da2
12 changed files with 184 additions and 129 deletions
43
sphere.hpp
43
sphere.hpp
|
|
@ -7,11 +7,11 @@
|
|||
struct sphere : hittable {
|
||||
/* Attributes */
|
||||
point3 center;
|
||||
double radius;
|
||||
float radius;
|
||||
std::shared_ptr<material> mat_ptr;
|
||||
|
||||
/* Contructor */
|
||||
sphere(point3 c, double r, std::shared_ptr<material> m)
|
||||
sphere(point3 c, float r, std::shared_ptr<material> m)
|
||||
{
|
||||
center = c;
|
||||
radius = r;
|
||||
|
|
@ -19,49 +19,42 @@ struct sphere : hittable {
|
|||
}
|
||||
|
||||
/* Virtual methods declaration */
|
||||
virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const override;
|
||||
bool hit(const ray& r, float t_min, float t_max, hit_record& rec) const;
|
||||
};
|
||||
|
||||
/* Virtual method implementations */
|
||||
bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) const
|
||||
bool sphere::hit(const ray& r, float t_min, float t_max, hit_record& rec) const
|
||||
{
|
||||
rmt_ScopedCPUSample(Sphere_Hit, RMTSF_Aggregate);
|
||||
|
||||
// Part 1
|
||||
|
||||
/* NOTE: This function is called too many times (and too fast) for it to be
|
||||
profiled in a usual way using Remotery. */
|
||||
|
||||
TIMED_BLOCK();
|
||||
|
||||
vec3 oc = r.origin - center;
|
||||
double a = r.direction.length_squared();
|
||||
double half_b = dot(oc, r.direction);
|
||||
double c = oc.length_squared() - radius*radius;
|
||||
float a = r.direction.length_squared();
|
||||
float half_b = dot(oc, r.direction);
|
||||
float c = oc.length_squared() - radius*radius;
|
||||
|
||||
|
||||
// Part 2
|
||||
|
||||
double discriminant = half_b*half_b - a*c;
|
||||
float discriminant = half_b*half_b - a*c;
|
||||
if (discriminant < 0)
|
||||
return false;
|
||||
double sqrtd = sqrt(discriminant);
|
||||
|
||||
float sqrtd = sqrt(discriminant);
|
||||
|
||||
// Find the nearest root that lies in the acceptable range
|
||||
// Part 3
|
||||
|
||||
double root = (-half_b - sqrtd) / a;
|
||||
float root = (-half_b - sqrtd) / a;
|
||||
if (root < t_min || t_max < root)
|
||||
{
|
||||
root = (-half_b + sqrtd) / a;
|
||||
if (root < t_min || t_max < root)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Part 4
|
||||
|
||||
|
||||
rec.t = root;
|
||||
rec.p = r.at(rec.t);
|
||||
vec3 outward_normal = (rec.p - center) / radius;
|
||||
rec.set_face_normal(r, outward_normal);
|
||||
rec.mat_ptr = mat_ptr;
|
||||
|
||||
rec.mat_ptr = mat_ptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue