-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhaseFunction.hpp
More file actions
26 lines (23 loc) · 887 Bytes
/
PhaseFunction.hpp
File metadata and controls
26 lines (23 loc) · 887 Bytes
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
#pragma once
#include "Interaction.hpp"
#include <numbers>
template <std::floating_point T>
inline T phaseHG(T cosTheta, T g){
T denom = 1 + g * g + 2 * g * cosTheta;
return static_cast<T>(0.25) * std::numbers::inv_pi_v<T> *(static_cast<T>(1) - g * g) / (denom * std::sqrt(denom));
}
class PhaseFunction{
public:
virtual ~PhaseFunction() = default;
virtual float PDF(const glm::vec3& in, const glm::vec3& out) const = 0;
virtual float Sample(const glm::vec3& in, glm::vec3& out, const glm::vec2& u) const = 0;
};
class HenyeyGreenstein : public PhaseFunction{
public:
virtual ~HenyeyGreenstein() = default;
HenyeyGreenstein(float G) : g(glm::clamp(G, -0.99f, 0.99f)){}
float PDF(const glm::vec3& in, const glm::vec3& out) const override;
float Sample(const glm::vec3& in, glm::vec3& out, const glm::vec2& u) const override;
private:
float g;
};