Blender V5.3
gpu_shader_math_matrix_projection.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
9/* -------------------------------------------------------------------- */
12
19 float left, float right, float bottom, float top, float near_clip, float far_clip)
20{
21 float x_delta = right - left;
22 float y_delta = top - bottom;
23 float z_delta = far_clip - near_clip;
24
25 float4x4 mat = float4x4(1.0f);
26 if (x_delta != 0.0f && y_delta != 0.0f && z_delta != 0.0f) {
27 mat[0][0] = 2.0f / x_delta;
28 mat[3][0] = -(right + left) / x_delta;
29 mat[1][1] = 2.0f / y_delta;
30 mat[3][1] = -(top + bottom) / y_delta;
31 mat[2][2] = -2.0f / z_delta; /* NOTE: negate Z. */
32 mat[3][2] = -(far_clip + near_clip) / z_delta;
33 }
34 return mat;
35}
36
44 float left, float right, float bottom, float top, float near_clip, float far_clip)
45{
46 float x_delta = right - left;
47 float y_delta = top - bottom;
48 float z_delta = far_clip - near_clip;
49
50 float4x4 mat = float4x4(1.0f);
51 if (x_delta != 0.0f && y_delta != 0.0f && z_delta != 0.0f) {
52 mat[0][0] = near_clip * 2.0f / x_delta;
53 mat[1][1] = near_clip * 2.0f / y_delta;
54 mat[2][0] = (right + left) / x_delta; /* NOTE: negate Z. */
55 mat[2][1] = (top + bottom) / y_delta;
56 mat[2][2] = -(far_clip + near_clip) / z_delta;
57 mat[2][3] = -1.0f;
58 mat[3][2] = (-2.0f * near_clip * far_clip) / z_delta;
59 mat[3][3] = 0.0f;
60 }
61 return mat;
62}
63
71 float angle_right,
72 float angle_bottom,
73 float angle_top,
74 float near_clip,
75 float far_clip)
76{
78 tan(angle_left), tan(angle_right), tan(angle_bottom), tan(angle_top), near_clip, far_clip);
79 mat[0][0] /= near_clip;
80 mat[1][1] /= near_clip;
81 return mat;
82}
83
#define tan
float4x4 projection_perspective_fov(float angle_left, float angle_right, float angle_bottom, float angle_top, float near_clip, float far_clip)
Create a perspective projection matrix using OpenGL coordinate convention: Maps each axis range to [-...
float4x4 projection_orthographic(float left, float right, float bottom, float top, float near_clip, float far_clip)
Create an orthographic projection matrix using OpenGL coordinate convention: Maps each axis range to ...
float4x4 projection_perspective(float left, float right, float bottom, float top, float near_clip, float far_clip)
Create a perspective projection matrix using OpenGL coordinate convention: Maps each axis range to [-...
MatBase< float, 4, 4 > float4x4