Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TableTIR.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <Common/assertion.h>
7#include <Common/primitive_type.h>
8#include <Common/logging.h>
9
10#include <vector>
11
12namespace ph
13{
14
16
17class TableTIR final
18{
19public:
20 explicit TableTIR(const Path& tableFilePath);
21
22 real sample(real cosWi, real alpha, real relIor) const;
23
24private:
25 std::vector<float> m_table;
26
27 int m_numCosWi;
28 int m_numAlpha;
29 int m_numRelIor;
30
31 float m_minCosWi, m_maxCosWi;
32 float m_minAlpha, m_maxAlpha;
33 float m_minRelIor, m_maxRelIor;
34
35 int calcIndex(int iCosWi, int iAlpha, int iRelIor) const;
36};
37
38// In-header Implementations:
39
40inline TableTIR::TableTIR(const Path& tableFilePath) :
41 m_table(),
42
43 m_numCosWi (0),
44 m_numAlpha (0),
45 m_numRelIor(0),
46
47 m_minCosWi (0.0f), m_maxCosWi (0.0f),
48 m_minAlpha (0.0f), m_maxAlpha (0.0f),
49 m_minRelIor(0.0f), m_maxRelIor(0.0f)
50{
51 PH_LOG(TableTIR, Note, "loading <{}>", tableFilePath.toString());
52
53 BinaryFileReader reader(tableFilePath);
54 if(!reader.open())
55 {
56 return;
57 }
58
59 reader.read(&m_numCosWi);
60 reader.read(&m_numAlpha);
61 reader.read(&m_numRelIor);
62 reader.read(&m_minCosWi); reader.read(&m_maxCosWi);
63 reader.read(&m_minAlpha); reader.read(&m_maxAlpha);
64 reader.read(&m_minRelIor); reader.read(&m_maxRelIor);
65
66 PH_DEBUG_LOG(TableTIR, "dimension: (cos-w_i = {}, alpha = {}, relative-IOR = {})",
67 m_numCosWi, m_numAlpha, m_numRelIor);
68
69 PH_DEBUG_LOG(TableTIR, "range: (cos-w_i = [{}, {}], alpha = [{}, {}], relative-IOR = [{}, {}])",
70 m_minCosWi, m_maxCosWi,
71 m_minAlpha, m_maxAlpha,
72 m_minRelIor, m_maxRelIor);
73
74 PH_ASSERT(m_numCosWi > 0 && m_numAlpha > 0 && m_numRelIor > 0);
75
76 const std::size_t tableSize =
77 static_cast<std::size_t>(m_numCosWi) *
78 static_cast<std::size_t>(m_numAlpha) *
79 static_cast<std::size_t>(m_numRelIor);
80 m_table.resize(tableSize, 0.0f);
81 reader.read(m_table.data(), m_table.size());
82}
83
84inline int TableTIR::calcIndex(const int iCosWi, const int iAlpha, const int iRelIor) const
85{
86 // make sure the indices stay in the limits
87 PH_ASSERT(0 <= iCosWi && iCosWi < m_numCosWi);
88 PH_ASSERT(0 <= iAlpha && iAlpha < m_numAlpha);
89 PH_ASSERT(0 <= iRelIor && iRelIor < m_numRelIor);
90
91 return iRelIor + m_numRelIor * (iAlpha + m_numAlpha * iCosWi);
92}
93
94}// end namespace ph
Definition BinaryFileReader.h:14
void read(T *out_buffer, std::size_t numElements=1)
Definition BinaryFileReader.h:48
bool open()
Definition BinaryFileReader.cpp:10
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
std::string toString() const
Get a string representation of this path in generic format.
Definition Path.cpp:121
Definition TableTIR.h:18
real sample(real cosWi, real alpha, real relIor) const
Definition TableTIR.cpp:23
TableTIR(const Path &tableFilePath)
Definition TableTIR.h:40
The root for all renderer implementations.
Definition EEngineProject.h:6
PH_DEFINE_EXTERNAL_LOG_GROUP(ApiDatabase, Core)