ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MaterialMask.h
Go to the documentation of this file.
1/**
2 * @file MaterialMask.h
3 * @brief Defines the `MaterialMask` class, which blends materials with a mask defined by a shape.
4 *
5 * The `MaterialMask` class allows rendering of one material within a defined shape
6 * and another material outside of it, with support for adjustable opacity.
7 *
8 * @date 22/12/2024
9 * @version 1.0
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../Material.h"
16#include "../../../Renderer/Primitives/2D/Shape.h"
17
18/**
19 * @class MaterialMask
20 * @brief Combines two materials using a shape as a mask.
21 *
22 * The `MaterialMask` class provides functionality to blend two materials—one within
23 * a defined shape and another for the outer region. Opacity can be adjusted for
24 * blending effects.
25 */
26class MaterialMask : public Material {
27private:
28 Material* materialShape; ///< The material rendered inside the mask shape.
29 Material* materialOuter; ///< The material rendered outside the mask shape.
30 Shape* shape; ///< Defines the masked area for blending the materials.
31 float opacity = 1.0f; ///< Controls the opacity of the mask effect.
32
33public:
34 /**
35 * @brief Constructs a `MaterialMask` with given materials and shape.
36 *
37 * @param materialShape Pointer to the material rendered within the shape.
38 * @param materialOuter Pointer to the material rendered outside the shape.
39 * @param shape Pointer to the shape used as the mask.
40 */
42
43 /**
44 * @brief Sets the opacity of the mask effect.
45 *
46 * @param opacity The opacity value (0.0 to 1.0).
47 */
48 void SetOpacity(float opacity);
49
50 /**
51 * @brief Provides a reference to the opacity value.
52 *
53 * Useful for dynamically modifying opacity during runtime.
54 *
55 * @return Pointer to the opacity value.
56 */
57 float* GetOpacityReference();
58
59 /**
60 * @brief Retrieves the color at a specific position based on the mask.
61 *
62 * Determines if the position lies within the mask shape and blends the
63 * materials accordingly.
64 *
65 * @param position The 3D position to sample the color.
66 * @param normal The normal vector at the position.
67 * @param uvw UVW coordinates at the position.
68 * @return The blended RGB color based on the mask and materials.
69 */
70 RGBColor GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) override;
71};
Combines two materials using a shape as a mask.
Material * materialOuter
The material rendered outside the mask shape.
Shape * shape
Defines the masked area for blending the materials.
void SetOpacity(float opacity)
Sets the opacity of the mask effect.
float opacity
Controls the opacity of the mask effect.
Material * materialShape
The material rendered inside the mask shape.
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Retrieves the color at a specific position based on the mask.
float * GetOpacityReference()
Provides a reference to the opacity value.
Abstract base class for rendering materials.
Definition Material.h:27
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
Abstract base class for 2D geometric shapes.
Definition Shape.h:22
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26