-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.hpp
38 lines (34 loc) · 866 Bytes
/
Utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include <Siv3D.hpp>
namespace RayT {
namespace Utils
{
// リニア空間からsRGB空間へ変換
constexpr ColorF LinearToGamma(const ColorF color, const double gammaFactor) {
const double recipGammaFactor = 1 / gammaFactor;
return {
Math::Pow(color.r, recipGammaFactor),
Math::Pow(color.g, recipGammaFactor),
Math::Pow(color.b, recipGammaFactor)
};
}
// sRGB空間からリニア空間へ変換
constexpr ColorF GammaToLinear(const ColorF color, const double gammaFactor) {
return {
Math::Pow(color.r, gammaFactor),
Math::Pow(color.g, gammaFactor),
Math::Pow(color.b, gammaFactor)
};
}
// 単位球の中にあるベクトルをランダムに生成
inline Vec3 RandomVec3InUnitSphere()
{
while (true)
{
const Vec3 v = RandomVec3({ -1, 1 }, { -1, 1 }, { -1, 1 });
if (v.lengthSq() <= 1)
return v;
}
}
}
}