Blender  V3.3
cycles/util/projection.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __UTIL_PROJECTION_H__
5 #define __UTIL_PROJECTION_H__
6 
7 #include "util/transform.h"
8 
10 
11 /* 4x4 projection matrix, perspective or orthographic. */
12 
13 typedef struct ProjectionTransform {
14  float4 x, y, z, w; /* rows */
15 
16 #ifndef __KERNEL_GPU__
18  {
19  }
20 
21  explicit ProjectionTransform(const Transform &tfm)
22  : x(tfm.x), y(tfm.y), z(tfm.z), w(make_float4(0.0f, 0.0f, 0.0f, 1.0f))
23  {
24  }
25 #endif
27 
32 
33 /* Functions */
34 
36  const float3 a)
37 {
38  float4 b = make_float4(a.x, a.y, a.z, 1.0f);
39  float3 c = make_float3(dot(t->x, b), dot(t->y, b), dot(t->z, b));
40  float w = dot(t->w, b);
41 
42  return (w != 0.0f) ? c / w : zero_float3();
43 }
44 
46  const float3 a)
47 {
48  float3 c = make_float3(a.x * t->x.x + a.y * t->x.y + a.z * t->x.z,
49  a.x * t->y.x + a.y * t->y.y + a.z * t->y.z,
50  a.x * t->z.x + a.y * t->z.y + a.z * t->z.z);
51 
52  return c;
53 }
54 
55 #ifndef __KERNEL_GPU__
56 
58 {
59  Transform tfm = {a.x, a.y, a.z};
60  return tfm;
61 }
62 
64 {
66 
67  t.x.x = a.x.x;
68  t.x.y = a.y.x;
69  t.x.z = a.z.x;
70  t.x.w = a.w.x;
71  t.y.x = a.x.y;
72  t.y.y = a.y.y;
73  t.y.z = a.z.y;
74  t.y.w = a.w.y;
75  t.z.x = a.x.z;
76  t.z.y = a.y.z;
77  t.z.z = a.z.z;
78  t.z.w = a.w.z;
79  t.w.x = a.x.w;
80  t.w.y = a.y.w;
81  t.w.z = a.z.w;
82  t.w.w = a.w.w;
83 
84  return t;
85 }
86 
88 
90  float b,
91  float c,
92  float d,
93  float e,
94  float f,
95  float g,
96  float h,
97  float i,
98  float j,
99  float k,
100  float l,
101  float m,
102  float n,
103  float o,
104  float p)
105 {
107 
108  t.x.x = a;
109  t.x.y = b;
110  t.x.z = c;
111  t.x.w = d;
112  t.y.x = e;
113  t.y.y = f;
114  t.y.z = g;
115  t.y.w = h;
116  t.z.x = i;
117  t.z.y = j;
118  t.z.z = k;
119  t.z.w = l;
120  t.w.x = m;
121  t.w.y = n;
122  t.w.z = o;
123  t.w.w = p;
124 
125  return t;
126 }
128 {
129  return make_projection(1.0f,
130  0.0f,
131  0.0f,
132  0.0f,
133  0.0f,
134  1.0f,
135  0.0f,
136  0.0f,
137  0.0f,
138  0.0f,
139  1.0f,
140  0.0f,
141  0.0f,
142  0.0f,
143  0.0f,
144  1.0f);
145 }
146 
148  const ProjectionTransform &b)
149 {
152 
153  t.x = make_float4(dot(a.x, c.x), dot(a.x, c.y), dot(a.x, c.z), dot(a.x, c.w));
154  t.y = make_float4(dot(a.y, c.x), dot(a.y, c.y), dot(a.y, c.z), dot(a.y, c.w));
155  t.z = make_float4(dot(a.z, c.x), dot(a.z, c.y), dot(a.z, c.z), dot(a.z, c.w));
156  t.w = make_float4(dot(a.w, c.x), dot(a.w, c.y), dot(a.w, c.z), dot(a.w, c.w));
157 
158  return t;
159 }
160 
162 {
163  return a * ProjectionTransform(b);
164 }
165 
167 {
168  return ProjectionTransform(a) * b;
169 }
170 
172 {
173  print_float4(label, t.x);
174  print_float4(label, t.y);
175  print_float4(label, t.z);
176  print_float4(label, t.w);
177  printf("\n");
178 }
179 
181 {
183  1, 0, 0, 0, 0, 1, 0, 0, 0, 0, f / (f - n), -f * n / (f - n), 0, 0, 1, 0);
184 
185  float inv_angle = 1.0f / tanf(0.5f * fov);
186 
187  Transform scale = transform_scale(inv_angle, inv_angle, 1);
188 
189  return scale * persp;
190 }
191 
193 {
194  Transform t = transform_scale(1.0f, 1.0f, 1.0f / (zfar - znear)) *
195  transform_translate(0.0f, 0.0f, -znear);
196 
197  return ProjectionTransform(t);
198 }
199 
200 #endif /* __KERNEL_GPU__ */
201 
203 
204 #endif /* __UTIL_PROJECTION_H__ */
_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 GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
float float4[4]
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
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_inline
Definition: cuda/compat.h:34
#define tanf(x)
Definition: cuda/compat.h:104
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
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:93
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
ccl_device_inline Transform transform_translate(float3 t)
ccl_device_inline Transform transform_scale(float3 s)
ccl_device_inline float3 zero_float3()
Definition: math_float3.h:80
#define make_float4(x, y, z, w)
Definition: metal/compat.h:205
#define make_float3(x, y, z)
Definition: metal/compat.h:204
static unsigned c
Definition: RandGen.cpp:83
static unsigned a[3]
Definition: RandGen.cpp:78
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
ProjectionTransform(const Transform &tfm)
ccl_device_inline void print_float4(const char *label, const float4 &a)