-
Notifications
You must be signed in to change notification settings - Fork 6
Standardize code for HLS #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ee32c11
3979043
1893a47
1741496
8d3c225
6ceb4ce
60c883a
8a73547
4644777
70c34f9
b92d9c2
635037d
5e96817
092b972
8afb9cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #ifndef HIT_RECORD_HPP | ||
| #define HIT_RECORD_HPP | ||
|
|
||
| #include "rtweekend.hpp" | ||
|
|
||
| class hit_record { | ||
| public: | ||
| real_t t; // | ||
| point p; // hit point | ||
| vec normal; // normal at hit point | ||
| bool front_face; // to check if hit point is on the outer surface | ||
| /*local coordinates for rectangles | ||
| and mercator coordintes for spheres */ | ||
| real_t u; | ||
| real_t v; | ||
|
|
||
| // To set if the hit point is on the front face | ||
| void set_face_normal(const ray& r, const vec& outward_normal) { | ||
| front_face = dot(r.direction(), outward_normal) < 0; | ||
| normal = front_face ? outward_normal : vec {} - outward_normal; | ||
| } | ||
| }; | ||
| #endif | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing end-of-line.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious... An IDE configuration bug? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,11 @@ | ||
| #ifndef HITTABLE_H | ||
| #define HITTABLE_H | ||
|
|
||
| #include "box.hpp" | ||
| #include "constant_medium.hpp" | ||
| #include "ray.hpp" | ||
| #include "rtweekend.hpp" | ||
| #include "vec.hpp" | ||
|
|
||
| class hit_record { | ||
| public: | ||
| float t; // | ||
| point p; // hit point | ||
| vec normal; // normal at hit point | ||
| bool front_face; // to check if hit point is on the outer surface | ||
| /*local coordinates for rectangles | ||
| and mercator coordintes for spheres */ | ||
| float u; | ||
| float v; | ||
|
|
||
| // To set if the hit point is on the front face | ||
| void set_face_normal(const ray& r, const vec& outward_normal) { | ||
| front_face = dot(r.direction(), outward_normal) < 0; | ||
| normal = front_face ? outward_normal : vec {} - outward_normal; | ||
| } | ||
| }; | ||
| #include "sphere.hpp" | ||
| #include "triangle.hpp" | ||
|
|
||
| using hittable_t = std::variant<sphere, triangle, constant_medium, box, xy_rect>; | ||
| #endif |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |||||
|
|
||||||
| #include <iostream> | ||||||
|
|
||||||
| #include "hitable.hpp" | ||||||
| #include "hit_record.hpp" | ||||||
| #include "texture.hpp" | ||||||
| #include "vec.hpp" | ||||||
| #include "visit.hpp" | ||||||
|
|
@@ -15,30 +15,29 @@ struct lambertian_material { | |||||
| lambertian_material(const texture_t& a) | ||||||
| : albedo { a } {} | ||||||
|
|
||||||
| bool scatter(auto& ctx, const ray& r_in, const hit_record& rec, | ||||||
| color& attenuation, ray& scattered) const { | ||||||
| auto& rng = ctx.rng; | ||||||
| bool scatter(auto& ctx, const ray& r_in, const hit_record& rec, color& attenuation, | ||||||
| ray& scattered) const { | ||||||
| LocalPseudoRNG rng { toseed(r_in.direction(), r_in.origin()) }; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| vec scatter_direction = rec.normal + rng.unit_vec(); | ||||||
| scattered = ray(rec.p, scatter_direction, r_in.time()); | ||||||
| // Attenuation of the ray hitting the object is modified based on the color | ||||||
| // at hit point | ||||||
| attenuation *= | ||||||
| dev_visit([&](auto&& arg) { return arg.value(ctx, rec); }, albedo); | ||||||
| attenuation *= dev_visit([&](auto&& t) { return t.value(ctx, rec); }, albedo); | ||||||
| return true; | ||||||
| } | ||||||
| color emitted(auto&, const hit_record& rec) { return color(0, 0, 0); } | ||||||
| color emitted(auto&, const hit_record& rec) { return color(0.f, 0.f, 0.f); } | ||||||
| texture_t albedo; | ||||||
| }; | ||||||
|
|
||||||
| struct metal_material { | ||||||
| metal_material() = default; | ||||||
| metal_material(const color& a, float f) | ||||||
| metal_material(const color& a, real_t f) | ||||||
| : albedo { a } | ||||||
| , fuzz { std::clamp(f, 0.0f, 1.0f) } {} | ||||||
|
|
||||||
| bool scatter(auto& ctx, const ray& r_in, const hit_record& rec, | ||||||
| color& attenuation, ray& scattered) const { | ||||||
| auto& rng = ctx.rng; | ||||||
| bool scatter(auto&, const ray& r_in, const hit_record& rec, color& attenuation, | ||||||
| ray& scattered) const { | ||||||
| LocalPseudoRNG rng { toseed(r_in.direction(), r_in.origin()) }; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| vec reflected = reflect(unit_vector(r_in.direction()), rec.normal); | ||||||
| scattered = ray(rec.p, reflected + fuzz * rng.in_unit_ball(), r_in.time()); | ||||||
| // Attenuation of the ray hitting the object is modified based on the color | ||||||
|
|
@@ -49,7 +48,7 @@ struct metal_material { | |||||
|
|
||||||
| color emitted(auto&, const hit_record& rec) { return color(0, 0, 0); } | ||||||
| color albedo; | ||||||
| float fuzz; | ||||||
| real_t fuzz; | ||||||
| }; | ||||||
|
|
||||||
| struct dielectric_material { | ||||||
|
|
@@ -65,20 +64,19 @@ struct dielectric_material { | |||||
| return r0 + (1 - r0) * sycl::pow((1 - cosine), 5.0f); | ||||||
| } | ||||||
|
|
||||||
| bool scatter(auto& ctx, const ray& r_in, const hit_record& rec, | ||||||
| color& attenuation, ray& scattered) const { | ||||||
| bool scatter(auto&, const ray& r_in, const hit_record& rec, color& attenuation, | ||||||
| ray& scattered) const { | ||||||
| // Attenuation of the ray hitting the object is modified based on the color | ||||||
| // at hit point | ||||||
| auto& rng = ctx.rng; | ||||||
| LocalPseudoRNG rng { toseed(r_in.direction(), r_in.origin()) }; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| attenuation *= albedo; | ||||||
| float refraction_ratio = rec.front_face ? (1.0f / ref_idx) : ref_idx; | ||||||
| real_t refraction_ratio = rec.front_face ? (1.0f / ref_idx) : ref_idx; | ||||||
| vec unit_direction = unit_vector(r_in.direction()); | ||||||
| float cos_theta = sycl::fmin(-sycl::dot(unit_direction, rec.normal), 1.0f); | ||||||
| float sin_theta = sycl::sqrt(1.0f - cos_theta * cos_theta); | ||||||
| real_t cos_theta = sycl::fmin(-sycl::dot(unit_direction, rec.normal), 1.0f); | ||||||
| real_t sin_theta = sycl::sqrt(1.0f - cos_theta * cos_theta); | ||||||
| bool cannot_refract = refraction_ratio * sin_theta > 1.0f; | ||||||
| vec direction; | ||||||
| if (cannot_refract || | ||||||
| reflectance(cos_theta, refraction_ratio) > rng.float_t()) | ||||||
| if (cannot_refract || reflectance(cos_theta, refraction_ratio) > rng.real()) | ||||||
| direction = reflect(unit_direction, rec.normal); | ||||||
| else | ||||||
| direction = refract(unit_direction, rec.normal, refraction_ratio); | ||||||
|
|
@@ -104,7 +102,7 @@ struct lightsource_material { | |||||
| template <typename... T> bool scatter(T&...) const { return false; } | ||||||
|
|
||||||
| color emitted(auto& ctx, const hit_record& rec) { | ||||||
| return dev_visit([&](auto&& arg) { return arg.value(ctx, rec); }, emit); | ||||||
| return dev_visit([&](auto&& t) { return t.value(ctx, rec); }, emit); | ||||||
| } | ||||||
|
|
||||||
| texture_t emit; | ||||||
|
|
@@ -116,12 +114,11 @@ struct isotropic_material { | |||||
| isotropic_material(texture_t& a) | ||||||
| : albedo { a } {} | ||||||
|
|
||||||
| bool scatter(auto& ctx, const ray& r_in, const hit_record& rec, | ||||||
| color& attenuation, ray& scattered) const { | ||||||
| auto& rng = ctx.rng; | ||||||
| bool scatter(auto& ctx, const ray& r_in, const hit_record& rec, color& attenuation, | ||||||
| ray& scattered) const { | ||||||
| LocalPseudoRNG rng { toseed(r_in.direction(), r_in.origin()) }; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I do not know why I am getting bored here... |
||||||
| scattered = ray(rec.p, rng.in_unit_ball(), r_in.time()); | ||||||
| attenuation *= | ||||||
| dev_visit([&](auto&& arg) { return arg.value(ctx, rec); }, albedo); | ||||||
| attenuation *= dev_visit([&](auto&& t) { return t.value(ctx, rec); }, albedo); | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -133,5 +130,4 @@ struct isotropic_material { | |||||
| using material_t = | ||||||
| std::variant<lambertian_material, metal_material, dielectric_material, | ||||||
| lightsource_material, isotropic_material>; | ||||||
|
|
||||||
| #endif | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the feeling that if we remove the
std::monostatefrom the material it will always create aspherehere even when there is no intersection.