Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ConstantImage.h
Go to the documentation of this file.
1#pragma once
2
3#include "Actor/Image/Image.h"
4#include "Math/math_fwd.h"
6#include "SDL/sdl_interface.h"
7
8#include <vector>
9#include <utility>
10#include <type_traits>
11
12namespace ph
13{
14
15class ConstantImage : public Image
16{
17public:
18 std::shared_ptr<TTexture<Image::ArrayType>> genNumericTexture(
19 const CookingContext& ctx) override;
20
21 std::shared_ptr<TTexture<math::Spectrum>> genColorTexture(
22 const CookingContext& ctx) override;
23
24 template<typename T>
25 void setRaw(T value);
26
27 template<typename T>
28 void setRaw(const math::TVector3<T>& values);
29
30 template<typename T>
31 void setRaw(std::vector<T> values);
32
35 template<typename T>
36 void setColor(T color, math::EColorSpace colorSpace);
37
40 template<typename T>
41 void setColor(const math::TVector3<T>& color, math::EColorSpace colorSpace);
42
43 template<typename T>
44 void setValues(std::vector<T> values, math::EColorSpace colorSpace);
45
46private:
47 std::vector<float64> m_values;
48 math::EColorSpace m_colorSpace;
49
50public:
52 {
53 ClassType clazz("constant");
54 clazz.docName("Constant Image");
55 clazz.description(
56 "An image that stores constant values. It can be a single scalar, a vector or a color. "
57 "By default, all values are treated as raw data (bypass any color space conversion).");
58 clazz.baseOn<Image>();
59
60 TSdlRealArray<OwnerType, float64> values("values", &OwnerType::m_values);
61 values.description("A series of values to initialize the constant.");
62 values.required();
63 clazz.addField(values);
64
65 TSdlEnumField<OwnerType, math::EColorSpace> colorSpace(&OwnerType::m_colorSpace);
66 colorSpace.description(
67 "Associated color space of the constant. By default, values are raw data. If a color "
68 "space is specified, then values will be treated as if in the specified color space. "
69 "When the engine is in spectral mode, raw data may be treated as linear sRGB if a "
70 "direct conversion is impossible.");
72 colorSpace.optional();
73 clazz.addField(colorSpace);
74
75 return clazz;
76 }
77};
78
79// In-ueader Implementations:
80
81template<typename T>
82inline void ConstantImage::setRaw(T value)
83{
84 setRaw(std::vector<T>{value});
85}
86
87template<typename T>
88inline void ConstantImage::setRaw(const math::TVector3<T>& values)
89{
90 setRaw(std::vector<T>{values.x(), values.y(), values.z()});
91}
92
93template<typename T>
94inline void ConstantImage::setRaw(std::vector<T> values)
95{
96 setValues(std::move(values), math::EColorSpace::Unspecified);
97}
98
99template<typename T>
100inline void ConstantImage::setColor(T color, math::EColorSpace colorSpace)
101{
102 setValues(std::vector<T>{color}, colorSpace);
103}
104
105template<typename T>
107{
108 setValues(std::vector<T>{color.x(), color.y(), color.z()}, colorSpace);
109}
110
111template<typename T>
112inline void ConstantImage::setValues(std::vector<T> values, math::EColorSpace colorSpace)
113{
114 if constexpr(std::is_same_v<T, float64>)
115 {
116 m_values = std::move(values);
117 }
118 else
119 {
120 m_values.resize(values.size());
121 for(std::size_t i = 0; i < values.size(); ++i)
122 {
123 m_values[i] = static_cast<float64>(values[i]);
124 }
125 }
126
127 m_colorSpace = colorSpace;
128}
129
130}// end namespace ph
Definition ConstantImage.h:16
void setValues(std::vector< T > values, math::EColorSpace colorSpace)
Definition ConstantImage.h:112
std::shared_ptr< TTexture< math::Spectrum > > genColorTexture(const CookingContext &ctx) override
Definition ConstantImage.cpp:43
PH_DEFINE_SDL_CLASS(TSdlOwnerClass< ConstantImage >)
Definition ConstantImage.h:51
std::shared_ptr< TTexture< Image::ArrayType > > genNumericTexture(const CookingContext &ctx) override
Definition ConstantImage.cpp:17
void setRaw(T value)
Definition ConstantImage.h:82
void setColor(T color, math::EColorSpace colorSpace)
Set as a monochromatic color value.
Definition ConstantImage.h:100
Information about the world being cooked.
Definition CookingContext.h:24
Definition Image.h:21
Definition TSdlEnumField.h:23
SDL binding type for a canonical SDL resource class.
Definition TSdlOwnerClass.h:23
Definition TSdlRealArray.h:23
TSdlValue & description(std::string descriptionStr)
Definition TSdlValue.ipp:95
TSdlValue & optional()
Definition TSdlValue.ipp:103
TSdlValue & defaultTo(T defaultValue)
Definition TSdlValue.ipp:71
Represents a 3-D vector.
Definition TVector3.h:17
T & y()
Definition TVector3.ipp:189
T & z()
Definition TVector3.ipp:195
T & x()
Definition TVector3.ipp:183
EColorSpace
Definition color_enums.h:7
The root for all renderer implementations.
Definition EEngineProject.h:6