Blender V4.3
initrender.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9/* Global includes */
10
11#include <cmath>
12#include <cstdio>
13#include <cstdlib>
14#include <cstring>
15
16#include "MEM_guardedalloc.h"
17
18#include "BLI_math_base.h"
19#include "BLI_math_matrix.h"
20#include "BLI_utildefines.h"
21
22#include "BKE_camera.h"
23
24/* this module */
25#include "render_types.h"
26
27/* ****************** MASKS and LUTS **************** */
28
29static float filt_quadratic(float x)
30{
31 if (x < 0.0f) {
32 x = -x;
33 }
34 if (x < 0.5f) {
35 return 0.75f - (x * x);
36 }
37 if (x < 1.5f) {
38 return 0.50f * (x - 1.5f) * (x - 1.5f);
39 }
40 return 0.0f;
41}
42
43static float filt_cubic(float x)
44{
45 float x2 = x * x;
46
47 if (x < 0.0f) {
48 x = -x;
49 }
50
51 if (x < 1.0f) {
52 return 0.5f * x * x2 - x2 + 2.0f / 3.0f;
53 }
54 if (x < 2.0f) {
55 return (2.0f - x) * (2.0f - x) * (2.0f - x) / 6.0f;
56 }
57 return 0.0f;
58}
59
60static float filt_catrom(float x)
61{
62 float x2 = x * x;
63
64 if (x < 0.0f) {
65 x = -x;
66 }
67 if (x < 1.0f) {
68 return 1.5f * x2 * x - 2.5f * x2 + 1.0f;
69 }
70 if (x < 2.0f) {
71 return -0.5f * x2 * x + 2.5f * x2 - 4.0f * x + 2.0f;
72 }
73 return 0.0f;
74}
75
76static float filt_mitchell(float x) /* Mitchell & Netravali's two-param cubic */
77{
78 float b = 1.0f / 3.0f, c = 1.0f / 3.0f;
79 float p0 = (6.0f - 2.0f * b) / 6.0f;
80 float p2 = (-18.0f + 12.0f * b + 6.0f * c) / 6.0f;
81 float p3 = (12.0f - 9.0f * b - 6.0f * c) / 6.0f;
82 float q0 = (8.0f * b + 24.0f * c) / 6.0f;
83 float q1 = (-12.0f * b - 48.0f * c) / 6.0f;
84 float q2 = (6.0f * b + 30.0f * c) / 6.0f;
85 float q3 = (-b - 6.0f * c) / 6.0f;
86
87 if (x < -2.0f) {
88 return 0.0f;
89 }
90 if (x < -1.0f) {
91 return (q0 - x * (q1 - x * (q2 - x * q3)));
92 }
93 if (x < 0.0f) {
94 return (p0 + x * x * (p2 - x * p3));
95 }
96 if (x < 1.0f) {
97 return (p0 + x * x * (p2 + x * p3));
98 }
99 if (x < 2.0f) {
100 return (q0 + x * (q1 + x * (q2 + x * q3)));
101 }
102 return 0.0f;
103}
104
105float RE_filter_value(int type, float x)
106{
107 float gaussfac = 1.6f;
108
109 x = fabsf(x);
110
111 switch (type) {
112 case R_FILTER_BOX:
113 if (x > 1.0f) {
114 return 0.0f;
115 }
116 return 1.0f;
117
118 case R_FILTER_TENT:
119 if (x > 1.0f) {
120 return 0.0f;
121 }
122 return 1.0f - x;
123
124 case R_FILTER_GAUSS:
125 case R_FILTER_FAST_GAUSS: {
126 const float two_gaussfac2 = 2.0f * gaussfac * gaussfac;
127 x *= 3.0f * gaussfac;
128 return 1.0f / sqrtf(float(M_PI) * two_gaussfac2) * expf(-x * x / two_gaussfac2);
129 }
130
131 case R_FILTER_MITCH:
132 return filt_mitchell(x * gaussfac);
133
134 case R_FILTER_QUAD:
135 return filt_quadratic(x * gaussfac);
136
137 case R_FILTER_CUBIC:
138 return filt_cubic(x * gaussfac);
139
140 case R_FILTER_CATROM:
141 return filt_catrom(x * gaussfac);
142 }
143 return 0.0f;
144}
145
146/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
147
149{
150 Object *camera = re->camera_override ? re->camera_override : re->scene->camera;
151 return BKE_camera_multiview_render(re->scene, camera, re->viewname);
152}
153
155{
156 re->camera_override = cam_ob;
157}
158
159void RE_SetCamera(Render *re, const Object *cam_ob)
160{
162
163 /* setup parameters */
166 BKE_camera_multiview_params(&re->r, &params, cam_ob, re->viewname);
167
168 /* Compute matrix, view-plane, etc. */
171
172 /* extract results */
173 copy_m4_m4(re->winmat, params.winmat);
174 re->clip_start = params.clip_start;
175 re->clip_end = params.clip_end;
176 re->viewplane = params.viewplane;
177}
178
179void RE_GetCameraWindow(Render *re, const Object *camera, float r_winmat[4][4])
180{
181 RE_SetCamera(re, camera);
182 copy_m4_m4(r_winmat, re->winmat);
183}
184
185void RE_GetCameraWindowWithOverscan(const Render *re, float overscan, float r_winmat[4][4])
186{
188 re->winmat[3][3] != 0.0f, re->clip_start, re->clip_end, re->viewplane, overscan, r_winmat);
189}
190
191void RE_GetCameraModelMatrix(const Render *re, const Object *camera, float r_modelmat[4][4])
192{
193 BKE_camera_multiview_model_matrix(&re->r, camera, re->viewname, r_modelmat);
194}
195
197 float clip_start,
198 float clip_end,
199 rctf viewplane,
200 float overscan,
201 float r_winmat[4][4])
202{
204 params.is_ortho = is_ortho;
205 params.clip_start = clip_start;
206 params.clip_end = clip_end;
207 params.viewplane = viewplane;
208
209 overscan *= max_ff(BLI_rctf_size_x(&params.viewplane), BLI_rctf_size_y(&params.viewplane));
210
211 params.viewplane.xmin -= overscan;
212 params.viewplane.xmax += overscan;
213 params.viewplane.ymin -= overscan;
214 params.viewplane.ymax += overscan;
216 copy_m4_m4(r_winmat, params.winmat);
217}
218
219void RE_GetViewPlane(Render *re, rctf *r_viewplane, rcti *r_disprect)
220{
221 *r_viewplane = re->viewplane;
222
223 /* make disprect zero when no border render, is needed to detect changes in 3d view render */
224 if (re->r.mode & R_BORDER) {
225 *r_disprect = re->disprect;
226 }
227 else {
228 BLI_rcti_init(r_disprect, 0, 0, 0, 0);
229 }
230}
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)
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)
void BKE_camera_params_compute_matrix(CameraParams *params)
MINLINE float max_ff(float a, float b)
#define M_PI
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.c:418
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.h:197
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.h:201
@ R_FILTER_TENT
@ R_FILTER_GAUSS
@ R_FILTER_FAST_GAUSS
@ R_FILTER_CATROM
@ R_FILTER_MITCH
@ R_FILTER_BOX
@ R_FILTER_CUBIC
@ R_FILTER_QUAD
@ R_BORDER
Read Guarded memory(de)allocation.
local_group_size(16, 16) .push_constant(Type b
#define expf(x)
#define fabsf(x)
#define sqrtf(x)
void RE_GetCameraModelMatrix(const Render *re, const Object *camera, float r_modelmat[4][4])
static float filt_cubic(float x)
Definition initrender.cc:43
void RE_GetCameraWindowWithOverscan(const Render *re, float overscan, float r_winmat[4][4])
void RE_GetViewPlane(Render *re, rctf *r_viewplane, rcti *r_disprect)
void RE_GetCameraWindow(Render *re, const Object *camera, float r_winmat[4][4])
void RE_GetWindowMatrixWithOverscan(bool is_ortho, float clip_start, float clip_end, rctf viewplane, float overscan, float r_winmat[4][4])
void RE_SetCamera(Render *re, const Object *cam_ob)
void RE_SetOverrideCamera(Render *re, Object *cam_ob)
Object * RE_GetCamera(Render *re)
static float filt_catrom(float x)
Definition initrender.cc:60
static float filt_quadratic(float x)
Definition initrender.cc:29
static float filt_mitchell(float x)
Definition initrender.cc:76
float RE_filter_value(int type, float x)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
float winmat[4][4]
float clip_start
RenderData r
float clip_end
Scene * scene
char viewname[MAX_NAME]
rctf viewplane
rcti disprect
struct Object * camera_override
struct Object * camera