ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
RadialBlur.cpp
Go to the documentation of this file.
1#include "RadialBlur.h"
2#include "../../Utils/Math/Mathematics.h"
3
4RadialBlur::RadialBlur(uint8_t pixels) : pixels(pixels) {}
5
7 uint16_t pixelCount = pixelGroup->GetPixelCount();
8 RGBColor* pixelColors = pixelGroup->GetColors();
9 RGBColor* colorBuffer = pixelGroup->GetColorBuffer();
10
11 float rotation = fGenRotation.Update();
12
13 for (uint16_t i = 0; i < pixelCount; i++) {
14 uint16_t indexV = i, indexD = i;
15 uint16_t tIndexV = 0, tIndexD = 0;
16 bool validV = true, validD = true;
17
18 uint16_t blurRange = uint16_t(Mathematics::Map(ratio, 0.0f, 1.0f, 1.0f, float(pixels)));
19
20 uint16_t R, G, B;
21
22 R = (uint16_t)pixelColors[i].R;
23 G = (uint16_t)pixelColors[i].G;
24 B = (uint16_t)pixelColors[i].B;
25
26 for (uint8_t j = 1; j < blurRange + 1; j++) {
27 validV = pixelGroup->GetRadialIndex(i, &tIndexV, j, rotation);
28 validD = pixelGroup->GetRadialIndex(i, &tIndexD, j, rotation + 180.0f);
29
30 indexV = tIndexV;
31 indexD = tIndexD;
32
33 if (validV) {
34 R = R + (uint16_t)pixelColors[indexV].R;
35 G = G + (uint16_t)pixelColors[indexV].G;
36 B = B + (uint16_t)pixelColors[indexV].B;
37 }
38
39 if (validD) {
40 R = R + (uint16_t)pixelColors[indexD].R;
41 G = G + (uint16_t)pixelColors[indexD].G;
42 B = B + (uint16_t)pixelColors[indexD].B;
43 }
44 }
45
46 colorBuffer[i].R = Mathematics::Constrain(R / (blurRange * 2), 0, 255);
47 colorBuffer[i].B = Mathematics::Constrain(G / (blurRange * 2), 0, 255);
48 colorBuffer[i].G = Mathematics::Constrain(B / (blurRange * 2), 0, 255);
49 }
50
51 for (uint16_t i = 0; i < pixelCount; i++) {
52 pixelColors[i].R = colorBuffer[i].R;
53 pixelColors[i].G = colorBuffer[i].G;
54 pixelColors[i].B = colorBuffer[i].B;
55 }
56}
Defines the RadialBlur effect class for applying a radial blur to pixel groups.
float ratio
A scaling ratio used for dynamic effect adjustments.
Definition Effect.h:28
float Update()
Updates and calculates the next value of the waveform.
Interface for managing and interacting with a collection of pixels.
Definition IPixelGroup.h:25
virtual RGBColor * GetColors()=0
Retrieves the array of colors for the pixel group.
virtual RGBColor * GetColorBuffer()=0
Retrieves the color buffer for the pixel group.
virtual uint16_t GetPixelCount()=0
Retrieves the total number of pixels in the group.
virtual bool GetRadialIndex(uint16_t count, uint16_t *index, int pixels, float angle)=0
Retrieves a radial index for a given pixel based on distance and angle.
static T Map(T value, T inLow, T inMax, T outMin, T outMax)
Maps a value from one range to another.
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
uint8_t B
Blue component of the color (0-255).
Definition RGBColor.h:27
uint8_t G
Green component of the color (0-255).
Definition RGBColor.h:26
uint8_t R
Red component of the color (0-255).
Definition RGBColor.h:25
void ApplyEffect(IPixelGroup *pixelGroup) override
Applies the radial blur effect to the given pixel group.
Definition RadialBlur.cpp:6
FunctionGenerator fGenRotation
Function generator for controlling the rotational motion of the blur.
Definition RadialBlur.h:31
RadialBlur(uint8_t pixels)
Constructs a RadialBlur effect instance.
Definition RadialBlur.cpp:4
const uint8_t pixels
Number of pixels to apply the effect to.
Definition RadialBlur.h:28