-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pathtracing.h
55 lines (42 loc) · 1.75 KB
/
Pathtracing.h
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
//
// Created by marc on 13/08/2021.
//
#ifndef RAYTRACING_RAYMARCHING_HYBRID_PATHTRACING_H
#define RAYTRACING_RAYMARCHING_HYBRID_PATHTRACING_H
#include "Types.h"
#include "Raytracing.h"
#include "Raymarching.h"
#include "Raymarching_primitives.h"
namespace pathtracing {
inline vec3 reflect_diffuse(vec3 normal, vec3 vector, scalar roughness, rng_engine* random_engine) {
vec3 rand_vec = random_normal(random_engine);
const vec3 ref_vec = reflect(vector, normal);
//if ((rand_vec^normal) < 0) rand_vec = rand_vec*(-1);
// Apparently uncommenting this line makes it more physically accurate, but looking at the results, I think it looks more
// physically accurate like this (I am lacking the BSDF)
// vvvvvvvvv---- This would also have to be taken out
return lerp(ref_vec, rand_vec + normal, roughness);
}
inline vec3 reflect_metallic(vec3 normal, vec3 vector, scalar roughness, rng_engine* random_engine) {
vec3 rand_vec = random_normal(random_engine);
const vec3 ref_vec = reflect(vector, normal);
const vec3 out_dir = ref_vec + rand_vec*glm::dot(normal, vector)*roughness;
return out_dir;
}
struct Pathtracer {
polygon::Node* polygon_root;
raymarching::Node* raymarching_root;
inline bool combined_ray_intersect(ray r, vec3* poi, scalar* dist, vec3* normal, Material* material) const;
vec3 trace_path(ray r, int max_bounce_count, rng_engine* random_engine);
static inline vec3 get_ambient_color(ray r) {
// If you want stuff like HDRIs, implement them here
return (vec3{0.7411764706, 0.8509803922, 1}*(0.2/1.7303841221));
//return {0.05, 0.05, 0.05};
}
inline void build() const {
polygon_root->build();
raymarching_root->build();
}
};
}
#endif //RAYTRACING_RAYMARCHING_HYBRID_PATHTRACING_H