CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
61 lines
1.9 KiB
C++
61 lines
1.9 KiB
C++
#include "hip/hip_runtime.h"
|
|
#ifndef SPHEREH
|
|
#define SPHEREH
|
|
|
|
#include "hitable.h"
|
|
|
|
class sphere: public hittable {
|
|
public:
|
|
__host__ __device__ sphere() {}
|
|
__host__ __device__ sphere(vec3 cen, float r, material *m) : center(cen), radius(r), mat_ptr(m) {};
|
|
__host__ __device__ sphere(sphere &&other)
|
|
: center(other.center), radius(other.radius), mat_ptr(other.mat_ptr) {
|
|
other.mat_ptr = nullptr;
|
|
}
|
|
__host__ __device__ sphere& operator=(sphere &&other) {
|
|
delete mat_ptr;
|
|
center = other.center;
|
|
radius = other.radius;
|
|
mat_ptr = other.mat_ptr;
|
|
other.mat_ptr = nullptr;
|
|
return *this;
|
|
}
|
|
__host__ __device__ ~sphere() {
|
|
delete mat_ptr;
|
|
}
|
|
__host__ __device__ virtual bool hit(const ray& r, float tmin, float tmax, hit_record& rec) const;
|
|
vec3 center;
|
|
float radius;
|
|
material *mat_ptr;
|
|
};
|
|
|
|
__host__ __device__ bool sphere::hit(const ray& r, float t_min, float t_max, hit_record& rec) const {
|
|
vec3 oc = r.origin() - center;
|
|
float a = dot(r.direction(), r.direction());
|
|
float b = dot(oc, r.direction());
|
|
float c = dot(oc, oc) - radius*radius;
|
|
float discriminant = b*b - a*c;
|
|
if (discriminant > 0) {
|
|
float temp = (-b - sqrt(discriminant))/a;
|
|
if (temp < t_max && temp > t_min) {
|
|
rec.t = temp;
|
|
rec.p = r.point_at_parameter(rec.t);
|
|
rec.normal = (rec.p - center) / radius;
|
|
rec.mat_ptr = mat_ptr;
|
|
return true;
|
|
}
|
|
temp = (-b + sqrt(discriminant)) / a;
|
|
if (temp < t_max && temp > t_min) {
|
|
rec.t = temp;
|
|
rec.p = r.point_at_parameter(rec.t);
|
|
rec.normal = (rec.p - center) / radius;
|
|
rec.mat_ptr = mat_ptr;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
#endif
|