-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce perm<T> * uber material * Update plan.md
- Loading branch information
Showing
10 changed files
with
189 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,54 @@ | ||
namespace rt { | ||
struct Hit_Info; | ||
|
||
// @TODO: remove polymorphism; use function pointers instead so we can use malloc | ||
// and don't have to care about vtable ptr. -- kkubacki 07.09.2023 | ||
struct Material { | ||
// Returns true when the ray was absorbed. | ||
// Calculates the new color and ray. | ||
virtual bool | ||
scatter(Ray const &in, Hit_Info const &hi, Vec3 &attenuation_color, Ray &out) = 0; | ||
|
||
virtual Vec3 | ||
emitted() { | ||
return {0, 0, 0}; | ||
} | ||
}; | ||
|
||
struct Lambertian : Material { | ||
Vec3 albedo; | ||
|
||
Lambertian(Vec3 albedo_); | ||
|
||
[[nodiscard]] bool | ||
scatter(Ray const &in, | ||
Hit_Info const &hi, | ||
Vec3 &attenuation_color, | ||
Ray &out) override; | ||
enum Material_Type { | ||
MaterialType_None = 0, | ||
MaterialType_Lambertian, | ||
MaterialType_Metal, | ||
MaterialType_Dielectric, | ||
MaterialType_Diffuse_Light, | ||
|
||
MaterialType__count | ||
}; | ||
|
||
struct Metal : Material { | ||
Vec3 albedo; | ||
f32 fuzz; | ||
|
||
Metal(Vec3 albedo_, f32 fuzz_); | ||
|
||
[[nodiscard]] bool | ||
scatter(Ray const &in, | ||
Hit_Info const &hi, | ||
Vec3 &attenuation_color, | ||
Ray &out) override; | ||
struct Material { | ||
Material_Type type; | ||
union { | ||
struct { | ||
Vec3 albedo; | ||
} lambertian; | ||
struct { | ||
Vec3 albedo; | ||
f32 fuzz; | ||
} metal; | ||
struct { | ||
f32 refraction_index; | ||
} dielectric; | ||
struct { | ||
Vec3 albedo; | ||
} diffuse_light; | ||
}; | ||
}; | ||
|
||
struct Dielectric : Material { | ||
f32 refraction_index; | ||
[[nodiscard]] bool | ||
scatter(Material const &material, | ||
Ray const &in, | ||
Hit_Info const &hi, | ||
Vec3 &attenuation_color, | ||
Ray &out); | ||
|
||
Dielectric(f32 refraction_index_); | ||
[[nodiscard]] Vec3 | ||
emit(Material const &material); | ||
|
||
[[nodiscard]] bool | ||
scatter(Ray const &in, | ||
Hit_Info const &hi, | ||
Vec3 &attenuation_color, | ||
Ray &out) override; | ||
}; | ||
[[nodiscard]] Material | ||
make_lambertian(Vec3 const &albedo); | ||
|
||
struct Diffuse_Light : Material { | ||
Vec3 color; | ||
Diffuse_Light(Vec3 col_) : color(col_) {}; | ||
[[nodiscard]] Material | ||
make_metal(Vec3 const &albedo, f32 fuzz); | ||
|
||
bool | ||
scatter(Ray const &, Hit_Info const &, Vec3 &, Ray &) { | ||
return false; | ||
} | ||
[[nodiscard]] Material | ||
make_dielectric(f32 refraction_index); | ||
|
||
virtual Vec3 | ||
emitted() { | ||
return color; | ||
} | ||
}; | ||
[[nodiscard]] Material | ||
make_diffuse_light(Vec3 const &albedo); | ||
} // namespace rt |
Oops, something went wrong.