Blender  V2.93
COM_ConvertDepthToRadiusOperation.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 "BKE_camera.h"
21 #include "BLI_math.h"
22 #include "DNA_camera_types.h"
23 
24 namespace blender::compositor {
25 
27 {
30  this->m_inputOperation = nullptr;
31  this->m_fStop = 128.0f;
32  this->m_cameraObject = nullptr;
33  this->m_maxRadius = 32.0f;
34  this->m_blurPostOperation = nullptr;
35 }
36 
38 {
39  if (this->m_cameraObject && this->m_cameraObject->type == OB_CAMERA) {
40  Camera *camera = (Camera *)this->m_cameraObject->data;
41  this->m_cam_lens = camera->lens;
42  return BKE_camera_object_dof_distance(this->m_cameraObject);
43  }
44 
45  return 10.0f;
46 }
47 
49 {
50  float cam_sensor = DEFAULT_SENSOR_WIDTH;
51  Camera *camera = nullptr;
52 
53  if (this->m_cameraObject && this->m_cameraObject->type == OB_CAMERA) {
54  camera = (Camera *)this->m_cameraObject->data;
55  cam_sensor = BKE_camera_sensor_size(camera->sensor_fit, camera->sensor_x, camera->sensor_y);
56  }
57 
58  this->m_inputOperation = this->getInputSocketReader(0);
59  float focalDistance = determineFocalDistance();
60  if (focalDistance == 0.0f) {
61  focalDistance = 1e10f; /* if the dof is 0.0 then set it to be far away */
62  }
63  this->m_inverseFocalDistance = 1.0f / focalDistance;
64  this->m_aspect = (this->getWidth() > this->getHeight()) ?
65  (this->getHeight() / (float)this->getWidth()) :
66  (this->getWidth() / (float)this->getHeight());
67  this->m_aperture = 0.5f * (this->m_cam_lens / (this->m_aspect * cam_sensor)) / this->m_fStop;
68  const float minsz = MIN2(getWidth(), getHeight());
69  this->m_dof_sp = minsz /
70  ((cam_sensor / 2.0f) /
71  this->m_cam_lens); // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov);
72 
73  if (this->m_blurPostOperation) {
74  m_blurPostOperation->setSigma(MIN2(m_aperture * 128.0f, this->m_maxRadius));
75  }
76 }
77 
79  float x,
80  float y,
81  PixelSampler sampler)
82 {
83  float inputValue[4];
84  float z;
85  float radius;
86  this->m_inputOperation->readSampled(inputValue, x, y, sampler);
87  z = inputValue[0];
88  if (z != 0.0f) {
89  float iZ = (1.0f / z);
90 
91  /* bug T6656 part 2b, do not re-scale. */
92 #if 0
93  bcrad = 0.5f * fabs(aperture * (dof_sp * (cam_invfdist - iZ) - 1.0f));
94  // scale crad back to original maximum and blend
95  crad->rect[px] = bcrad + wts->rect[px] * (scf * crad->rect[px] - bcrad);
96 #endif
97  radius = 0.5f * fabsf(this->m_aperture *
98  (this->m_dof_sp * (this->m_inverseFocalDistance - iZ) - 1.0f));
99  /* 'bug' T6615, limit minimum radius to 1 pixel,
100  * not really a solution, but somewhat mitigates the problem. */
101  if (radius < 0.0f) {
102  radius = 0.0f;
103  }
104  if (radius > this->m_maxRadius) {
105  radius = this->m_maxRadius;
106  }
107  output[0] = radius;
108  }
109  else {
110  output[0] = 0.0f;
111  }
112 }
113 
115 {
116  this->m_inputOperation = nullptr;
117 }
118 
119 } // namespace blender::compositor
typedef float(TangentPoint)[2]
Camera data-block and utility functions.
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
Definition: camera.c:242
float BKE_camera_object_dof_distance(struct Object *ob)
Definition: camera.c:227
#define MIN2(a, b)
#define DEFAULT_SENSOR_WIDTH
@ OB_CAMERA
_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 z
_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
#define output
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
void readSampled(float result[4], float x, float y, PixelSampler sampler)
void addInputSocket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void addOutputSocket(DataType datatype)
SocketReader * getInputSocketReader(unsigned int inputSocketindex)
#define fabsf(x)
char sensor_fit
float sensor_y
float sensor_x
void * data
ccl_device_inline float2 fabs(const float2 &a)