Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ternary_texture_operators.h
Go to the documentation of this file.
1#pragma once
2
5#include "Utility/traits.h"
6#include "Math/math.h"
9
10#include <Common/assertion.h>
11
12#include <type_traits>
13#include <memory>
14#include <utility>
15#include <concepts>
16#include <cmath>
17
18namespace ph
19{
20
21namespace texfunc
22{
23
24template<typename OperatorType, typename InputTypeA, typename InputTypeB, typename InputTypeC, typename OutputType>
25concept CTernaryOperator = requires (OperatorType op, InputTypeA inputA, InputTypeB inputB, InputTypeC inputC)
26{
27 { op(inputA, inputB, inputC) } -> std::same_as<OutputType>;
28};
29
30template<typename InputTypeA, typename InputTypeB, typename InputTypeC, typename OutputType>
31class TClamp final
32{
33public:
34 OutputType operator () (
35 const InputTypeA& inputValueA,
36 const InputTypeB& inputValueB,
37 const InputTypeC& inputValueC) const
38 {
39 constexpr bool canCallClampMethod = requires (InputTypeA a, InputTypeB b, InputTypeC c)
40 {
41 { a.clamp(b, c) } -> std::convertible_to<OutputType>;
42 };
43
44 constexpr bool canCallMathClamp = requires (InputTypeA a, InputTypeB b, InputTypeC c)
45 {
46 { math::clamp(a, b, c) } -> std::convertible_to<OutputType>;
47 };
48
49 if constexpr(canCallClampMethod)
50 {
51 return inputValueA.clamp(inputValueB, inputValueC);
52 }
53 else if constexpr(canCallMathClamp)
54 {
55 return math::clamp(inputValueA, inputValueB, inputValueC);
56 }
57 else
58 {
59 PH_STATIC_ASSERT_DEPENDENT_FALSE(OutputType,
60 "Cannot perform clamp operation for the specified types.");
61 }
62 }
63};
64
66
67}// end namespace texfunc
68
69template
70<
71 typename InputTypeA,
72 typename InputTypeB,
73 typename InputTypeC,
74 typename OutputType,
76>
77class TTernaryTextureOperator : public TTexture<OutputType>
78{
79public:
80 using InputTexResA = std::shared_ptr<TTexture<InputTypeA>>;
81 using InputTexResB = std::shared_ptr<TTexture<InputTypeB>>;
82 using InputTexResC = std::shared_ptr<TTexture<InputTypeC>>;
83
85 InputTexResA inputA,
86 InputTexResB inputB,
87 InputTexResC inputC) requires std::default_initializable<OperatorType>
88
90 std::move(inputA),
91 std::move(inputB),
92 std::move(inputC),
93 OperatorType{})
94 {}
95
97 InputTexResA inputA,
98 InputTexResB inputB,
99 InputTexResC inputC,
100 OperatorType op)
101
102 : m_inputA (std::move(inputA))
103 , m_inputB (std::move(inputB))
104 , m_inputC (std::move(inputC))
105 , m_operator(std::move(op))
106 {}
107
108 void sample(const SampleLocation& sampleLocation, OutputType* const out_value) const override
109 {
110 PH_ASSERT(m_inputA);
111 PH_ASSERT(m_inputB);
112 PH_ASSERT(m_inputC);
113 PH_ASSERT(out_value);
114
115 InputTypeA inputValueA;
116 m_inputA->sample(sampleLocation, &inputValueA);
117
118 InputTypeB inputValueB;
119 m_inputB->sample(sampleLocation, &inputValueB);
120
121 InputTypeC inputValueC;
122 m_inputC->sample(sampleLocation, &inputValueC);
123
124 *out_value = m_operator(inputValueA, inputValueB, inputValueC);
125 }
126
127private:
128 InputTexResA m_inputA;
129 InputTexResB m_inputB;
130 InputTexResC m_inputC;
131 OperatorType m_operator;
132};
133
134}// end namespace ph
Definition SampleLocation.h:22
Definition ternary_texture_operators.h:78
TTernaryTextureOperator(InputTexResA inputA, InputTexResB inputB, InputTexResC inputC, OperatorType op)
Definition ternary_texture_operators.h:96
std::shared_ptr< TTexture< InputTypeC > > InputTexResC
Definition ternary_texture_operators.h:82
TTernaryTextureOperator(InputTexResA inputA, InputTexResB inputB, InputTexResC inputC)
Definition ternary_texture_operators.h:84
void sample(const SampleLocation &sampleLocation, OutputType *const out_value) const override
Definition ternary_texture_operators.h:108
std::shared_ptr< TTexture< InputTypeB > > InputTexResB
Definition ternary_texture_operators.h:81
std::shared_ptr< TTexture< InputTypeA > > InputTexResA
Definition ternary_texture_operators.h:80
Definition TTexture.h:12
Definition ternary_texture_operators.h:32
OutputType operator()(const InputTypeA &inputValueA, const InputTypeB &inputValueB, const InputTypeC &inputValueC) const
Definition ternary_texture_operators.h:34
Definition ternary_texture_operators.h:25
Miscellaneous math utilities.
T clamp(const T value, const T lowerBound, const T upperBound)
Clamps a value to [lowerBound, upperBound]. None of value, lowerBound and upperBound can be NaN,...
Definition math.h:77
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96