aboutsummaryrefslogtreecommitdiff
path: root/src/render.hpp
blob: 810268603d9c5d0038047559d558e3e484377cd9 (plain)
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
53
54
55
56
57
58
59
60
61
#ifndef RENDER_H
#define RENDER_H

#include "core/vector.hpp"
#include "core/ray.hpp"
#include "scene.hpp"

class Random {
    public:
        void seed(unsigned seed);
        double operator()();

    private:
        unsigned m_seed;
};

// Samples a random direction in a hemisphere, cosine weighed
// https://blog.thomaspoulet.fr/uniform-sampling-on-unit-hemisphere/
class Sampler {
    public:
        Sampler(Random &src);

        Vec3d sample(const Vec3d &norm);

    private:
        Random &m_src;
};

class Renderer {
    public:
    Renderer(const Scene &scn, Vec3d eye, Vec3d target, unsigned width, unsigned height, unsigned maxhops);

    Color render(unsigned x, unsigned y, unsigned samples);

    unsigned m_width, m_height;
    Sampler m_sampler;

    private:
    void recalculate();
    Ray findray(double x, double y) const ;

    Color pathtrace_sample(const Ray &r, unsigned hop);
    // Will return first result less than chk_dist. 
    // This is ignored if chk_dist is 0.
    // If dist is non-null the resulting distance is written here.
    const Shape* cast_ray(const Ray &r, double chk_dist, double *dist);

    const Scene &m_scn;

    Random m_random;

    // User options
    Vec3d m_eye, m_target;
    unsigned m_maxhops;

    // Calculated values
    Vec3d m_qx, m_qy, m_blc;

};

#endif