Merge pull request #66898 from aaronfranke/proj-mat-columns

Rename Projection `matrix` to `columns`
This commit is contained in:
Rémi Verschelde 2022-10-05 08:35:26 +02:00
commit 3a2b0ab73d
25 changed files with 284 additions and 282 deletions

View File

@ -503,7 +503,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
ERR_FAIL_COND_V((size_t)len < sizeof(double) * 16, ERR_INVALID_DATA);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
val.matrix[i][j] = decode_double(&buf[(i * 4 + j) * sizeof(double)]);
val.columns[i][j] = decode_double(&buf[(i * 4 + j) * sizeof(double)]);
}
}
if (r_len) {
@ -513,7 +513,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
ERR_FAIL_COND_V((size_t)len < sizeof(float) * 16, ERR_INVALID_DATA);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
val.matrix[i][j] = decode_float(&buf[(i * 4 + j) * sizeof(float)]);
val.columns[i][j] = decode_float(&buf[(i * 4 + j) * sizeof(float)]);
}
}
@ -1450,7 +1450,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
Projection val = p_variant;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
memcpy(&buf[(i * 4 + j) * sizeof(real_t)], &val.matrix[i][j], sizeof(real_t));
memcpy(&buf[(i * 4 + j) * sizeof(real_t)], &val.columns[i][j], sizeof(real_t));
}
}
}

View File

