Blender V4.3
COM_GlareStreaksOperation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6#include "BLI_math_rotation.h"
7
8namespace blender::compositor {
9
11 MemoryBuffer *input_tile,
12 const NodeGlare *settings)
13{
14 int x, y, n;
15 // uint nump = 0; /* UNUSED. */
16 float c1[4], c2[4], c3[4], c4[4];
17 float a, ang = DEG2RADF(360.0f) / float(settings->streaks);
18
19 int size = input_tile->get_width() * input_tile->get_height();
20 int size4 = size * 4;
21
22 bool breaked = false;
23
24 MemoryBuffer tsrc(*input_tile);
25 MemoryBuffer tdst(DataType::Color, input_tile->get_rect());
26 tdst.clear();
27 memset(data, 0, size4 * sizeof(float));
28
29 for (a = 0.0f; a < DEG2RADF(360.0f) && (!breaked); a += ang) {
30 const float an = a + settings->angle_ofs;
31 const float vx = cos(double(an)), vy = sin(double(an));
32 for (n = 0; n < settings->iter && (!breaked); n++) {
33 const float p4 = pow(4.0, double(n));
34 const float vxp = vx * p4, vyp = vy * p4;
35 const float wt = pow(double(settings->fade), double(p4));
36
37 /* Color-modulation amount relative to current pass. */
38 const float cmo = 1.0f - float(pow(double(settings->colmod), double(n) + 1));
39
40 float *tdstcol = tdst.get_buffer();
41 for (y = 0; y < tsrc.get_height() && (!breaked); y++) {
42 for (x = 0; x < tsrc.get_width(); x++, tdstcol += 4) {
43 /* First pass no offset, always same for every pass, exact copy,
44 * otherwise results in uneven brightness, only need once. */
45 if (n == 0) {
46 tsrc.read(c1, x, y);
47 }
48 else {
49 c1[0] = c1[1] = c1[2] = 0;
50 }
51 tsrc.read_bilinear(c2, x + vxp, y + vyp);
52 tsrc.read_bilinear(c3, x + vxp * 2.0f, y + vyp * 2.0f);
53 tsrc.read_bilinear(c4, x + vxp * 3.0f, y + vyp * 3.0f);
54 /* Modulate color to look vaguely similar to a color spectrum. */
55 c2[1] *= cmo;
56 c2[2] *= cmo;
57
58 c3[0] *= cmo;
59 c3[1] *= cmo;
60
61 c4[0] *= cmo;
62 c4[2] *= cmo;
63
64 tdstcol[0] = 0.5f * (tdstcol[0] + c1[0] + wt * (c2[0] + wt * (c3[0] + wt * c4[0])));
65 tdstcol[1] = 0.5f * (tdstcol[1] + c1[1] + wt * (c2[1] + wt * (c3[1] + wt * c4[1])));
66 tdstcol[2] = 0.5f * (tdstcol[2] + c1[2] + wt * (c2[2] + wt * (c3[2] + wt * c4[2])));
67 tdstcol[3] = 1.0f;
68 }
69 if (is_braked()) {
70 breaked = true;
71 }
72 }
73 memcpy(tsrc.get_buffer(), tdst.get_buffer(), sizeof(float) * size4);
74 }
75
76 float *sourcebuffer = tsrc.get_buffer();
77 float factor = 1.0f / float(6 - settings->iter);
78 for (int i = 0; i < size4; i += 4) {
79 madd_v3_v3fl(&data[i], &sourcebuffer[i], factor);
80 data[i + 3] = 1.0f;
81 }
82
83 tdst.clear();
84 memcpy(tsrc.get_buffer(), input_tile->get_buffer(), sizeof(float) * size4);
85 // nump++; /* UNUSED. */
86 }
87}
88
89} // namespace blender::compositor
#define DEG2RADF(_deg)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void generate_glare(float *data, MemoryBuffer *input_tile, const NodeGlare *settings) override
a MemoryBuffer contains access to the data
const rcti & get_rect() const
get the rect of this MemoryBuffer
void read(float *result, float x, float y, PixelSampler sampler=PixelSampler::Nearest, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip) const
const int get_width() const
get the width of this MemoryBuffer
const int get_height() const
get the height of this MemoryBuffer
float * get_buffer()
get the data of this MemoryBuffer
void read_bilinear(float *result, float x, float y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip) const
void clear()
clear the buffer. Make all pixels black transparent.
pow(value.r - subtrahend, 2.0)") .do_static_compilation(true)
draw_view in_light_buf[] float
ccl_device_inline float3 cos(float3 v)