-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalIntegrator.cppm
More file actions
52 lines (43 loc) · 1.27 KB
/
Copy pathNormalIntegrator.cppm
File metadata and controls
52 lines (43 loc) · 1.27 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module;
#include <optional>
export module Kairo.Foundation.RayTracer.NormalIntegrator;
import Kairo.Foundation.Math.Vector;
import Kairo.Foundation.Geometry.Ray;
import Kairo.Foundation.RayTracer.Color;
import Kairo.Foundation.RayTracer.Types;
import Kairo.Foundation.RayTracer.Scene;
export namespace kairo::foundation::raytracer
{
using namespace kairo::foundation::math;
using namespace kairo::foundation::geometry;
// Normal rendering maps surface normal components from [-1, 1] to [0, 1].
// It is the fastest way to see wrong winding, bad transforms, or incorrect
// sphere normals before lighting makes the problem harder to read.
[[nodiscard]]
inline Color3f TraceNormal(
const Scene& scene,
const Rayf& ray,
RenderStats* stats)
{
const std::optional<SurfaceHit> hit =
scene.Intersect(ray, stats);
if (!hit)
{
if (stats)
{
++stats->MissCount;
}
return scene.Settings.Background;
}
if (stats)
{
++stats->HitCount;
}
return
{
hit->Normal.x * 0.5f + 0.5f,
hit->Normal.y * 0.5f + 0.5f,
hit->Normal.z * 0.5f + 0.5f
};
}
}