@ -327,22 +327,22 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
} break;
case VARIANT_PROJECTION: {
Projection v;
v.matrix[0].x = f->get_real();
v.matrix[0].y = f->get_real();
v.matrix[0].z = f->get_real();
v.matrix[0].w = f->get_real();
v.matrix[1].x = f->get_real();
v.matrix[1].y = f->get_real();
v.matrix[1].z = f->get_real();
v.matrix[1].w = f->get_real();
v.matrix[2].x = f->get_real();
v.matrix[2].y = f->get_real();
v.matrix[2].z = f->get_real();
v.matrix[2].w = f->get_real();
v.matrix[3].x = f->get_real();
v.matrix[3].y = f->get_real();
v.matrix[3].z = f->get_real();
v.matrix[3].w = f->get_real();
v.columns[0].x = f->get_real();
v.columns[0].y = f->get_real();
v.columns[0].z = f->get_real();
v.columns[0].w = f->get_real();
v.columns[1].x = f->get_real();
v.columns[1].y = f->get_real();
v.columns[1].z = f->get_real();
v.columns[1].w = f->get_real();
v.columns[2].x = f->get_real();
v.columns[2].y = f->get_real();
v.columns[2].z = f->get_real();
v.columns[2].w = f->get_real();
v.columns[3].x = f->get_real();
v.columns[3].y = f->get_real();
v.columns[3].z = f->get_real();
v.columns[3].w = f->get_real();
r_v = v;
} break;
case VARIANT_COLOR: {
@ -1630,22 +1630,22 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V
case Variant::PROJECTION: {
f->store_32(VARIANT_PROJECTION);
Projection val = p_property;
f->store_real(val.matrix[0].x);
f->store_real(val.matrix[0].y);
f->store_real(val.matrix[0].z);
f->store_real(val.matrix[0].w);
f->store_real(val.matrix[1].x);
f->store_real(val.matrix[1].y);
f->store_real(val.matrix[1].z);
f->store_real(val.matrix[1].w);
f->store_real(val.matrix[2].x);
f->store_real(val.matrix[2].y);
f->store_real(val.matrix[2].z);
f->store_real(val.matrix[2].w);
f->store_real(val.matrix[3].x);
f->store_real(val.matrix[3].y);
f->store_real(val.matrix[3].z);
f->store_real(val.matrix[3].w);
f->store_real(val.columns[0].x);
f->store_real(val.columns[0].y);
f->store_real(val.columns[0].z);
f->store_real(val.columns[0].w);
f->store_real(val.columns[1].x);
f->store_real(val.columns[1].y);
f->store_real(val.columns[1].z);
f->store_real(val.columns[1].w);
f->store_real(val.columns[2].x);
f->store_real(val.columns[2].y);
f->store_real(val.columns[2].z);
f->store_real(val.columns[2].w);
f->store_real(val.columns[3].x);
f->store_real(val.columns[3].y);
f->store_real(val.columns[3].z);
f->store_real(val.columns[3].w);
} break;
case Variant::COLOR: {

View File

@ -186,25 +186,25 @@ class Delaunay3D {
Projection cm;
cm.matrix[0][0] = p_points[p_simplex.points[0]].x;
cm.matrix[0][1] = p_points[p_simplex.points[1]].x;
cm.matrix[0][2] = p_points[p_simplex.points[2]].x;
cm.matrix[0][3] = p_points[p_simplex.points[3]].x;
cm.columns[0][0] = p_points[p_simplex.points[0]].x;
cm.columns[0][1] = p_points[p_simplex.points[1]].x;
cm.columns[0][2] = p_points[p_simplex.points[2]].x;
cm.columns[0][3] = p_points[p_simplex.points[3]].x;
cm.matrix[1][0] = p_points[p_simplex.points[0]].y;
cm.matrix[1][1] = p_points[p_simplex.points[1]].y;
cm.matrix[1][2] = p_points[p_simplex.points[2]].y;
cm.matrix[1][3] = p_points[p_simplex.points[3]].y;
cm.columns[1][0] = p_points[p_simplex.points[0]].y;
cm.columns[1][1] = p_points[p_simplex.points[1]].y;
cm.columns[1][2] = p_points[p_simplex.points[2]].y;
cm.columns[1][3] = p_points[p_simplex.points[3]].y;
cm.matrix[2][0] = p_points[p_simplex.points[0]].z;
cm.matrix[2][1] = p_points[p_simplex.points[1]].z;
cm.matrix[2][2] = p_points[p_simplex.points[2]].z;
cm.matrix[2][3] = p_points[p_simplex.points[3]].z;
cm.columns[2][0] = p_points[p_simplex.points[0]].z;
cm.columns[2][1] = p_points[p_simplex.points[1]].z;
cm.columns[2][2] = p_points[p_simplex.points[2]].z;
cm.columns[2][3] = p_points[p_simplex.points[3]].z;
cm.matrix[3][0] = 1.0;
cm.matrix[3][1] = 1.0;
cm.matrix[3][2] = 1.0;
cm.matrix[3][3] = 1.0;
cm.columns[3][0] = 1.0;
cm.columns[3][1] = 1.0;
cm.columns[3][2] = 1.0;
cm.columns[3][3] = 1.0;
return ABS(cm.determinant()) <= CMP_EPSILON;
}

View File

@ -215,22 +215,22 @@ Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const
case Variant::PROJECTION: {
SETUP_TYPE(Projection)
/**/ TRY_TRANSFER_FIELD("xx", matrix[0].x)
else TRY_TRANSFER_FIELD("xy", matrix[0].y)
else TRY_TRANSFER_FIELD("xz", matrix[0].z)
else TRY_TRANSFER_FIELD("xw", matrix[0].w)
else TRY_TRANSFER_FIELD("yx", matrix[1].x)
else TRY_TRANSFER_FIELD("yy", matrix[1].y)
else TRY_TRANSFER_FIELD("yz", matrix[1].z)
else TRY_TRANSFER_FIELD("yw", matrix[1].w)
else TRY_TRANSFER_FIELD("zx", matrix[2].x)
else TRY_TRANSFER_FIELD("zy", matrix[2].y)
else TRY_TRANSFER_FIELD("zz", matrix[2].z)
else TRY_TRANSFER_FIELD("zw", matrix[2].w)
else TRY_TRANSFER_FIELD("xo", matrix[3].x)
else TRY_TRANSFER_FIELD("yo", matrix[3].y)
else TRY_TRANSFER_FIELD("zo", matrix[3].z)
else TRY_TRANSFER_FIELD("wo", matrix[3].w)
/**/ TRY_TRANSFER_FIELD("xx", columns[0].x)
else TRY_TRANSFER_FIELD("xy", columns[0].y)
else TRY_TRANSFER_FIELD("xz", columns[0].z)
else TRY_TRANSFER_FIELD("xw", columns[0].w)
else TRY_TRANSFER_FIELD("yx", columns[1].x)
else TRY_TRANSFER_FIELD("yy", columns[1].y)
else TRY_TRANSFER_FIELD("yz", columns[1].z)
else TRY_TRANSFER_FIELD("yw", columns[1].w)
else TRY_TRANSFER_FIELD("zx", columns[2].x)
else TRY_TRANSFER_FIELD("zy", columns[2].y)
else TRY_TRANSFER_FIELD("zz", columns[2].z)
else TRY_TRANSFER_FIELD("zw", columns[2].w)
else TRY_TRANSFER_FIELD("xo", columns[3].x)
else TRY_TRANSFER_FIELD("yo", columns[3].y)
else TRY_TRANSFER_FIELD("zo", columns[3].z)
else TRY_TRANSFER_FIELD("wo", columns[3].w)
return target;
}

View File

@ -38,24 +38,24 @@
#include "core/string/print_string.h"
float Projection::determinant() const {
return matrix[0][3] * matrix[1][2] * matrix[2][1] * matrix[3][0] - matrix[0][2] * matrix[1][3] * matrix[2][1] * matrix[3][0] -
matrix[0][3] * matrix[1][1] * matrix[2][2] * matrix[3][0] + matrix[0][1] * matrix[1][3] * matrix[2][2] * matrix[3][0] +
matrix[0][2] * matrix[1][1] * matrix[2][3] * matrix[3][0] - matrix[0][1] * matrix[1][2] * matrix[2][3] * matrix[3][0] -
matrix[0][3] * matrix[1][2] * matrix[2][0] * matrix[3][1] + matrix[0][2] * matrix[1][3] * matrix[2][0] * matrix[3][1] +
matrix[0][3] * matrix[1][0] * matrix[2][2] * matrix[3][1] - matrix[0][0] * matrix[1][3] * matrix[2][2] * matrix[3][1] -
matrix[0][2] * matrix[1][0] * matrix[2][3] * matrix[3][1] + matrix[0][0] * matrix[1][2] * matrix[2][3] * matrix[3][1] +
matrix[0][3] * matrix[1][1] * matrix[2][0] * matrix[3][2] - matrix[0][1] * matrix[1][3] * matrix[2][0] * matrix[3][2] -
matrix[0][3] * matrix[1][0] * matrix[2][1] * matrix[3][2] + matrix[0][0] * matrix[1][3] * matrix[2][1] * matrix[3][2] +
matrix[0][1] * matrix[1][0] * matrix[2][3] * matrix[3][2] - matrix[0][0] * matrix[1][1] * matrix[2][3] * matrix[3][2] -
matrix[0][2] * matrix[1][1] * matrix[2][0] * matrix[3][3] + matrix[0][1] * matrix[1][2] * matrix[2][0] * matrix[3][3] +
matrix[0][2] * matrix[1][0] * matrix[2][1] * matrix[3][3] - matrix[0][0] * matrix[1][2] * matrix[2][1] * matrix[3][3] -
matrix[0][1] * matrix[1][0] * matrix[2][2] * matrix[3][3] + matrix[0][0] * matrix[1][1] * matrix[2][2] * matrix[3][3];
return columns[0][3] * columns[1][2] * columns[2][1] * columns[3][0] - columns[0][2] * columns[1][3] * columns[2][1] * columns[3][0] -
columns[0][3] * columns[1][1] * columns[2][2] * columns[3][0] + columns[0][1] * columns[1][3] * columns[2][2] * columns[3][0] +
columns[0][2] * columns[1][1] * columns[2][3] * columns[3][0] - columns[0][1] * columns[1][2] * columns[2][3] * columns[3][0] -
columns[0][3] * columns[1][2] * columns[2][0] * columns[3][1] + columns[0][2] * columns[1][3] * columns[2][0] * columns[3][1] +
columns[0][3] * columns[1][0] * columns[2][2] * columns[3][1] - columns[0][0] * columns[1][3] * columns[2][2] * columns[3][1] -
columns[0][2] * columns[1][0] * columns[2][3] * columns[3][1] + columns[0][0] * columns[1][2] * columns[2][3] * columns[3][1] +
columns[0][3] * columns[1][1] * columns[2][0] * columns[3][2] - columns[0][1] * columns[1][3] * columns[2][0] * columns[3][2] -
columns[0][3] * columns[1][0] * columns[2][1] * columns[3][2] + columns[0][0] * columns[1][3] * columns[2][1] * columns[3][2] +
columns[0][1] * columns[1][0] * columns[2][3] * columns[3][2] - columns[0][0] * columns[1][1] * columns[2][3] * columns[3][2] -
columns[0][2] * columns[1][1] * columns[2][0] * columns[3][3] + columns[0][1] * columns[1][2] * columns[2][0] * columns[3][3] +
columns[0][2] * columns[1][0] * columns[2][1] * columns[3][3] - columns[0][0] * columns[1][2] * columns[2][1] * columns[3][3] -
columns[0][1] * columns[1][0] * columns[2][2] * columns[3][3] + columns[0][0] * columns[1][1] * columns[2][2] * columns[3][3];
}
void Projection::set_identity() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
matrix[i][j] = (i == j) ? 1 : 0;
columns[i][j] = (i == j) ? 1 : 0;
}
}
}
@ -63,7 +63,7 @@ void Projection::set_identity() {
void Projection::set_zero() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
matrix[i][j] = 0;
columns[i][j] = 0;
}
}
}
@ -71,26 +71,26 @@ void Projection::set_zero() {
Plane Projection::xform4(const Plane &p_vec4) const {
Plane ret;
ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d;
ret.normal.y = matrix[0][1] * p_vec4.normal.x + matrix[1][1] * p_vec4.normal.y + matrix[2][1] * p_vec4.normal.z + matrix[3][1] * p_vec4.d;
ret.normal.z = matrix[0][2] * p_vec4.normal.x + matrix[1][2] * p_vec4.normal.y + matrix[2][2] * p_vec4.normal.z + matrix[3][2] * p_vec4.d;
ret.d = matrix[0][3] * p_vec4.normal.x + matrix[1][3] * p_vec4.normal.y + matrix[2][3] * p_vec4.normal.z + matrix[3][3] * p_vec4.d;
ret.normal.x = columns[0][0] * p_vec4.normal.x + columns[1][0] * p_vec4.normal.y + columns[2][0] * p_vec4.normal.z + columns[3][0] * p_vec4.d;
ret.normal.y = columns[0][1] * p_vec4.normal.x + columns[1][1] * p_vec4.normal.y + columns[2][1] * p_vec4.normal.z + columns[3][1] * p_vec4.d;
ret.normal.z = columns[0][2] * p_vec4.normal.x + columns[1][2] * p_vec4.normal.y + columns[2][2] * p_vec4.normal.z + columns[3][2] * p_vec4.d;
ret.d = columns[0][3] * p_vec4.normal.x + columns[1][3] * p_vec4.normal.y + columns[2][3] * p_vec4.normal.z + columns[3][3] * p_vec4.d;
return ret;
}
Vector4 Projection::xform(const Vector4 &p_vec4) const {
return Vector4(
matrix[0][0] * p_vec4.x + matrix[1][0] * p_vec4.y + matrix[2][0] * p_vec4.z + matrix[3][0] * p_vec4.w,
matrix[0][1] * p_vec4.x + matrix[1][1] * p_vec4.y + matrix[2][1] * p_vec4.z + matrix[3][1] * p_vec4.w,
matrix[0][2] * p_vec4.x + matrix[1][2] * p_vec4.y + matrix[2][2] * p_vec4.z + matrix[3][2] * p_vec4.w,
matrix[0][3] * p_vec4.x + matrix[1][3] * p_vec4.y + matrix[2][3] * p_vec4.z + matrix[3][3] * p_vec4.w);
columns[0][0] * p_vec4.x + columns[1][0] * p_vec4.y + columns[2][0] * p_vec4.z + columns[3][0] * p_vec4.w,
columns[0][1] * p_vec4.x + columns[1][1] * p_vec4.y + columns[2][1] * p_vec4.z + columns[3][1] * p_vec4.w,
columns[0][2] * p_vec4.x + columns[1][2] * p_vec4.y + columns[2][2] * p_vec4.z + columns[3][2] * p_vec4.w,
columns[0][3] * p_vec4.x + columns[1][3] * p_vec4.y + columns[2][3] * p_vec4.z + columns[3][3] * p_vec4.w);
}
Vector4 Projection::xform_inv(const Vector4 &p_vec4) const {
return Vector4(
matrix[0][0] * p_vec4.x + matrix[0][1] * p_vec4.y + matrix[0][2] * p_vec4.z + matrix[0][3] * p_vec4.w,
matrix[1][0] * p_vec4.x + matrix[1][1] * p_vec4.y + matrix[1][2] * p_vec4.z + matrix[1][3] * p_vec4.w,
matrix[2][0] * p_vec4.x + matrix[2][1] * p_vec4.y + matrix[2][2] * p_vec4.z + matrix[2][3] * p_vec4.w,
matrix[3][0] * p_vec4.x + matrix[3][1] * p_vec4.y + matrix[3][2] * p_vec4.z + matrix[3][3] * p_vec4.w);
columns[0][0] * p_vec4.x + columns[0][1] * p_vec4.y + columns[0][2] * p_vec4.z + columns[0][3] * p_vec4.w,
columns[1][0] * p_vec4.x + columns[1][1] * p_vec4.y + columns[1][2] * p_vec4.z + columns[1][3] * p_vec4.w,
columns[2][0] * p_vec4.x + columns[2][1] * p_vec4.y + columns[2][2] * p_vec4.z + columns[2][3] * p_vec4.w,
columns[3][0] * p_vec4.x + columns[3][1] * p_vec4.y + columns[3][2] * p_vec4.z + columns[3][3] * p_vec4.w);
}
void Projection::adjust_perspective_znear(real_t p_new_znear) {
@ -98,8 +98,8 @@ void Projection::adjust_perspective_znear(real_t p_new_znear) {
real_t znear = p_new_znear;
real_t deltaZ = zfar - znear;
matrix[2][2] = -(zfar + znear) / deltaZ;
matrix[3][2] = -2 * znear * zfar / deltaZ;
columns[2][2] = -(zfar + znear) / deltaZ;
columns[3][2] = -2 * znear * zfar / deltaZ;
}
Projection Projection::create_depth_correction(bool p_flip_y) {
@ -169,7 +169,7 @@ Projection Projection::perspective_znear_adjusted(real_t p_new_znear) const {
}
Plane Projection::get_projection_plane(Planes p_plane) const {
const real_t *matrix = (const real_t *)this->matrix;
const real_t *matrix = (const real_t *)this->columns;
switch (p_plane) {
case PLANE_NEAR: {
@ -267,12 +267,12 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t
set_identity();
matrix[0][0] = cotangent / p_aspect;
matrix[1][1] = cotangent;
matrix[2][2] = -(p_z_far + p_z_near) / deltaZ;
matrix[2][3] = -1;
matrix[3][2] = -2 * p_z_near * p_z_far / deltaZ;
matrix[3][3] = 0;
columns[0][0] = cotangent / p_aspect;
columns[1][1] = cotangent;
columns[2][2] = -(p_z_far + p_z_near) / deltaZ;
columns[2][3] = -1;
columns[3][2] = -2 * p_z_near * p_z_far / deltaZ;
columns[3][3] = 0;
}
void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist) {
@ -309,7 +309,7 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t
// translate matrix by (modeltranslation, 0.0, 0.0)
Projection cm;
cm.set_identity();
cm.matrix[3][0] = modeltranslation;
cm.columns[3][0] = modeltranslation;
*this = *this * cm;
}
@ -344,13 +344,13 @@ void Projection::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_di
void Projection::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
set_identity();
matrix[0][0] = 2.0 / (p_right - p_left);
matrix[3][0] = -((p_right + p_left) / (p_right - p_left));
matrix[1][1] = 2.0 / (p_top - p_bottom);
matrix[3][1] = -((p_top + p_bottom) / (p_top - p_bottom));
matrix[2][2] = -2.0 / (p_zfar - p_znear);
matrix[3][2] = -((p_zfar + p_znear) / (p_zfar - p_znear));
matrix[3][3] = 1.0;
columns[0][0] = 2.0 / (p_right - p_left);
columns[3][0] = -((p_right + p_left) / (p_right - p_left));
columns[1][1] = 2.0 / (p_top - p_bottom);
columns[3][1] = -((p_top + p_bottom) / (p_top - p_bottom));
columns[2][2] = -2.0 / (p_zfar - p_znear);
columns[3][2] = -((p_zfar + p_znear) / (p_zfar - p_znear));
columns[3][3] = 1.0;
}
void Projection::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
@ -366,7 +366,7 @@ void Projection::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, rea
ERR_FAIL_COND(p_top <= p_bottom);
ERR_FAIL_COND(p_far <= p_near);
real_t *te = &matrix[0][0];
real_t *te = &columns[0][0];
real_t x = 2 * p_near / (p_right - p_left);
real_t y = 2 * p_near / (p_top - p_bottom);
@ -402,7 +402,7 @@ void Projection::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, r
}
real_t Projection::get_z_far() const {
const real_t *matrix = (const real_t *)this->matrix;
const real_t *matrix = (const real_t *)this->columns;
Plane new_plane = Plane(matrix[3] - matrix[2],
matrix[7] - matrix[6],
matrix[11] - matrix[10],
@ -415,7 +415,7 @@ real_t Projection::get_z_far() const {
}
real_t Projection::get_z_near() const {
const real_t *matrix = (const real_t *)this->matrix;
const real_t *matrix = (const real_t *)this->columns;
Plane new_plane = Plane(matrix[3] + matrix[2],
matrix[7] + matrix[6],
matrix[11] + matrix[10],
@ -426,7 +426,7 @@ real_t Projection::get_z_near() const {
}
Vector2 Projection::get_viewport_half_extents() const {
const real_t *matrix = (const real_t *)this->matrix;
const real_t *matrix = (const real_t *)this->columns;
///////--- Near Plane ---///////
Plane near_plane = Plane(matrix[3] + matrix[2],
matrix[7] + matrix[6],
@ -454,7 +454,7 @@ Vector2 Projection::get_viewport_half_extents() const {
}
Vector2 Projection::get_far_plane_half_extents() const {
const real_t *matrix = (const real_t *)this->matrix;
const real_t *matrix = (const real_t *)this->columns;
///////--- Far Plane ---///////
Plane far_plane = Plane(matrix[3] - matrix[2],
matrix[7] - matrix[6],
@ -514,7 +514,7 @@ Vector<Plane> Projection::get_projection_planes(const Transform3D &p_transform)
Vector<Plane> planes;
planes.resize(6);
const real_t *matrix = (const real_t *)this->matrix;
const real_t *matrix = (const real_t *)this->columns;
Plane new_plane;
@ -601,15 +601,15 @@ void Projection::invert() {
real_t determinant = 1.0f;
for (k = 0; k < 4; k++) {
/** Locate k'th pivot element **/
pvt_val = matrix[k][k]; /** Initialize for search **/
pvt_val = columns[k][k]; /** Initialize for search **/
pvt_i[k] = k;
pvt_j[k] = k;
for (i = k; i < 4; i++) {
for (j = k; j < 4; j++) {
if (Math::abs(matrix[i][j]) > Math::abs(pvt_val)) {
if (Math::abs(columns[i][j]) > Math::abs(pvt_val)) {
pvt_i[k] = i;
pvt_j[k] = j;
pvt_val = matrix[i][j];
pvt_val = columns[i][j];
}
}
}
@ -624,9 +624,9 @@ void Projection::invert() {
i = pvt_i[k];
if (i != k) { /** If rows are different **/
for (j = 0; j < 4; j++) {
hold = -matrix[k][j];
matrix[k][j] = matrix[i][j];
matrix[i][j] = hold;
hold = -columns[k][j];
columns[k][j] = columns[i][j];
columns[i][j] = hold;
}
}
@ -634,25 +634,25 @@ void Projection::invert() {
j = pvt_j[k];
if (j != k) { /** If columns are different **/
for (i = 0; i < 4; i++) {
hold = -matrix[i][k];
matrix[i][k] = matrix[i][j];
matrix[i][j] = hold;
hold = -columns[i][k];
columns[i][k] = columns[i][j];
columns[i][j] = hold;
}
}
/** Divide column by minus pivot value **/
for (i = 0; i < 4; i++) {
if (i != k) {
matrix[i][k] /= (-pvt_val);
columns[i][k] /= (-pvt_val);
}
}
/** Reduce the matrix **/
for (i = 0; i < 4; i++) {
hold = matrix[i][k];
hold = columns[i][k];
for (j = 0; j < 4; j++) {
if (i != k && j != k) {
matrix[i][j] += hold * matrix[k][j];
columns[i][j] += hold * columns[k][j];
}
}
}
@ -660,12 +660,12 @@ void Projection::invert() {
/** Divide row by pivot **/
for (j = 0; j < 4; j++) {
if (j != k) {
matrix[k][j] /= pvt_val;
columns[k][j] /= pvt_val;
}
}
/** Replace pivot by reciprocal (at last we can touch it). **/
matrix[k][k] = 1.0 / pvt_val;
columns[k][k] = 1.0 / pvt_val;
}
/* That was most of the work, one final pass of row/column interchange */
@ -674,18 +674,18 @@ void Projection::invert() {
i = pvt_j[k]; /* Rows to swap correspond to pivot COLUMN */
if (i != k) { /* If rows are different */
for (j = 0; j < 4; j++) {
hold = matrix[k][j];
matrix[k][j] = -matrix[i][j];
matrix[i][j] = hold;
hold = columns[k][j];
columns[k][j] = -columns[i][j];
columns[i][j] = hold;
}
}
j = pvt_i[k]; /* Columns to swap correspond to pivot ROW */
if (j != k) { /* If columns are different */
for (i = 0; i < 4; i++) {
hold = matrix[i][k];
matrix[i][k] = -matrix[i][j];
matrix[i][j] = hold;
hold = columns[i][k];
columns[i][k] = -columns[i][j];
columns[i][j] = hold;
}
}
}
@ -693,7 +693,7 @@ void Projection::invert() {
void Projection::flip_y() {
for (int i = 0; i < 4; i++) {
matrix[1][i] = -matrix[1][i];
columns[1][i] = -columns[1][i];
}
}
@ -708,9 +708,9 @@ Projection Projection::operator*(const Projection &p_matrix) const {
for (int i = 0; i < 4; i++) {
real_t ab = 0;
for (int k = 0; k < 4; k++) {
ab += matrix[k][i] * p_matrix.matrix[j][k];
ab += columns[k][i] * p_matrix.columns[j][k];
}
new_matrix.matrix[j][i] = ab;
new_matrix.columns[j][i] = ab;
}
}
@ -718,7 +718,7 @@ Projection Projection::operator*(const Projection &p_matrix) const {
}
void Projection::set_depth_correction(bool p_flip_y) {
real_t *m = &matrix[0][0];
real_t *m = &columns[0][0];
m[0] = 1;
m[1] = 0.0;
@ -739,7 +739,7 @@ void Projection::set_depth_correction(bool p_flip_y) {
}
void Projection::set_light_bias() {
real_t *m = &matrix[0][0];
real_t *m = &columns[0][0];
m[0] = 0.5;
m[1] = 0.0;
@ -760,7 +760,7 @@ void Projection::set_light_bias() {
}
void Projection::set_light_atlas_rect(const Rect2 &p_rect) {
real_t *m = &matrix[0][0];
real_t *m = &columns[0][0];
m[0] = p_rect.size.width;
m[1] = 0.0;
@ -784,7 +784,7 @@ Projection::operator String() const {
String str;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
str += String((j > 0) ? ", " : "\n") + rtos(matrix[i][j]);
str += String((j > 0) ? ", " : "\n") + rtos(columns[i][j]);
}
}
@ -803,11 +803,11 @@ int Projection::get_pixels_per_meter(int p_for_pixel_width) const {
}
bool Projection::is_orthogonal() const {
return matrix[3][3] == 1.0;
return columns[3][3] == 1.0;
}
real_t Projection::get_fov() const {
const real_t *matrix = (const real_t *)this->matrix;
const real_t *matrix = (const real_t *)this->columns;
Plane right_plane = Plane(matrix[3] - matrix[0],
matrix[7] - matrix[4],
@ -842,44 +842,44 @@ float Projection::get_lod_multiplier() const {
}
void Projection::make_scale(const Vector3 &p_scale) {
set_identity();
matrix[0][0] = p_scale.x;
matrix[1][1] = p_scale.y;
matrix[2][2] = p_scale.z;
columns[0][0] = p_scale.x;
columns[1][1] = p_scale.y;
columns[2][2] = p_scale.z;
}
void Projection::scale_translate_to_fit(const AABB &p_aabb) {
Vector3 min = p_aabb.position;
Vector3 max = p_aabb.position + p_aabb.size;
matrix[0][0] = 2 / (max.x - min.x);
matrix[1][0] = 0;
matrix[2][0] = 0;
matrix[3][0] = -(max.x + min.x) / (max.x - min.x);
columns[0][0] = 2 / (max.x - min.x);
columns[1][0] = 0;
columns[2][0] = 0;
columns[3][0] = -(max.x + min.x) / (max.x - min.x);
matrix[0][1] = 0;
matrix[1][1] = 2 / (max.y - min.y);
matrix[2][1] = 0;
matrix[3][1] = -(max.y + min.y) / (max.y - min.y);
columns[0][1] = 0;
columns[1][1] = 2 / (max.y - min.y);
columns[2][1] = 0;
columns[3][1] = -(max.y + min.y) / (max.y - min.y);
matrix[0][2] = 0;
matrix[1][2] = 0;
matrix[2][2] = 2 / (max.z - min.z);
matrix[3][2] = -(max.z + min.z) / (max.z - min.z);
columns[0][2] = 0;
columns[1][2] = 0;
columns[2][2] = 2 / (max.z - min.z);
columns[3][2] = -(max.z + min.z) / (max.z - min.z);
matrix[0][3] = 0;
matrix[1][3] = 0;
matrix[2][3] = 0;
matrix[3][3] = 1;
columns[0][3] = 0;
columns[1][3] = 0;
columns[2][3] = 0;
columns[3][3] = 1;
}
void Projection::add_jitter_offset(const Vector2 &p_offset) {
matrix[3][0] += p_offset.x;
matrix[3][1] += p_offset.y;
columns[3][0] += p_offset.x;
columns[3][1] += p_offset.y;
}
Projection::operator Transform3D() const {
Transform3D tr;
const real_t *m = &matrix[0][0];
const real_t *m = &columns[0][0];
tr.basis.rows[0][0] = m[0];
tr.basis.rows[1][0] = m[1];
@ -899,15 +899,17 @@ Projection::operator Transform3D() const {
return tr;
}
Projection::Projection(const Vector4 &p_x, const Vector4 &p_y, const Vector4 &p_z, const Vector4 &p_w) {
matrix[0] = p_x;
matrix[1] = p_y;
matrix[2] = p_z;
matrix[3] = p_w;
columns[0] = p_x;
columns[1] = p_y;
columns[2] = p_z;
columns[3] = p_w;
}
Projection::Projection(const Transform3D &p_transform) {
const Transform3D &tr = p_transform;
real_t *m = &matrix[0][0];
real_t *m = &columns[0][0];
m[0] = tr.basis.rows[0][0];
m[1] = tr.basis.rows[1][0];

View File

@ -52,16 +52,16 @@ struct Projection {
PLANE_BOTTOM
};
Vector4 matrix[4];
Vector4 columns[4];
_FORCE_INLINE_ const Vector4 &operator[](const int p_axis) const {
DEV_ASSERT((unsigned int)p_axis < 4);
return matrix[p_axis];
return columns[p_axis];
}
_FORCE_INLINE_ Vector4 &operator[](const int p_axis) {
DEV_ASSERT((unsigned int)p_axis < 4);
return matrix[p_axis];
return columns[p_axis];
}
float determinant() const;
@ -135,7 +135,7 @@ struct Projection {
bool operator==(const Projection &p_cam) const {
for (uint32_t i = 0; i < 4; i++) {
for (uint32_t j = 0; j < 4; j++) {
if (matrix[i][j] != p_cam.matrix[i][j]) {
if (columns[i][j] != p_cam.columns[i][j]) {
return false;
}
}
@ -157,10 +157,10 @@ struct Projection {
Vector3 Projection::xform(const Vector3 &p_vec3) const {
Vector3 ret;
ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0];
ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1];
ret.z = matrix[0][2] * p_vec3.x + matrix[1][2] * p_vec3.y + matrix[2][2] * p_vec3.z + matrix[3][2];
real_t w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3];
ret.x = columns[0][0] * p_vec3.x + columns[1][0] * p_vec3.y + columns[2][0] * p_vec3.z + columns[3][0];
ret.y = columns[0][1] * p_vec3.x + columns[1][1] * p_vec3.y + columns[2][1] * p_vec3.z + columns[3][1];
ret.z = columns[0][2] * p_vec3.x + columns[1][2] * p_vec3.y + columns[2][2] * p_vec3.z + columns[3][2];
real_t w = columns[0][3] * p_vec3.x + columns[1][3] * p_vec3.y + columns[2][3] * p_vec3.z + columns[3][3];
return ret / w;
}

View File

@ -3123,22 +3123,22 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
case PROJECTION: {
uint32_t h = HASH_MURMUR3_SEED;
const Projection &t = *_data._projection;
h = hash_murmur3_one_real(t.matrix[0].x, h);
h = hash_murmur3_one_real(t.matrix[0].y, h);
h = hash_murmur3_one_real(t.matrix[0].z, h);
h = hash_murmur3_one_real(t.matrix[0].w, h);
h = hash_murmur3_one_real(t.matrix[1].x, h);
h = hash_murmur3_one_real(t.matrix[1].y, h);
h = hash_murmur3_one_real(t.matrix[1].z, h);
h = hash_murmur3_one_real(t.matrix[1].w, h);
h = hash_murmur3_one_real(t.matrix[2].x, h);
h = hash_murmur3_one_real(t.matrix[2].y, h);
h = hash_murmur3_one_real(t.matrix[2].z, h);
h = hash_murmur3_one_real(t.matrix[2].w, h);
h = hash_murmur3_one_real(t.matrix[3].x, h);
h = hash_murmur3_one_real(t.matrix[3].y, h);
h = hash_murmur3_one_real(t.matrix[3].z, h);
h = hash_murmur3_one_real(t.matrix[3].w, h);
h = hash_murmur3_one_real(t.columns[0].x, h);
h = hash_murmur3_one_real(t.columns[0].y, h);
h = hash_murmur3_one_real(t.columns[0].z, h);
h = hash_murmur3_one_real(t.columns[0].w, h);
h = hash_murmur3_one_real(t.columns[1].x, h);
h = hash_murmur3_one_real(t.columns[1].y, h);
h = hash_murmur3_one_real(t.columns[1].z, h);
h = hash_murmur3_one_real(t.columns[1].w, h);
h = hash_murmur3_one_real(t.columns[2].x, h);
h = hash_murmur3_one_real(t.columns[2].y, h);
h = hash_murmur3_one_real(t.columns[2].z, h);
h = hash_murmur3_one_real(t.columns[2].w, h);
h = hash_murmur3_one_real(t.columns[3].x, h);
h = hash_murmur3_one_real(t.columns[3].y, h);
h = hash_murmur3_one_real(t.columns[3].z, h);
h = hash_murmur3_one_real(t.columns[3].w, h);
return hash_fmix32(h);
} break;
// misc types
@ -3509,7 +3509,7 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const
const Projection *r = p_variant._data._projection;
for (int i = 0; i < 4; i++) {
if (!(hash_compare_vector4(l->matrix[i], r->matrix[i]))) {
if (!(hash_compare_vector4(l->columns[i], r->columns[i]))) {
return false;
}
}

View File

@ -1651,7 +1651,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
if (i != 0 || j != 0) {
s += ", ";
}
s += rtos_fix(t.matrix[i][j]);
s += rtos_fix(t.columns[i][j]);
}
}

View File

@ -826,7 +826,7 @@ INDEXED_SETGET_STRUCT_BULTIN_NUMERIC(Color, double, float, 4)
INDEXED_SETGET_STRUCT_BULTIN_ACCESSOR(Transform2D, Vector2, .columns, 3)
INDEXED_SETGET_STRUCT_BULTIN_FUNC(Basis, Vector3, set_column, get_column, 3)
INDEXED_SETGET_STRUCT_BULTIN_ACCESSOR(Projection, Vector4, .matrix, 4)
INDEXED_SETGET_STRUCT_BULTIN_ACCESSOR(Projection, Vector4, .columns, 4)
INDEXED_SETGET_STRUCT_TYPED_NUMERIC(PackedByteArray, int64_t, uint8_t)
INDEXED_SETGET_STRUCT_TYPED_NUMERIC(PackedInt32Array, int64_t, int32_t)

View File

@ -325,10 +325,10 @@ SETGET_STRUCT_FUNC_INDEX(Basis, Vector3, z, set_column, get_column, 2)
SETGET_STRUCT(Transform3D, Basis, basis)
SETGET_STRUCT(Transform3D, Vector3, origin)
SETGET_STRUCT_CUSTOM(Projection, Vector4, x, matrix[0])
SETGET_STRUCT_CUSTOM(Projection, Vector4, y, matrix[1])
SETGET_STRUCT_CUSTOM(Projection, Vector4, z, matrix[2])
SETGET_STRUCT_CUSTOM(Projection, Vector4, w, matrix[3])
SETGET_STRUCT_CUSTOM(Projection, Vector4, x, columns[0])
SETGET_STRUCT_CUSTOM(Projection, Vector4, y, columns[1])
SETGET_STRUCT_CUSTOM(Projection, Vector4, z, columns[2])
SETGET_STRUCT_CUSTOM(Projection, Vector4, w, columns[3])
SETGET_NUMBER_STRUCT(Color, double, r)
SETGET_NUMBER_STRUCT(Color, double, g)

View File

@ -753,7 +753,7 @@ void RasterizerSceneGLES3::_draw_sky(RID p_env, const Projection &p_projection,
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_bind_shader(shader_data->version, SkyShaderGLES3::MODE_BACKGROUND);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::ORIENTATION, sky_transform, shader_data->version, SkyShaderGLES3::MODE_BACKGROUND);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::PROJECTION, camera.matrix[2][0], camera.matrix[0][0], camera.matrix[2][1], camera.matrix[1][1], shader_data->version, SkyShaderGLES3::MODE_BACKGROUND);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::PROJECTION, camera.columns[2][0], camera.columns[0][0], camera.columns[2][1], camera.columns[1][1], shader_data->version, SkyShaderGLES3::MODE_BACKGROUND);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::POSITION, p_transform.origin, shader_data->version, SkyShaderGLES3::MODE_BACKGROUND);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::TIME, time, shader_data->version, SkyShaderGLES3::MODE_BACKGROUND);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::LUMINANCE_MULTIPLIER, p_luminance_multiplier, shader_data->version, SkyShaderGLES3::MODE_BACKGROUND);
@ -854,7 +854,7 @@ void RasterizerSceneGLES3::_update_sky_radiance(RID p_env, const Projection &p_p
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::POSITION, p_transform.origin, shader_data->version, SkyShaderGLES3::MODE_CUBEMAP);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::TIME, time, shader_data->version, SkyShaderGLES3::MODE_CUBEMAP);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::PROJECTION, cm.matrix[2][0], cm.matrix[0][0], cm.matrix[2][1], cm.matrix[1][1], shader_data->version, SkyShaderGLES3::MODE_CUBEMAP);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::PROJECTION, cm.columns[2][0], cm.columns[0][0], cm.columns[2][1], cm.columns[1][1], shader_data->version, SkyShaderGLES3::MODE_CUBEMAP);
GLES3::MaterialStorage::get_singleton()->shaders.sky_shader.version_set_uniform(SkyShaderGLES3::LUMINANCE_MULTIPLIER, p_luminance_multiplier, shader_data->version, SkyShaderGLES3::MODE_CUBEMAP);
glBindVertexArray(sky_globals.screen_triangle_array);

View File

@ -714,7 +714,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
Projection v = value;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
gui[i * 4 + j] = v.matrix[i][j];
gui[i * 4 + j] = v.columns[i][j];
}
}
}

View File

@ -494,7 +494,7 @@ public:
static _FORCE_INLINE_ void store_camera(const Projection &p_mtx, float *p_array) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
p_array[i * 4 + j] = p_mtx.matrix[i][j];
p_array[i * 4 + j] = p_mtx.columns[i][j];
}
}
}

View File

@ -3393,22 +3393,22 @@ void EditorPropertyProjection::_value_changed(double val, const String &p_name)
}
Projection p;
p.matrix[0][0] = spin[0]->get_value();
p.matrix[0][1] = spin[1]->get_value();
p.matrix[0][2] = spin[2]->get_value();
p.matrix[0][3] = spin[3]->get_value();
p.matrix[1][0] = spin[4]->get_value();
p.matrix[1][1] = spin[5]->get_value();
p.matrix[1][2] = spin[6]->get_value();
p.matrix[1][3] = spin[7]->get_value();
p.matrix[2][0] = spin[8]->get_value();
p.matrix[2][1] = spin[9]->get_value();
p.matrix[2][2] = spin[10]->get_value();
p.matrix[2][3] = spin[11]->get_value();
p.matrix[3][0] = spin[12]->get_value();
p.matrix[3][1] = spin[13]->get_value();
p.matrix[3][2] = spin[14]->get_value();
p.matrix[3][3] = spin[15]->get_value();
p.columns[0][0] = spin[0]->get_value();
p.columns[0][1] = spin[1]->get_value();
p.columns[0][2] = spin[2]->get_value();
p.columns[0][3] = spin[3]->get_value();
p.columns[1][0] = spin[4]->get_value();
p.columns[1][1] = spin[5]->get_value();
p.columns[1][2] = spin[6]->get_value();
p.columns[1][3] = spin[7]->get_value();
p.columns[2][0] = spin[8]->get_value();
p.columns[2][1] = spin[9]->get_value();
p.columns[2][2] = spin[10]->get_value();
p.columns[2][3] = spin[11]->get_value();
p.columns[3][0] = spin[12]->get_value();
p.columns[3][1] = spin[13]->get_value();
p.columns[3][2] = spin[14]->get_value();
p.columns[3][3] = spin[15]->get_value();
emit_changed(get_edited_property(), p, p_name);
}
@ -3419,22 +3419,22 @@ void EditorPropertyProjection::update_property() {
void EditorPropertyProjection::update_using_transform(Projection p_transform) {
setting = true;
spin[0]->set_value(p_transform.matrix[0][0]);
spin[1]->set_value(p_transform.matrix[0][1]);
spin[2]->set_value(p_transform.matrix[0][2]);
spin[3]->set_value(p_transform.matrix[0][3]);
spin[4]->set_value(p_transform.matrix[1][0]);
spin[5]->set_value(p_transform.matrix[1][1]);
spin[6]->set_value(p_transform.matrix[1][2]);
spin[7]->set_value(p_transform.matrix[1][3]);
spin[8]->set_value(p_transform.matrix[2][0]);
spin[9]->set_value(p_transform.matrix[2][1]);
spin[10]->set_value(p_transform.matrix[2][2]);
spin[11]->set_value(p_transform.matrix[2][3]);
spin[12]->set_value(p_transform.matrix[3][0]);
spin[13]->set_value(p_transform.matrix[3][1]);
spin[14]->set_value(p_transform.matrix[3][2]);
spin[15]->set_value(p_transform.matrix[3][3]);
spin[0]->set_value(p_transform.columns[0][0]);
spin[1]->set_value(p_transform.columns[0][1]);
spin[2]->set_value(p_transform.columns[0][2]);
spin[3]->set_value(p_transform.columns[0][3]);
spin[4]->set_value(p_transform.columns[1][0]);
spin[5]->set_value(p_transform.columns[1][1]);
spin[6]->set_value(p_transform.columns[1][2]);
spin[7]->set_value(p_transform.columns[1][3]);
spin[8]->set_value(p_transform.columns[2][0]);
spin[9]->set_value(p_transform.columns[2][1]);
spin[10]->set_value(p_transform.columns[2][2]);
spin[11]->set_value(p_transform.columns[2][3]);
spin[12]->set_value(p_transform.columns[3][0]);
spin[13]->set_value(p_transform.columns[3][1]);
spin[14]->set_value(p_transform.columns[3][2]);
spin[15]->set_value(p_transform.columns[3][3]);
setting = false;
}

View File

@ -436,7 +436,7 @@ def build_gles3_header(filename: str, include: str, class_suffix: str, header_da
)
fd.write(
"""_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Projection& p_matrix,RID p_version,ShaderVariant p_variant"""
"""_FORCE_INLINE_ void version_set_uniform(Uniforms p_uniform, const Projection& p_matrix, RID p_version, ShaderVariant p_variant"""
+ defvariant
+ """,uint64_t p_specialization="""
+ str(defspec)
@ -444,13 +444,13 @@ def build_gles3_header(filename: str, include: str, class_suffix: str, header_da
GLfloat matrix[16];
for (int i=0;i<4;i++) {
for (int j=0;j<4;j++) {
matrix[i*4+j]=p_matrix.matrix[i][j];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
matrix[i * 4 + j] = p_matrix.columns[i][j];
}
}
glUniformMatrix4fv(version_get_uniform(p_uniform,p_version,p_variant,p_specialization),1,false,matrix);
glUniformMatrix4fv(version_get_uniform(p_uniform, p_version, p_variant, p_specialization), 1, false, matrix);
}"""
)

View File

@ -3326,11 +3326,11 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;
case Variant::PROJECTION: {
Projection transform = p_val.operator Projection();
if (transform == Projection()) {
Projection projection = p_val.operator Projection();
if (projection == Projection()) {
r_iarg.default_argument = "Projection.Identity";
} else {
r_iarg.default_argument = "new Projection(new Vector4" + transform.matrix[0].operator String() + ", new Vector4" + transform.matrix[1].operator String() + ", new Vector4" + transform.matrix[2].operator String() + ", new Vector4" + transform.matrix[3].operator String() + ")";
r_iarg.default_argument = "new Projection(new Vector4" + projection.columns[0].operator String() + ", new Vector4" + projection.columns[1].operator String() + ", new Vector4" + projection.columns[2].operator String() + ", new Vector4" + projection.columns[3].operator String() + ")";
}
r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL;
} break;

View File

@ -382,7 +382,7 @@ bool OpenXRVulkanExtension::create_projection_fov(const XrFovf p_fov, double p_z
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 4; i++) {
r_camera_matrix.matrix[j][i] = matrix.m[j * 4 + i];
r_camera_matrix.columns[j][i] = matrix.m[j * 4 + i];
}
}

View File

@ -388,15 +388,15 @@ Projection WebXRInterfaceJS::get_projection_for_view(uint32_t p_view, double p_a
int k = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
eye.matrix[i][j] = js_matrix[k++];
eye.columns[i][j] = js_matrix[k++];
}
}
free(js_matrix);
// Copied from godot_oculus_mobile's ovr_mobile_session.cpp
eye.matrix[2][2] = -(p_z_far + p_z_near) / (p_z_far - p_z_near);
eye.matrix[3][2] = -(2.0f * p_z_far * p_z_near) / (p_z_far - p_z_near);
eye.columns[2][2] = -(p_z_far + p_z_near) / (p_z_far - p_z_near);
eye.columns[3][2] = -(2.0f * p_z_far * p_z_near) / (p_z_far - p_z_near);
return eye;
}

View File

@ -43,7 +43,7 @@ SSEffects *SSEffects::singleton = nullptr;
static _FORCE_INLINE_ void store_camera(const Projection &p_mtx, float *p_array) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
p_array[i * 4 + j] = p_mtx.matrix[i][j];
p_array[i * 4 + j] = p_mtx.columns[i][j];
}
}
}
@ -488,8 +488,8 @@ void SSEffects::downsample_depth(RID p_depth_buffer, const Vector<RID> &p_depth_
ss_effects.downsample_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, ss_effects.downsample_shader.version_get_shader(ss_effects.downsample_shader_version, use_full_mips ? 6 : 2), 2);
}
float depth_linearize_mul = -p_projection.matrix[3][2];
float depth_linearize_add = p_projection.matrix[2][2];
float depth_linearize_mul = -p_projection.columns[3][2];
float depth_linearize_add = p_projection.columns[2][2];
if (depth_linearize_mul * depth_linearize_add < 0) {
depth_linearize_add = -depth_linearize_add;
}
@ -713,8 +713,8 @@ void SSEffects::screen_space_indirect_lighting(SSILRenderBuffers &p_ssil_buffers
ssil.gather_push_constant.half_screen_pixel_size[0] = 1.0 / p_ssil_buffers.buffer_width;
ssil.gather_push_constant.half_screen_pixel_size[1] = 1.0 / p_ssil_buffers.buffer_height;
float tan_half_fov_x = 1.0 / p_projection.matrix[0][0];
float tan_half_fov_y = 1.0 / p_projection.matrix[1][1];
float tan_half_fov_x = 1.0 / p_projection.columns[0][0];
float tan_half_fov_y = 1.0 / p_projection.columns[1][1];
ssil.gather_push_constant.NDC_to_view_mul[0] = tan_half_fov_x * 2.0;
ssil.gather_push_constant.NDC_to_view_mul[1] = tan_half_fov_y * -2.0;
ssil.gather_push_constant.NDC_to_view_add[0] = tan_half_fov_x * -1.0;
@ -1164,8 +1164,8 @@ void SSEffects::generate_ssao(SSAORenderBuffers &p_ssao_buffers, RID p_normal_bu
ssao.gather_push_constant.half_screen_pixel_size[0] = 1.0 / p_ssao_buffers.buffer_width;
ssao.gather_push_constant.half_screen_pixel_size[1] = 1.0 / p_ssao_buffers.buffer_height;
float tan_half_fov_x = 1.0 / p_projection.matrix[0][0];
float tan_half_fov_y = 1.0 / p_projection.matrix[1][1];
float tan_half_fov_x = 1.0 / p_projection.columns[0][0];
float tan_half_fov_y = 1.0 / p_projection.columns[1][1];
ssao.gather_push_constant.NDC_to_view_mul[0] = tan_half_fov_x * 2.0;
ssao.gather_push_constant.NDC_to_view_mul[1] = tan_half_fov_y * -2.0;
ssao.gather_push_constant.NDC_to_view_add[0] = tan_half_fov_x * -1.0;
@ -1611,10 +1611,10 @@ void SSEffects::screen_space_reflection(SSRRenderBuffers &p_ssr_buffers, const R
push_constant.num_steps = p_max_steps;
push_constant.depth_tolerance = p_tolerance;
push_constant.use_half_res = true;
push_constant.proj_info[0] = -2.0f / (p_screen_size.width * p_projections[v].matrix[0][0]);
push_constant.proj_info[1] = -2.0f / (p_screen_size.height * p_projections[v].matrix[1][1]);
push_constant.proj_info[2] = (1.0f - p_projections[v].matrix[0][2]) / p_projections[v].matrix[0][0];
push_constant.proj_info[3] = (1.0f + p_projections[v].matrix[1][2]) / p_projections[v].matrix[1][1];
push_constant.proj_info[0] = -2.0f / (p_screen_size.width * p_projections[v].columns[0][0]);
push_constant.proj_info[1] = -2.0f / (p_screen_size.height * p_projections[v].columns[1][1]);
push_constant.proj_info[2] = (1.0f - p_projections[v].columns[0][2]) / p_projections[v].columns[0][0];
push_constant.proj_info[3] = (1.0f + p_projections[v].columns[1][2]) / p_projections[v].columns[1][1];
ScreenSpaceReflectionMode mode = (ssr_roughness_quality != RS::ENV_SSR_ROUGHNESS_QUALITY_DISABLED) ? SCREEN_SPACE_REFLECTION_ROUGH : SCREEN_SPACE_REFLECTION_NORMAL;
RID shader = ssr.shader.version_get_shader(ssr.shader_version, mode);
@ -1659,10 +1659,10 @@ void SSEffects::screen_space_reflection(SSRRenderBuffers &p_ssr_buffers, const R
push_constant.view_index = v;
push_constant.orthogonal = p_projections[v].is_orthogonal();
push_constant.edge_tolerance = Math::sin(Math::deg_to_rad(15.0));
push_constant.proj_info[0] = -2.0f / (p_screen_size.width * p_projections[v].matrix[0][0]);
push_constant.proj_info[1] = -2.0f / (p_screen_size.height * p_projections[v].matrix[1][1]);
push_constant.proj_info[2] = (1.0f - p_projections[v].matrix[0][2]) / p_projections[v].matrix[0][0];
push_constant.proj_info[3] = (1.0f + p_projections[v].matrix[1][2]) / p_projections[v].matrix[1][1];
push_constant.proj_info[0] = -2.0f / (p_screen_size.width * p_projections[v].columns[0][0]);
push_constant.proj_info[1] = -2.0f / (p_screen_size.height * p_projections[v].columns[1][1]);
push_constant.proj_info[2] = (1.0f - p_projections[v].columns[0][2]) / p_projections[v].columns[0][0];
push_constant.proj_info[3] = (1.0f + p_projections[v].columns[1][2]) / p_projections[v].columns[1][1];
push_constant.vertical = 0;
if (ssr_roughness_quality == RS::ENV_SSR_ROUGHNESS_QUALITY_LOW) {
push_constant.steps = p_max_steps / 3;

View File

@ -1634,7 +1634,7 @@ void GI::SDFGI::debug_draw(uint32_t p_view_count, const Projection *p_projection
Projection inv_projection = p_projections[v].inverse();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
push_constant.inv_projection[j][i] = inv_projection.matrix[i][j];
push_constant.inv_projection[j][i] = inv_projection.columns[i][j];
}
}
@ -3285,7 +3285,7 @@ void GI::VoxelGIInstance::debug(RD::DrawListID p_draw_list, RID p_framebuffer, c
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
push_constant.projection[i * 4 + j] = cam_transform.matrix[i][j];
push_constant.projection[i * 4 + j] = cam_transform.columns[i][j];
}
}
@ -3820,10 +3820,10 @@ void GI::process_gi(Ref<RenderSceneBuffersRD> p_render_buffers, const RID *p_nor
push_constant.z_far = p_projections[0].get_z_far();
// these are only used if we have 1 view, else we use the projections in our scene data
push_constant.proj_info[0] = -2.0f / (internal_size.x * p_projections[0].matrix[0][0]);
push_constant.proj_info[1] = -2.0f / (internal_size.y * p_projections[0].matrix[1][1]);
push_constant.proj_info[2] = (1.0f - p_projections[0].matrix[0][2]) / p_projections[0].matrix[0][0];
push_constant.proj_info[3] = (1.0f + p_projections[0].matrix[1][2]) / p_projections[0].matrix[1][1];
push_constant.proj_info[0] = -2.0f / (internal_size.x * p_projections[0].columns[0][0]);
push_constant.proj_info[1] = -2.0f / (internal_size.y * p_projections[0].columns[1][1]);
push_constant.proj_info[2] = (1.0f - p_projections[0].columns[0][2]) / p_projections[0].columns[0][0];
push_constant.proj_info[3] = (1.0f + p_projections[0].columns[1][2]) / p_projections[0].columns[1][1];
bool use_sdfgi = p_render_buffers->has_custom_data(RB_SCOPE_SDFGI);
bool use_voxel_gi_instances = push_constant.max_voxel_gi_instances > 0;

View File

@ -300,10 +300,10 @@ void SkyRD::_render_sky(RD::DrawListID p_list, float p_time, RID p_fb, PipelineC
for (uint32_t v = 0; v < p_view_count; v++) {
// We only need key components of our projection matrix
sky_push_constant.projections[v][0] = p_projections[v].matrix[2][0];
sky_push_constant.projections[v][1] = p_projections[v].matrix[0][0];
sky_push_constant.projections[v][2] = p_projections[v].matrix[2][1];
sky_push_constant.projections[v][3] = p_projections[v].matrix[1][1];
sky_push_constant.projections[v][0] = p_projections[v].columns[2][0];
sky_push_constant.projections[v][1] = p_projections[v].columns[0][0];
sky_push_constant.projections[v][2] = p_projections[v].columns[2][1];
sky_push_constant.projections[v][3] = p_projections[v].columns[1][1];
}
sky_push_constant.position[0] = p_position.x;
sky_push_constant.position[1] = p_position.y;

View File

@ -1627,7 +1627,7 @@ void RendererCanvasRenderRD::light_update_shadow(RID p_rid, int p_shadow_index,
ShadowRenderPushConstant push_constant;
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
push_constant.projection[y * 4 + x] = projection.matrix[y][x];
push_constant.projection[y * 4 + x] = projection.columns[y][x];
}
}
static const Vector2 directions[4] = { Vector2(1, 0), Vector2(0, 1), Vector2(-1, 0), Vector2(0, -1) };
@ -1702,7 +1702,7 @@ void RendererCanvasRenderRD::light_update_directional_shadow(RID p_rid, int p_sh
ShadowRenderPushConstant push_constant;
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
push_constant.projection[y * 4 + x] = projection.matrix[y][x];
push_constant.projection[y * 4 + x] = projection.columns[y][x];
}
}
@ -1770,7 +1770,7 @@ void RendererCanvasRenderRD::render_sdf(RID p_render_target, LightOccluderInstan
ShadowRenderPushConstant push_constant;
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
push_constant.projection[y * 4 + x] = projection.matrix[y][x];
push_constant.projection[y * 4 + x] = projection.columns[y][x];
}
}

View File

@ -720,7 +720,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
Projection v = value;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
gui[i * 4 + j] = v.matrix[i][j];
gui[i * 4 + j] = v.columns[i][j];
}
}
}

View File

@ -302,7 +302,7 @@ public:
static _FORCE_INLINE_ void store_camera(const Projection &p_mtx, float *p_array) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
p_array[i * 4 + j] = p_mtx.matrix[i][j];
p_array[i * 4 + j] = p_mtx.columns[i][j];
}
}
}

View File

@ -273,7 +273,7 @@ Projection XRInterfaceExtension::get_projection_for_view(uint32_t p_view, double
if (GDVIRTUAL_CALL(_get_projection_for_view, p_view, p_aspect, p_z_near, p_z_far, arr)) {
ERR_FAIL_COND_V_MSG(arr.size() != 16, Projection(), "Projection matrix must contain 16 floats");
real_t *m = (real_t *)cm.matrix;
real_t *m = (real_t *)cm.columns;
for (int i = 0; i < 16; i++) {
m[i] = arr[i];
}