Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
MathImage.h
Go to the documentation of this file.
1#pragma once
2
3#include "Actor/Image/Image.h"
4#include "SDL/sdl_interface.h"
5
6#include <Common/primitive_type.h>
7
8#include <vector>
9#include <optional>
10
11namespace ph
12{
13
14enum class EMathImageOp
15{
16 Add = 0,
19 Divide,
20 Power,
22 Clamp
23};
24
26{
27 SdlEnumType sdlEnum("math-image-op");
28 sdlEnum.description("The mathematical operation used on images.");
29
30 sdlEnum.addEntry(EnumType::Add, "add");
31 sdlEnum.addEntry(EnumType::Subtract, "sub");
32 sdlEnum.addEntry(EnumType::Multiply, "mul");
33 sdlEnum.addEntry(EnumType::Divide, "div");
34 sdlEnum.addEntry(EnumType::Power, "pow");
35 sdlEnum.addEntry(EnumType::Absolute, "abs");
36 sdlEnum.addEntry(EnumType::Clamp, "clamp");
37
38 return sdlEnum;
39}
40
41class MathImage : public Image
42{
43public:
44 MathImage();
45
46 std::shared_ptr<TTexture<Image::ArrayType>> genNumericTexture(
47 const CookingContext& ctx) override;
48
49 std::shared_ptr<TTexture<math::Spectrum>> genColorTexture(
50 const CookingContext& ctx) override;
51
53 MathImage& setOperandImage(std::shared_ptr<Image> operand);
54 MathImage& setScalarInput0(float64 value);
55 MathImage& setScalarInput1(float64 value);
56 MathImage& setInputImage0(std::shared_ptr<Image> input);
57 MathImage& setInputImage1(std::shared_ptr<Image> input);
58
59private:
60 EMathImageOp m_mathOp;
61 std::shared_ptr<Image> m_operandImage;
62 float64 m_scalarInput0;
63 float64 m_scalarInput1;
64 std::shared_ptr<Image> m_imageInput0;
65 std::shared_ptr<Image> m_imageInput1;
66
67public:
69 {
70 ClassType clazz("math");
71 clazz.docName("Math Image");
72 clazz.description(
73 "This image applies mathematical modifications on other images, such as addition and "
74 "multiplication.");
75 clazz.baseOn<Image>();
76
77 TSdlEnumField<OwnerType, EMathImageOp> mathOp(&OwnerType::m_mathOp);
78 mathOp.description("The mathematical operation used.");
79 mathOp.defaultTo(EMathImageOp::Add);
80 mathOp.required();
81 clazz.addField(mathOp);
82
83 TSdlReference<Image, OwnerType> operandImage("operand", &OwnerType::m_operandImage);
84 operandImage.description("The target image that is going to be operated on.");
85 operandImage.required();
86 clazz.addField(operandImage);
87
88 TSdlReal<OwnerType, float64> scalarInput0("scalar-input-0", &OwnerType::m_scalarInput0);
89 scalarInput0.description(
90 "First scalar input for the specified mathematical operation. This will only be used if "
91 "no image input is provided. Using scalar input is also more efficient than specifying "
92 "the scalar as a constant image input.");
93 scalarInput0.defaultTo(0.0);
94 scalarInput0.optional();
95 clazz.addField(scalarInput0);
96
97 TSdlReal<OwnerType, float64> scalarInput1("scalar-input-1", &OwnerType::m_scalarInput1);
98 scalarInput1.description(
99 "Second scalar input for the specified mathematical operation. This will only be used if "
100 "no image input is provided. Using scalar input is also more efficient than specifying "
101 "the scalar as a constant image input.");
102 scalarInput1.defaultTo(0.0);
103 scalarInput1.optional();
104 clazz.addField(scalarInput1);
105
106 TSdlReference<Image, OwnerType> imageInput0("input-0", &OwnerType::m_imageInput0);
107 imageInput0.description("First input for the specified mathematical operation.");
108 imageInput0.optional();
109 clazz.addField(imageInput0);
110
111 TSdlReference<Image, OwnerType> imageInput1("input-1", &OwnerType::m_imageInput1);
112 imageInput1.description("Second input for the specified mathematical operation.");
113 imageInput1.optional();
114 clazz.addField(imageInput1);
115
116 return clazz;
117 }
118};
119
120}// end namespace ph
Information about the world being cooked.
Definition CookingContext.h:24
Definition Image.h:21
Definition MathImage.h:42
MathImage & setInputImage1(std::shared_ptr< Image > input)
Definition MathImage.cpp:409
MathImage & setScalarInput1(float64 value)
Definition MathImage.cpp:397
MathImage & setScalarInput0(float64 value)
Definition MathImage.cpp:391
MathImage & setOperation(EMathImageOp op)
Definition MathImage.cpp:379
PH_DEFINE_SDL_CLASS(TSdlOwnerClass< MathImage >)
Definition MathImage.h:68
MathImage()
Definition MathImage.cpp:301
MathImage & setOperandImage(std::shared_ptr< Image > operand)
Definition MathImage.cpp:385
std::shared_ptr< TTexture< math::Spectrum > > genColorTexture(const CookingContext &ctx) override
Definition MathImage.cpp:346
std::shared_ptr< TTexture< Image::ArrayType > > genNumericTexture(const CookingContext &ctx) override
Definition MathImage.cpp:313
MathImage & setInputImage0(std::shared_ptr< Image > input)
Definition MathImage.cpp:403
Definition TSdlEnumField.h:23
SDL enum implementation with common features. Enum value and string mapping are done in a brute-force...
Definition TSdlGeneralEnum.h:26
SDL binding type for a canonical SDL resource class.
Definition TSdlOwnerClass.h:23
A field class that binds a floating point member variable.
Definition TSdlReal.h:21
A value that points to a SDL resource.
Definition TSdlReference.h:21
TSdlReference & optional()
Definition TSdlReference.ipp:214
TSdlReference & required()
Definition TSdlReference.ipp:228
TSdlReference & description(std::string descriptionStr)
Definition TSdlReference.ipp:206
TSdlValue & description(std::string descriptionStr)
Definition TSdlValue.ipp:95
TSdlValue & optional()
Definition TSdlValue.ipp:103
TSdlValue & defaultTo(T defaultValue)
Definition TSdlValue.ipp:71
The root for all renderer implementations.
Definition EEngineProject.h:6
EMathImageOp
Definition MathImage.h:15
#define PH_DEFINE_SDL_ENUM(...)
Define a SDL enum with function-like syntax.
Definition sdl_interface.h:142