ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
CombineMaterial.h
Go to the documentation of this file.
1/**
2 * @file CombineMaterial.h
3 * @brief Combines multiple materials with different blending methods and opacities.
4 *
5 * This class allows combining materials for complex visual effects.
6 *
7 * @date 22/12/2024
8 * @version 1.0
9 * @author Coela Can't
10 */
11
12#pragma once
13
14#include "Material.h"
15#include "../../Utils/Math/Vector2D.h"
16#include "../../Utils/Math/Vector3D.h"
17
18/**
19 * @class CombineMaterial
20 * @brief Combines multiple materials with specified blending methods and opacities.
21 *
22 * The `CombineMaterial` class allows for the creation of composite materials by blending
23 * multiple materials using different methods and opacities. Each material can have a unique
24 * blending method and opacity level.
25 *
26 * @tparam materialCount Maximum number of materials to combine.
27 */
28template<size_t materialCount>
29class CombineMaterial : public Material {
30private:
31 Method method[materialCount]; ///< Array of blending methods for each material.
32 Material* materials[materialCount]; ///< Array of pointers to materials.
33 float opacity[materialCount]; ///< Array of opacities for each material.
34 uint8_t materialsAdded = 0; ///< Counter for added materials.
35
36public:
37 /**
38 * @brief Constructs an empty `CombineMaterial` instance.
39 */
41
42 /**
43 * @brief Adds a new material to the combination.
44 *
45 * @param method The blending method to use for the material.
46 * @param material A pointer to the material to add.
47 * @param opacity The opacity level of the material (0.0 to 1.0).
48 */
49 void AddMaterial(Method method, Material* material, float opacity);
50
51 /**
52 * @brief Sets the blending method for a specific material.
53 *
54 * @param index The index of the material.
55 * @param method The new blending method.
56 */
57 void SetMethod(uint8_t index, Method method);
58
59 /**
60 * @brief Sets the opacity for a specific material.
61 *
62 * @param index The index of the material.
63 * @param opacity The new opacity value (0.0 to 1.0).
64 */
65 void SetOpacity(uint8_t index, float opacity);
66
67 /**
68 * @brief Replaces a material at a specific index.
69 *
70 * @param index The index of the material to replace.
71 * @param material A pointer to the new material.
72 */
73 void SetMaterial(uint8_t index, Material* material);
74
75 /**
76 * @brief Calculates the resulting color by combining all materials.
77 *
78 * @param position The position in 3D space.
79 * @param normal The normal vector at the position.
80 * @param uvw The UVW coordinates for texture mapping.
81 * @return The resulting combined `RGBColor`.
82 */
83 RGBColor GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) override;
84};
85
86#include "CombineMaterial.tpp"
Base class for materials defining shading and rendering behavior.
Combines multiple materials with specified blending methods and opacities.
void SetMaterial(uint8_t index, Material *material)
Replaces a material at a specific index.
float opacity[materialCount]
Array of opacities for each material.
void SetOpacity(uint8_t index, float opacity)
Sets the opacity for a specific material.
uint8_t materialsAdded
Counter for added materials.
void SetMethod(uint8_t index, Method method)
Sets the blending method for a specific material.
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Calculates the resulting color by combining all materials.
Method method[materialCount]
Array of blending methods for each material.
void AddMaterial(Method method, Material *material, float opacity)
Adds a new material to the combination.
Material * materials[materialCount]
Array of pointers to materials.
CombineMaterial()
Constructs an empty CombineMaterial instance.
Abstract base class for rendering materials.
Definition Material.h:27
Method
Defines blending methods for combining colors.
Definition Material.h:33
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26