Blender V4.3
cycles/util/projection.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __UTIL_PROJECTION_H__
6#define __UTIL_PROJECTION_H__
7
8#include "util/transform.h"
9
11
12/* 4x4 projection matrix, perspective or orthographic. */
13
14typedef struct ProjectionTransform {
15 float4 x, y, z, w; /* rows */
16
17#ifndef __KERNEL_GPU__
19
20 explicit ProjectionTransform(const Transform &tfm)
21 : x(tfm.x), y(tfm.y), z(tfm.z), w(make_float4(0.0f, 0.0f, 0.0f, 1.0f))
22 {
23 }
24#endif
26
31
32/* Functions */
33
35 const float3 a)
36{
37 float4 b = make_float4(a.x, a.y, a.z, 1.0f);
38 float3 c = make_float3(dot(t->x, b), dot(t->y, b), dot(t->z, b));
39 float w = dot(t->w, b);
40
41 return (w != 0.0f) ? c / w : zero_float3();
42}
43
45 const float3 a)
46{
47 float3 c = make_float3(a.x * t->x.x + a.y * t->x.y + a.z * t->x.z,
48 a.x * t->y.x + a.y * t->y.y + a.z * t->y.z,
49 a.x * t->z.x + a.y * t->z.y + a.z * t->z.z);
50
51 return c;
52}
53
54#ifndef __KERNEL_GPU__
55
57{
58 Transform tfm = {a.x, a.y, a.z};
59 return tfm;
60}
61
63{
65
66 t.x.x = a.x.x;
67 t.x.y = a.y.x;
68 t.x.z = a.z.x;
69 t.x.w = a.w.x;
70 t.y.x = a.x.y;
71 t.y.y = a.y.y;
72 t.y.z = a.z.y;
73 t.y.w = a.w.y;
74 t.z.x = a.x.z;
75 t.z.y = a.y.z;
76 t.z.z = a.z.z;
77 t.z.w = a.w.z;
78 t.w.x = a.x.w;
79 t.w.y = a.y.w;
80 t.w.z = a.z.w;
81 t.w.w = a.w.w;
82
83 return t;
84}
85
87
89 float b,
90 float c,
91 float d,
92 float e,
93 float f,
94 float g,
95 float h,
96 float i,
97 float j,
98 float k,
99 float l,
100 float m,
101 float n,
102 float o,
103 float p)
104{
106
107 t.x.x = a;
108 t.x.y = b;
109 t.x.z = c;
110 t.x.w = d;
111 t.y.x = e;
112 t.y.y = f;
113 t.y.z = g;
114 t.y.w = h;
115 t.z.x = i;
116 t.z.y = j;
117 t.z.z = k;
118 t.z.w = l;
119 t.w.x = m;
120 t.w.y = n;
121 t.w.z = o;
122 t.w.w = p;
123
124 return t;
125}
127{
128 return make_projection(1.0f,
129 0.0f,
130 0.0f,
131 0.0f,
132 0.0f,
133 1.0f,
134 0.0f,
135 0.0f,
136 0.0f,
137 0.0f,
138 1.0f,
139 0.0f,
140 0.0f,
141 0.0f,
142 0.0f,
143 1.0f);
144}
145
147 const ProjectionTransform &b)
148{
151
152 t.x = make_float4(dot(a.x, c.x), dot(a.x, c.y), dot(a.x, c.z), dot(a.x, c.w));
153 t.y = make_float4(dot(a.y, c.x), dot(a.y, c.y), dot(a.y, c.z), dot(a.y, c.w));
154 t.z = make_float4(dot(a.z, c.x), dot(a.z, c.y), dot(a.z, c.z), dot(a.z, c.w));
155 t.w = make_float4(dot(a.w, c.x), dot(a.w, c.y), dot(a.w, c.z), dot(a.w, c.w));
156
157 return t;
158}
159
164
169
171{
172 print_float4(label, t.x);
173 print_float4(label, t.y);
174 print_float4(label, t.z);
175 print_float4(label, t.w);
176 printf("\n");
177}
178
180{
182 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, f / (f - n), -f * n / (f - n), 0, 0, 1, 0);
183
184 float inv_angle = 1.0f / tanf(0.5f * fov);
185
186 Transform scale = transform_scale(inv_angle, inv_angle, 1);
187
188 return scale * persp;
189}
190
192{
193 Transform t = transform_scale(1.0f, 1.0f, 1.0f / (zfar - znear));
194
195 return ProjectionTransform(t);
196}
197
198#endif /* __KERNEL_GPU__ */
199
201
202#endif /* __UTIL_PROJECTION_H__ */
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
local_group_size(16, 16) .push_constant(Type b
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
#define printf
ccl_device_inline float3 transform_perspective(ccl_private const ProjectionTransform *t, const float3 a)
ccl_device_inline ProjectionTransform projection_perspective(float fov, float n, float f)
ccl_device_inline ProjectionTransform operator*(const ProjectionTransform &a, const ProjectionTransform &b)
ccl_device_inline ProjectionTransform make_projection(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p)
ccl_device_inline float3 transform_perspective_direction(ccl_private const ProjectionTransform *t, const float3 a)
struct PerspectiveMotionTransform PerspectiveMotionTransform
CCL_NAMESPACE_BEGIN struct ProjectionTransform ProjectionTransform
ccl_device_inline Transform projection_to_transform(const ProjectionTransform &a)
ccl_device_inline ProjectionTransform projection_identity()
ccl_device_inline ProjectionTransform projection_transpose(const ProjectionTransform &a)
ProjectionTransform projection_inverse(const ProjectionTransform &a)
Definition transform.cpp:98
ccl_device_inline ProjectionTransform projection_orthographic(float znear, float zfar)
ccl_device_inline void print_projection(const char *label, const ProjectionTransform &t)
const char * label
#define ccl_private
#define ccl_device_inline
#define tanf(x)
#define CCL_NAMESPACE_END
ccl_device_forceinline float4 make_float4(const float x, const float y, const float z, const float w)
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:15
ProjectionTransform(const Transform &tfm)
float4 x
Definition transform.h:24
ccl_device_inline Transform transform_scale(float3 s)
Definition transform.h:254
ccl_device_inline void print_float4(ccl_private const char *label, const float4 a)