Blender  V3.3
COM_GlareGhostOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
6 
7 namespace blender::compositor {
8 
9 static float smooth_mask(float x, float y)
10 {
11  float t;
12  x = 2.0f * x - 1.0f;
13  y = 2.0f * y - 1.0f;
14  if ((t = 1.0f - sqrtf(x * x + y * y)) > 0.0f) {
15  return t;
16  }
17 
18  return 0.0f;
19 }
20 
22  MemoryBuffer *input_tile,
23  NodeGlare *settings)
24 {
25  const int qt = 1 << settings->quality;
26  const float s1 = 4.0f / (float)qt, s2 = 2.0f * s1;
27  int x, y, n, p, np;
28  fRGB c, tc, cm[64];
29  float sc, isc, u, v, sm, s, t, ofs, scalef[64];
30  const float cmo = 1.0f - settings->colmod;
31 
32  MemoryBuffer gbuf(*input_tile);
33  MemoryBuffer tbuf1(*input_tile);
34 
35  bool breaked = false;
36 
37  FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 0, 3);
38  if (!breaked) {
39  FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 1, 3);
40  }
41  if (is_braked()) {
42  breaked = true;
43  }
44  if (!breaked) {
45  FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 2, 3);
46  }
47 
48  MemoryBuffer tbuf2(tbuf1);
49 
50  if (is_braked()) {
51  breaked = true;
52  }
53  if (!breaked) {
54  FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 0, 3);
55  }
56  if (is_braked()) {
57  breaked = true;
58  }
59  if (!breaked) {
60  FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 1, 3);
61  }
62  if (is_braked()) {
63  breaked = true;
64  }
65  if (!breaked) {
66  FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 2, 3);
67  }
68 
69  ofs = (settings->iter & 1) ? 0.5f : 0.0f;
70  for (x = 0; x < (settings->iter * 4); x++) {
71  y = x & 3;
72  cm[x][0] = cm[x][1] = cm[x][2] = 1;
73  if (y == 1) {
74  fRGB_rgbmult(cm[x], 1.0f, cmo, cmo);
75  }
76  if (y == 2) {
77  fRGB_rgbmult(cm[x], cmo, cmo, 1.0f);
78  }
79  if (y == 3) {
80  fRGB_rgbmult(cm[x], cmo, 1.0f, cmo);
81  }
82  scalef[x] = 2.1f * (1.0f - (x + ofs) / (float)(settings->iter * 4));
83  if (x & 1) {
84  scalef[x] = -0.99f / scalef[x];
85  }
86  }
87 
88  sc = 2.13;
89  isc = -0.97;
90  for (y = 0; y < gbuf.get_height() && (!breaked); y++) {
91  v = ((float)y + 0.5f) / (float)gbuf.get_height();
92  for (x = 0; x < gbuf.get_width(); x++) {
93  u = ((float)x + 0.5f) / (float)gbuf.get_width();
94  s = (u - 0.5f) * sc + 0.5f;
95  t = (v - 0.5f) * sc + 0.5f;
96  tbuf1.read_bilinear(c, s * gbuf.get_width(), t * gbuf.get_height());
97  sm = smooth_mask(s, t);
98  mul_v3_fl(c, sm);
99  s = (u - 0.5f) * isc + 0.5f;
100  t = (v - 0.5f) * isc + 0.5f;
101  tbuf2.read_bilinear(tc, s * gbuf.get_width() - 0.5f, t * gbuf.get_height() - 0.5f);
102  sm = smooth_mask(s, t);
103  madd_v3_v3fl(c, tc, sm);
104 
105  gbuf.write_pixel(x, y, c);
106  }
107  if (is_braked()) {
108  breaked = true;
109  }
110  }
111 
112  memset(tbuf1.get_buffer(),
113  0,
114  tbuf1.get_width() * tbuf1.get_height() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float));
115  for (n = 1; n < settings->iter && (!breaked); n++) {
116  for (y = 0; y < gbuf.get_height() && (!breaked); y++) {
117  v = ((float)y + 0.5f) / (float)gbuf.get_height();
118  for (x = 0; x < gbuf.get_width(); x++) {
119  u = ((float)x + 0.5f) / (float)gbuf.get_width();
120  tc[0] = tc[1] = tc[2] = 0.0f;
121  for (p = 0; p < 4; p++) {
122  np = (n << 2) + p;
123  s = (u - 0.5f) * scalef[np] + 0.5f;
124  t = (v - 0.5f) * scalef[np] + 0.5f;
125  gbuf.read_bilinear(c, s * gbuf.get_width() - 0.5f, t * gbuf.get_height() - 0.5f);
126  mul_v3_v3(c, cm[np]);
127  sm = smooth_mask(s, t) * 0.25f;
128  madd_v3_v3fl(tc, c, sm);
129  }
130  tbuf1.add_pixel(x, y, tc);
131  }
132  if (is_braked()) {
133  breaked = true;
134  }
135  }
136  memcpy(gbuf.get_buffer(),
137  tbuf1.get_buffer(),
138  tbuf1.get_width() * tbuf1.get_height() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float));
139  }
140  memcpy(data,
141  gbuf.get_buffer(),
142  gbuf.get_width() * gbuf.get_height() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float));
143 }
144 
145 } // namespace blender::compositor
typedef float(TangentPoint)[2]
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void mul_v3_v3(float r[3], const float a[3])
MINLINE void mul_v3_fl(float r[3], float f)
#define fRGB_rgbmult(c, r, g, b)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
ATTR_WARN_UNUSED_RESULT const BMVert * v
static void IIR_gauss(MemoryBuffer *src, float sigma, unsigned int channel, unsigned int xy)
void generate_glare(float *data, MemoryBuffer *input_tile, NodeGlare *settings) override
a MemoryBuffer contains access to the data of a chunk
const int get_width() const
get the width of this MemoryBuffer
const int get_height() const
get the height of this MemoryBuffer
void write_pixel(int x, int y, const float color[4])
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 add_pixel(int x, int y, const float color[4])
#define sqrtf(x)
Definition: metal/compat.h:243
static unsigned c
Definition: RandGen.cpp:83
constexpr int COM_DATA_TYPE_COLOR_CHANNELS
Definition: COM_defines.h:62
static float smooth_mask(float x, float y)