ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MaterialMask.cpp
Go to the documentation of this file.
1#include "MaterialMask.h"
2
3MaterialMask::MaterialMask(Material* materialShape, Material* materialOuter, Shape* shape) {
4 this->materialShape = materialShape;
5 this->materialOuter = materialOuter;
6 this->shape = shape;
7}
8
9void MaterialMask::SetOpacity(float opacity) {
10 this->opacity = opacity;
11}
12
14 return &opacity;
15}
16
17RGBColor MaterialMask::GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) {
18 bool isInShape = shape->IsInShape(Vector2D(position.X, position.Y));
19
20 if (opacity > 0.97f && isInShape) {
21 return materialShape->GetRGB(position, normal, uvw);
22 }
23 else if (isInShape) {
24 RGBColor shapeColor = materialShape->GetRGB(position, normal, uvw);
25 RGBColor outerColor = materialOuter->GetRGB(position, normal, uvw);
26
27 return RGBColor::InterpolateColors(outerColor, shapeColor, Mathematics::Constrain(opacity, 0.0f, 1.0f));
28 }
29 else {
30 return materialOuter->GetRGB(position, normal, uvw);
31 }
32}
Defines the MaterialMask class, which blends materials with a mask defined by a shape.
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.
MaterialMask(Material *materialShape, Material *materialOuter, Shape *shape)
Constructs a MaterialMask with given materials and shape.
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
virtual RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw)=0
Pure virtual function to calculate color based on surface parameters.
static T Constrain(T value, T minimum, T maximum)
Constrains a value between minimum and maximum.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
static RGBColor InterpolateColors(const RGBColor &a, const RGBColor &b, const float &ratio)
Interpolates between two colors based on a ratio.
Definition RGBColor.cpp:79
Abstract base class for 2D geometric shapes.
Definition Shape.h:22
virtual bool IsInShape(Vector2D point)=0
Checks if a given point lies within the shape's boundaries.
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
float X
The X-component of the 3D vector.
Definition Vector3D.h:28
float Y
The Y-component of the 3D vector.
Definition Vector3D.h:29