Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
black_body.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/constant.h"
4#include "Math/math.h"
5
6#include <Common/assertion.h>
7
8#include <cmath>
9#include <cstddef>
10#include <vector>
11#include <utility>
12
13namespace ph::math
14{
15
23template<typename T>
24inline T black_body_spectral_radiance_at(const T temperatureK, const T wavelengthNM)
25{
26 PH_ASSERT_GE(temperatureK, 0);
27 PH_ASSERT_GT(wavelengthNM, 0);
28
29 if(temperatureK == 0)
30 {
31 return 0;
32 }
33
34 // Using double for calculation as the values can extend a wide range
35
36 using namespace constant;
37
38 const double nume = 2.0 * h_Planck<double> * c_light<double> * c_light<double>;
39
40 const double lambda = wavelengthNM * 1e-9;// convert nm to m
41 const double lambda5 = (lambda * lambda) * (lambda * lambda) * lambda;
42 const double exp = (h_Planck<double> * c_light<double>) / (lambda * k_Boltzmann<double> * temperatureK);
43 const double deno = lambda5 * (std::exp(exp) - 1.0);
44
45 return static_cast<T>(nume / deno);
46}
47
57template<typename T>
59 const T temperatureK,
60 const T lambdaMinNM,
61 const T lambdaMaxNM,
62 const std::size_t numCurvePoints,
63 std::vector<T>* const out_lambdaValues = nullptr)
64{
65 PH_ASSERT_GE(numCurvePoints, 2);
66 PH_ASSERT_GT(lambdaMaxNM, lambdaMinNM);
67
68 auto lambdaValues = evenly_spaced_vector<T>(lambdaMinNM, lambdaMaxNM, numCurvePoints);
69
70 std::vector<T> radianceCurve(numCurvePoints, 0);
71 for(std::size_t i = 0; i < numCurvePoints; ++i)
72 {
73 radianceCurve[i] = black_body_spectral_radiance_at(temperatureK, lambdaValues[i]);
74 }
75
76 if(out_lambdaValues)
77 {
78 *out_lambdaValues = std::move(lambdaValues);
79 }
80
81 return radianceCurve;
82}
83
84}// end namespace ph::math
Miscellaneous math utilities.
Math functions and utilities.
Definition TransformInfo.h:10
std::vector< T > black_body_spectral_radiance_curve(const T temperatureK, const T lambdaMinNM, const T lambdaMaxNM, const std::size_t numCurvePoints, std::vector< T > *const out_lambdaValues=nullptr)
Get a curve for Black-body radiation. Note that this function is not returning radiance but spectral ...
Definition black_body.h:58
std::vector< T > evenly_spaced_vector(const T min, const T max, const std::size_t n)
Definition math.h:570
T black_body_spectral_radiance_at(const T temperatureK, const T wavelengthNM)
Get Black-body spectral radiance at specific temperature and wavelength. Note that this function is n...
Definition black_body.h:24