Blender  V3.3
initrender.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 /* Global includes */
9 
10 #include <math.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 
15 #include "MEM_guardedalloc.h"
16 
17 #include "BLI_blenlib.h"
18 #include "BLI_ghash.h"
19 #include "BLI_math.h"
20 #include "BLI_utildefines.h"
21 
22 #include "DNA_camera_types.h"
23 
24 #include "BKE_camera.h"
25 
26 /* this module */
27 #include "pipeline.h"
28 #include "render_types.h"
29 
30 /* ****************** MASKS and LUTS **************** */
31 
32 static float filt_quadratic(float x)
33 {
34  if (x < 0.0f) {
35  x = -x;
36  }
37  if (x < 0.5f) {
38  return 0.75f - (x * x);
39  }
40  if (x < 1.5f) {
41  return 0.50f * (x - 1.5f) * (x - 1.5f);
42  }
43  return 0.0f;
44 }
45 
46 static float filt_cubic(float x)
47 {
48  float x2 = x * x;
49 
50  if (x < 0.0f) {
51  x = -x;
52  }
53 
54  if (x < 1.0f) {
55  return 0.5f * x * x2 - x2 + 2.0f / 3.0f;
56  }
57  if (x < 2.0f) {
58  return (2.0f - x) * (2.0f - x) * (2.0f - x) / 6.0f;
59  }
60  return 0.0f;
61 }
62 
63 static float filt_catrom(float x)
64 {
65  float x2 = x * x;
66 
67  if (x < 0.0f) {
68  x = -x;
69  }
70  if (x < 1.0f) {
71  return 1.5f * x2 * x - 2.5f * x2 + 1.0f;
72  }
73  if (x < 2.0f) {
74  return -0.5f * x2 * x + 2.5f * x2 - 4.0f * x + 2.0f;
75  }
76  return 0.0f;
77 }
78 
79 static float filt_mitchell(float x) /* Mitchell & Netravali's two-param cubic */
80 {
81  float b = 1.0f / 3.0f, c = 1.0f / 3.0f;
82  float p0 = (6.0f - 2.0f * b) / 6.0f;
83  float p2 = (-18.0f + 12.0f * b + 6.0f * c) / 6.0f;
84  float p3 = (12.0f - 9.0f * b - 6.0f * c) / 6.0f;
85  float q0 = (8.0f * b + 24.0f * c) / 6.0f;
86  float q1 = (-12.0f * b - 48.0f * c) / 6.0f;
87  float q2 = (6.0f * b + 30.0f * c) / 6.0f;
88  float q3 = (-b - 6.0f * c) / 6.0f;
89 
90  if (x < -2.0f) {
91  return 0.0f;
92  }
93  if (x < -1.0f) {
94  return (q0 - x * (q1 - x * (q2 - x * q3)));
95  }
96  if (x < 0.0f) {
97  return (p0 + x * x * (p2 - x * p3));
98  }
99  if (x < 1.0f) {
100  return (p0 + x * x * (p2 + x * p3));
101  }
102  if (x < 2.0f) {
103  return (q0 + x * (q1 + x * (q2 + x * q3)));
104  }
105  return 0.0f;
106 }
107 
108 float RE_filter_value(int type, float x)
109 {
110  float gaussfac = 1.6f;
111 
112  x = fabsf(x);
113 
114  switch (type) {
115  case R_FILTER_BOX:
116  if (x > 1.0f) {
117  return 0.0f;
118  }
119  return 1.0f;
120 
121  case R_FILTER_TENT:
122  if (x > 1.0f) {
123  return 0.0f;
124  }
125  return 1.0f - x;
126 
127  case R_FILTER_GAUSS: {
128  const float two_gaussfac2 = 2.0f * gaussfac * gaussfac;
129  x *= 3.0f * gaussfac;
130  return 1.0f / sqrtf((float)M_PI * two_gaussfac2) * expf(-x * x / two_gaussfac2);
131  }
132 
133  case R_FILTER_MITCH:
134  return filt_mitchell(x * gaussfac);
135 
136  case R_FILTER_QUAD:
137  return filt_quadratic(x * gaussfac);
138 
139  case R_FILTER_CUBIC:
140  return filt_cubic(x * gaussfac);
141 
142  case R_FILTER_CATROM:
143  return filt_catrom(x * gaussfac);
144  }
145  return 0.0f;
146 }
147 
148 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
149 
151 {
154 }
155 
157 {
158  re->camera_override = cam_ob;
159 }
160 
161 void RE_SetCamera(Render *re, const Object *cam_ob)
162 {
164 
165  /* setup parameters */
168  BKE_camera_multiview_params(&re->r, &params, cam_ob, re->viewname);
169 
170  /* Compute matrix, view-plane, etc. */
173 
174  /* extract results */
175  copy_m4_m4(re->winmat, params.winmat);
176  re->clip_start = params.clip_start;
177  re->clip_end = params.clip_end;
178  re->viewplane = params.viewplane;
179 }
180 
181 void RE_GetCameraWindow(struct Render *re, const struct Object *camera, float r_winmat[4][4])
182 {
183  RE_SetCamera(re, camera);
184  copy_m4_m4(r_winmat, re->winmat);
185 }
186 
187 void RE_GetCameraWindowWithOverscan(const struct Render *re, float overscan, float r_winmat[4][4])
188 {
190  params.is_ortho = re->winmat[3][3] != 0.0f;
191  params.clip_start = re->clip_start;
192  params.clip_end = re->clip_end;
193  params.viewplane = re->viewplane;
194 
195  overscan *= max_ff(BLI_rctf_size_x(&params.viewplane), BLI_rctf_size_y(&params.viewplane));
196 
197  params.viewplane.xmin -= overscan;
198  params.viewplane.xmax += overscan;
199  params.viewplane.ymin -= overscan;
200  params.viewplane.ymax += overscan;
202  copy_m4_m4(r_winmat, params.winmat);
203 }
204 
205 void RE_GetCameraModelMatrix(const Render *re, const struct Object *camera, float r_modelmat[4][4])
206 {
207  BKE_camera_multiview_model_matrix(&re->r, camera, re->viewname, r_modelmat);
208 }
209 
210 void RE_GetViewPlane(Render *re, rctf *r_viewplane, rcti *r_disprect)
211 {
212  *r_viewplane = re->viewplane;
213 
214  /* make disprect zero when no border render, is needed to detect changes in 3d view render */
215  if (re->r.mode & R_BORDER) {
216  *r_disprect = re->disprect;
217  }
218  else {
219  BLI_rcti_init(r_disprect, 0, 0, 0, 0);
220  }
221 }
Camera data-block and utility functions.
void BKE_camera_multiview_params(const struct RenderData *rd, struct CameraParams *params, const struct Object *camera, const char *viewname)
struct Object * BKE_camera_multiview_render(const struct Scene *scene, struct Object *camera, const char *viewname)
void BKE_camera_params_init(CameraParams *params)
Definition: camera.c:265
void BKE_camera_multiview_model_matrix(const struct RenderData *rd, const struct Object *camera, const char *viewname, float r_modelmat[4][4])
void BKE_camera_params_from_object(CameraParams *params, const struct Object *cam_ob)
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy)
Definition: camera.c:364
void BKE_camera_params_compute_matrix(CameraParams *params)
Definition: camera.c:429
MINLINE float max_ff(float a, float b)
#define M_PI
Definition: BLI_math_base.h:20
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:77
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:417
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:194
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition: BLI_rect.h:198
#define R_FILTER_GAUSS
#define R_BORDER
#define R_FILTER_QUAD
#define R_FILTER_MITCH
#define R_FILTER_TENT
#define R_FILTER_CUBIC
#define R_FILTER_BOX
#define R_FILTER_CATROM
_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 x2
_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 type
Read Guarded memory(de)allocation.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
#define expf(x)
Definition: cuda/compat.h:106
static float filt_cubic(float x)
Definition: initrender.c:46
void RE_GetViewPlane(Render *re, rctf *r_viewplane, rcti *r_disprect)
Definition: initrender.c:210
void RE_GetCameraWindowWithOverscan(const struct Render *re, float overscan, float r_winmat[4][4])
Definition: initrender.c:187
void RE_SetCamera(Render *re, const Object *cam_ob)
Definition: initrender.c:161
void RE_GetCameraModelMatrix(const Render *re, const struct Object *camera, float r_modelmat[4][4])
Definition: initrender.c:205
void RE_SetOverrideCamera(Render *re, Object *cam_ob)
Definition: initrender.c:156
static float filt_catrom(float x)
Definition: initrender.c:63
static float filt_quadratic(float x)
Definition: initrender.c:32
static float filt_mitchell(float x)
Definition: initrender.c:79
float RE_filter_value(int type, float x)
Definition: initrender.c:108
struct Object * RE_GetCamera(Render *re)
Definition: initrender.c:150
void RE_GetCameraWindow(struct Render *re, const struct Object *camera, float r_winmat[4][4])
Definition: initrender.c:181
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define fabsf(x)
Definition: metal/compat.h:219
#define sqrtf(x)
Definition: metal/compat.h:243
static unsigned c
Definition: RandGen.cpp:83
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
float winmat[4][4]
Definition: render_types.h:73
float clip_start
Definition: render_types.h:76
RenderData r
Definition: render_types.h:82
int winy
Definition: render_types.h:65
float clip_end
Definition: render_types.h:77
Scene * scene
Definition: render_types.h:81
char viewname[MAX_NAME]
Definition: render_types.h:123
int winx
Definition: render_types.h:65
rctf viewplane
Definition: render_types.h:67
rcti disprect
Definition: render_types.h:66
struct Object * camera_override
Definition: render_types.h:85
struct Object * camera