Remove unnessecary conversions between float and double in cast_scene
This commit is contained in:
parent
a0353edd89
commit
ad3cba9f78
2 changed files with 6 additions and 6 deletions
|
@ -75,7 +75,7 @@ struct Scene {
|
|||
|
||||
Scene() : gen(rd()), dis(0.0, 1.0) {}
|
||||
|
||||
float distribution() {
|
||||
double distribution() {
|
||||
return dis(gen);
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ struct Scene {
|
|||
auto o = std::make_unique<Object>();
|
||||
|
||||
std::string err;
|
||||
if (!tinyobj::LoadObj(&o->attrib, &o->shapes, &o->materials, &err, path.data()))
|
||||
if (!tinyobj::LoadObj(&o->attrib, &o->shapes, &o->materials, &err, path.data())) [[unlikely]]
|
||||
std::println("Could not load obj: {}", err);
|
||||
|
||||
return *objects.emplace_back(std::move(o));
|
||||
|
|
|
@ -216,9 +216,9 @@ std::optional<SceneResult> cast_scene(const Ray ray, Scene& scene, const bool us
|
|||
// and naive monte carlo without PDF
|
||||
if (num_indirect_samples > 0) {
|
||||
for (int i = 0; i < num_indirect_samples; i++) {
|
||||
const float theta = scene.distribution() * std::numbers::pi;
|
||||
const float cos_theta = cos(theta);
|
||||
const float sin_theta = sin(theta);
|
||||
const double theta = scene.distribution() * std::numbers::pi;
|
||||
const double cos_theta = cos(theta);
|
||||
const double sin_theta = sin(theta);
|
||||
|
||||
const auto [rotX, rotY] = orthogonal_system(hit->normal);
|
||||
|
||||
|
@ -229,7 +229,7 @@ std::optional<SceneResult> cast_scene(const Ray ray, Scene& scene, const bool us
|
|||
glm::dot({rotX.z, rotY.z, hit->normal.z}, sampled_dir)};
|
||||
|
||||
if (const auto indirect_result = cast_scene(Ray(ray.origin, rotated_dir), scene, use_bvh, depth + 1))
|
||||
result.indirect += indirect_result->combined * cos_theta;
|
||||
result.indirect += indirect_result->combined * static_cast<float>(cos_theta);
|
||||
}
|
||||
|
||||
result.indirect /= num_indirect_samples;
|
||||
|
|
Loading…
Add table
Reference in a new issue