Blender  V2.93
COM_GlareStreaksOperation.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"
21 
22 namespace blender::compositor {
23 
25  MemoryBuffer *inputTile,
26  NodeGlare *settings)
27 {
28  int x, y, n;
29  unsigned int nump = 0;
30  float c1[4], c2[4], c3[4], c4[4];
31  float a, ang = DEG2RADF(360.0f) / (float)settings->streaks;
32 
33  int size = inputTile->getWidth() * inputTile->getHeight();
34  int size4 = size * 4;
35 
36  bool breaked = false;
37 
38  MemoryBuffer tsrc(*inputTile);
39  MemoryBuffer tdst(DataType::Color, inputTile->get_rect());
40  tdst.clear();
41  memset(data, 0, size4 * sizeof(float));
42 
43  for (a = 0.0f; a < DEG2RADF(360.0f) && (!breaked); a += ang) {
44  const float an = a + settings->angle_ofs;
45  const float vx = cos((double)an), vy = sin((double)an);
46  for (n = 0; n < settings->iter && (!breaked); n++) {
47  const float p4 = pow(4.0, (double)n);
48  const float vxp = vx * p4, vyp = vy * p4;
49  const float wt = pow((double)settings->fade, (double)p4);
50  const float cmo = 1.0f -
51  (float)pow((double)settings->colmod,
52  (double)n +
53  1); // colormodulation amount relative to current pass
54  float *tdstcol = tdst.getBuffer();
55  for (y = 0; y < tsrc.getHeight() && (!breaked); y++) {
56  for (x = 0; x < tsrc.getWidth(); x++, tdstcol += 4) {
57  // first pass no offset, always same for every pass, exact copy,
58  // otherwise results in uneven brightness, only need once
59  if (n == 0) {
60  tsrc.read(c1, x, y);
61  }
62  else {
63  c1[0] = c1[1] = c1[2] = 0;
64  }
65  tsrc.readBilinear(c2, x + vxp, y + vyp);
66  tsrc.readBilinear(c3, x + vxp * 2.0f, y + vyp * 2.0f);
67  tsrc.readBilinear(c4, x + vxp * 3.0f, y + vyp * 3.0f);
68  // modulate color to look vaguely similar to a color spectrum
69  c2[1] *= cmo;
70  c2[2] *= cmo;
71 
72  c3[0] *= cmo;
73  c3[1] *= cmo;
74 
75  c4[0] *= cmo;
76  c4[2] *= cmo;
77 
78  tdstcol[0] = 0.5f * (tdstcol[0] + c1[0] + wt * (c2[0] + wt * (c3[0] + wt * c4[0])));
79  tdstcol[1] = 0.5f * (tdstcol[1] + c1[1] + wt * (c2[1] + wt * (c3[1] + wt * c4[1])));
80  tdstcol[2] = 0.5f * (tdstcol[2] + c1[2] + wt * (c2[2] + wt * (c3[2] + wt * c4[2])));
81  tdstcol[3] = 1.0f;
82  }
83  if (isBraked()) {
84  breaked = true;
85  }
86  }
87  memcpy(tsrc.getBuffer(), tdst.getBuffer(), sizeof(float) * size4);
88  }
89 
90  float *sourcebuffer = tsrc.getBuffer();
91  float factor = 1.0f / (float)(6 - settings->iter);
92  for (int i = 0; i < size4; i += 4) {
93  madd_v3_v3fl(&data[i], &sourcebuffer[i], factor);
94  data[i + 3] = 1.0f;
95  }
96 
97  tdst.clear();
98  memcpy(tsrc.getBuffer(), inputTile->getBuffer(), sizeof(float) * size4);
99  nump++;
100  }
101 }
102 
103 } // namespace blender::compositor
typedef float(TangentPoint)[2]
#define DEG2RADF(_deg)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
typedef double(DMatrix)[4][4]
_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
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings) override
a MemoryBuffer contains access to the data of a chunk
void read(float *result, int x, int y, MemoryBufferExtend extend_x=MemoryBufferExtend::Clip, MemoryBufferExtend extend_y=MemoryBufferExtend::Clip)
const rcti & get_rect() const
get the rect of this MemoryBuffer
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 clear()
clear the buffer. Make all pixels black transparent.
static unsigned a[3]
Definition: RandGen.cpp:92
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
Definition: rall1d.h:359
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:311
float angle_ofs
char angle streaks