add alternate diffuse method
This commit is contained in:
parent
58f710c967
commit
3296ea3e81
2 changed files with 15 additions and 1 deletions
|
@ -87,6 +87,20 @@ pub fn random_in_unit_sphere(rng: *Random) Vec3 {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn random_unit_vector(rng: *Random) Vec3 {
|
||||
return unitVector(random_in_unit_sphere(rng));
|
||||
}
|
||||
|
||||
pub fn random_in_hemisphere(rng: *Random, normal: Vec3) Vec3 {
|
||||
const in_unit_sphere = random_in_unit_sphere(rng);
|
||||
if (in_unit_sphere.dot(normal) > 0) {
|
||||
// In the same hemisphere as the normal
|
||||
return in_unit_sphere;
|
||||
} else {
|
||||
return in_unit_sphere.mul(-1);
|
||||
}
|
||||
}
|
||||
|
||||
pub const Point3 = Vec3;
|
||||
|
||||
const assert = @import("std").debug.assert;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue