ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
GradientMaterial.h
Go to the documentation of this file.
1/**
2 * @file GradientMaterial.h
3 * @brief Defines a material for creating gradient color effects in 3D rendering.
4 *
5 * The `GradientMaterial` class allows for the creation of gradients with customizable
6 * colors, radial effects, steps, and transformations like rotation and position offsets.
7 *
8 * @tparam colorCount Number of colors in the gradient.
9 * @date 22/12/2024
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../Material.h" // Base class for materials.
16#include "../../../Utils/Math/Mathematics.h" // Mathematical utilities.
17#include "../../../Utils/Math/Rotation.h" // Rotation utilities.
18#include "../../../Utils/Math/Vector2D.h" // 2D vector operations.
19
20/**
21 * @class GradientMaterial
22 * @brief Creates a customizable gradient material for rendering.
23 *
24 * The `GradientMaterial` class supports linear and radial gradients, with options for
25 * stepping, position and rotation offsets, and period adjustments.
26 *
27 * @tparam colorCount Number of colors in the gradient.
28 */
29template<size_t colorCount>
30class GradientMaterial : public Material {
31private:
32 RGBColor rgbColors[colorCount]; ///< Array of colors used in the gradient.
33 RGBColor* baseRGBColors; ///< Pointer to the base RGB colors.
34 Vector2D positionOffset; ///< Offset for the gradient's position.
35 Vector2D rotationOffset; ///< Point about which the gradient rotates.
36 float gradientPeriod = 1.0f; ///< Period of the gradient repetition.
37 float rotationAngle = 0.0f; ///< Angle for rotating the gradient.
38 bool isRadial = false; ///< Whether the gradient is radial.
39 bool isStepped = false; ///< Whether the gradient is stepped.
40 float gradientShift = 0.0f; ///< Shift in the gradient pattern.
41
42public:
43 /**
44 * @brief Constructs a `GradientMaterial` instance.
45 *
46 * @param rgbColors Array of colors for the gradient.
47 * @param gradientPeriod Period of the gradient repetition.
48 * @param isRadial Whether the gradient is radial.
49 * @param isStepped Whether the gradient is stepped.
50 */
52
53 /**
54 * @brief Updates the colors of the gradient.
55 *
56 * @param rgbColors New array of colors for the gradient.
57 */
59
60 /**
61 * @brief Sets the position offset for the gradient.
62 *
63 * @param positionOffset The new position offset.
64 */
66
67 /**
68 * @brief Sets the rotation offset for the gradient.
69 *
70 * @param rotationOffset The new rotation offset point.
71 */
73
74 /**
75 * @brief Sets the rotation angle for the gradient.
76 *
77 * @param rotationAngle The new rotation angle in degrees.
78 */
80
81 /**
82 * @brief Sets the gradient's period of repetition.
83 *
84 * @param gradientPeriod The new gradient period.
85 */
87
88 /**
89 * @brief Shifts the gradient by a ratio.
90 *
91 * @param ratio The ratio by which to shift the gradient.
92 */
93 void GradientShift(float ratio);
94
95 /**
96 * @brief Shifts the hue of the gradient by a specified degree.
97 *
98 * @param hueDeg Degrees by which to shift the gradient's hue.
99 */
100 void HueShift(float hueDeg);
101
102 /**
103 * @brief Updates the RGB colors in the gradient.
104 */
105 void UpdateRGB();
106
107 /**
108 * @brief Gets the RGB color for a given position in the gradient.
109 *
110 * @param position 3D position in the gradient.
111 * @param normal Normal vector at the position.
112 * @param uvw Texture coordinates at the position.
113 * @return The calculated RGB color.
114 */
115 RGBColor GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) override;
116};
117
118#include "GradientMaterial.tpp" // Include the template implementation.
Creates a customizable gradient material for rendering.
RGBColor rgbColors[colorCount]
Array of colors used in the gradient.
GradientMaterial(RGBColor *rgbColors, float gradientPeriod, bool isRadial, bool isStepped=false)
Constructs a GradientMaterial instance.
bool isRadial
Whether the gradient is radial.
void SetPositionOffset(Vector2D positionOffset)
Sets the position offset for the gradient.
void SetRotationAngle(float rotationAngle)
Sets the rotation angle for the gradient.
Vector2D positionOffset
Offset for the gradient's position.
bool isStepped
Whether the gradient is stepped.
void UpdateGradient(RGBColor *rgbColors)
Updates the colors of the gradient.
void HueShift(float hueDeg)
Shifts the hue of the gradient by a specified degree.
void GradientShift(float ratio)
Shifts the gradient by a ratio.
float rotationAngle
Angle for rotating the gradient.
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Gets the RGB color for a given position in the gradient.
void SetRotationOffset(Vector2D rotationOffset)
Sets the rotation offset for the gradient.
RGBColor * baseRGBColors
Pointer to the base RGB colors.
float gradientPeriod
Period of the gradient repetition.
void UpdateRGB()
Updates the RGB colors in the gradient.
Vector2D rotationOffset
Point about which the gradient rotates.
float gradientShift
Shift in the gradient pattern.
void SetGradientPeriod(float gradientPeriod)
Sets the gradient's period of repetition.
Abstract base class for rendering materials.
Definition Material.h:27
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26