Blender  V2.93
COM_GlareGhostOperation.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
20 #include "BLI_math.h"
22 
23 namespace blender::compositor {
24 
25 static float smoothMask(float x, float y)
26 {
27  float t;
28  x = 2.0f * x - 1.0f;
29  y = 2.0f * y - 1.0f;
30  if ((t = 1.0f - sqrtf(x * x + y * y)) > 0.0f) {
31  return t;
32  }
33 
34  return 0.0f;
35 }
36 
38 {
39  const int qt = 1 << settings->quality;
40  const float s1 = 4.0f / (float)qt, s2 = 2.0f * s1;
41  int x, y, n, p, np;
42  fRGB c, tc, cm[64];
43  float sc, isc, u, v, sm, s, t, ofs, scalef[64];
44  const float cmo = 1.0f - settings->colmod;
45 
46  MemoryBuffer gbuf(*inputTile);
47  MemoryBuffer tbuf1(*inputTile);
48 
49  bool breaked = false;
50 
51  FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 0, 3);
52  if (!breaked) {
53  FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 1, 3);
54  }
55  if (isBraked()) {
56  breaked = true;
57  }
58  if (!breaked) {
59  FastGaussianBlurOperation::IIR_gauss(&tbuf1, s1, 2, 3);
60  }
61 
62  MemoryBuffer tbuf2(tbuf1);
63 
64  if (isBraked()) {
65  breaked = true;
66  }
67  if (!breaked) {
68  FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 0, 3);
69  }
70  if (isBraked()) {
71  breaked = true;
72  }
73  if (!breaked) {
74  FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 1, 3);
75  }
76  if (isBraked()) {
77  breaked = true;
78  }
79  if (!breaked) {
80  FastGaussianBlurOperation::IIR_gauss(&tbuf2, s2, 2, 3);
81  }
82 
83  ofs = (settings->iter & 1) ? 0.5f : 0.0f;
84  for (x = 0; x < (settings->iter * 4); x++) {
85  y = x & 3;
86  cm[x][0] = cm[x][1] = cm[x][2] = 1;
87  if (y == 1) {
88  fRGB_rgbmult(cm[x], 1.0f, cmo, cmo);
89  }
90  if (y == 2) {
91  fRGB_rgbmult(cm[x], cmo, cmo, 1.0f);
92  }
93  if (y == 3) {
94  fRGB_rgbmult(cm[x], cmo, 1.0f, cmo);
95  }
96  scalef[x] = 2.1f * (1.0f - (x + ofs) / (float)(settings->iter * 4));
97  if (x & 1) {
98  scalef[x] = -0.99f / scalef[x];
99  }
100  }
101 
102  sc = 2.13;
103  isc = -0.97;
104  for (y = 0; y < gbuf.getHeight() && (!breaked); y++) {
105  v = ((float)y + 0.5f) / (float)gbuf.getHeight();
106  for (x = 0; x < gbuf.getWidth(); x++) {
107  u = ((float)x + 0.5f) / (float)gbuf.getWidth();
108  s = (u - 0.5f) * sc + 0.5f;
109  t = (v - 0.5f) * sc + 0.5f;
110  tbuf1.readBilinear(c, s * gbuf.getWidth(), t * gbuf.getHeight());
111  sm = smoothMask(s, t);
112  mul_v3_fl(c, sm);
113  s = (u - 0.5f) * isc + 0.5f;
114  t = (v - 0.5f) * isc + 0.5f;
115  tbuf2.readBilinear(tc, s * gbuf.getWidth() - 0.5f, t * gbuf.getHeight() - 0.5f);
116  sm = smoothMask(s, t);
117  madd_v3_v3fl(c, tc, sm);
118 
119  gbuf.writePixel(x, y, c);
120  }
121  if (isBraked()) {
122  breaked = true;
123  }
124  }
125 
126  memset(tbuf1.getBuffer(),
127  0,
128  tbuf1.getWidth() * tbuf1.getHeight() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float));
129  for (n = 1; n < settings->iter && (!breaked); n++) {
130  for (y = 0; y < gbuf.getHeight() && (!breaked); y++) {
131  v = ((float)y + 0.5f) / (float)gbuf.getHeight();
132  for (x = 0; x < gbuf.getWidth(); x++) {
133  u = ((float)x + 0.5f) / (float)gbuf.getWidth();
134  tc[0] = tc[1] = tc[2] = 0.0f;
135  for (p = 0; p < 4; p++) {
136  np = (n << 2) + p;
137  s = (u - 0.5f) * scalef[np] + 0.5f;
138  t = (v - 0.5f) * scalef[np] + 0.5f;
139  gbuf.readBilinear(c, s * gbuf.getWidth() - 0.5f, t * gbuf.getHeight() - 0.5f);
140  mul_v3_v3(c, cm[np]);
141  sm = smoothMask(s, t) * 0.25f;
142  madd_v3_v3fl(tc, c, sm);
143  }
144  tbuf1.addPixel(x, y, tc);
145  }
146  if (isBraked()) {
147  breaked = true;
148  }
149  }
150  memcpy(gbuf.getBuffer(),
151  tbuf1.getBuffer(),
152  tbuf1.getWidth() * tbuf1.getHeight() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float));
153  }
154  memcpy(data,
155  gbuf.getBuffer(),
156  gbuf.getWidth() * gbuf.getHeight() * COM_DATA_TYPE_COLOR_CHANNELS * sizeof(float));
157 }
158 
159 } // 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 generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings) override
a MemoryBuffer contains access to the data of a chunk
void writePixel(int x, int y, const float color[4])
const int getHeight() const
get the height of this MemoryBuffer
const int getWidth() const
get the width of this MemoryBuffer
void readBilinear(float *result, float x, float y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip)
float * getBuffer()
get the data of this MemoryBuffer
void addPixel(int x, int y, const float color[4])
#define sqrtf(x)
static unsigned c
Definition: RandGen.cpp:97
static float smoothMask(float x, float y)
constexpr int COM_DATA_TYPE_COLOR_CHANNELS
Definition: COM_defines.h:53