Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection. * Two versions of Vector4 (float and integer). * A Projection class, which is a 4x4 matrix specialized in projection types. These types have been requested for a long time, but given they were very corner case they were not added before. Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity. **Q**: Why Projection and not Matrix4? **A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
This commit is contained in:
parent
fe929d4787
commit
455c06ecd4
123 changed files with 4139 additions and 594 deletions
|
|
@ -172,75 +172,96 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
|
|||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_IVEC2: {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
int32_t *gui = (int32_t *)data;
|
||||
if (p_array_size > 0) {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
int count = 2 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0, j = 0; i < count; i += 2, j += 4) {
|
||||
if (i < s) {
|
||||
gui[j] = r[i];
|
||||
gui[j + 1] = r[i + 1];
|
||||
} else {
|
||||
gui[j] = 0;
|
||||
gui[j + 1] = 0;
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
gui[j + 2] = 0; // ignored
|
||||
gui[j + 3] = 0; // ignored
|
||||
int count = 2 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0, j = 0; i < count; i += 2, j += 4) {
|
||||
if (i < s) {
|
||||
gui[j] = r[i];
|
||||
gui[j + 1] = r[i + 1];
|
||||
} else {
|
||||
gui[j] = 0;
|
||||
gui[j + 1] = 0;
|
||||
}
|
||||
gui[j + 2] = 0; // ignored
|
||||
gui[j + 3] = 0; // ignored
|
||||
}
|
||||
} else {
|
||||
Vector2i v = value;
|
||||
gui[0] = v.x;
|
||||
gui[1] = v.y;
|
||||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_IVEC3: {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
int32_t *gui = (int32_t *)data;
|
||||
if (p_array_size > 0) {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
int count = 3 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0, j = 0; i < count; i += 3, j += 4) {
|
||||
if (i < s) {
|
||||
gui[j] = r[i];
|
||||
gui[j + 1] = r[i + 1];
|
||||
gui[j + 2] = r[i + 2];
|
||||
} else {
|
||||
gui[j] = 0;
|
||||
gui[j + 1] = 0;
|
||||
gui[j + 2] = 0;
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
gui[j + 3] = 0; // ignored
|
||||
int count = 3 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0, j = 0; i < count; i += 3, j += 4) {
|
||||
if (i < s) {
|
||||
gui[j] = r[i];
|
||||
gui[j + 1] = r[i + 1];
|
||||
gui[j + 2] = r[i + 2];
|
||||
} else {
|
||||
gui[j] = 0;
|
||||
gui[j + 1] = 0;
|
||||
gui[j + 2] = 0;
|
||||
}
|
||||
gui[j + 3] = 0; // ignored
|
||||
}
|
||||
} else {
|
||||
Vector3i v = value;
|
||||
gui[0] = v.x;
|
||||
gui[1] = v.y;
|
||||
gui[2] = v.z;
|
||||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_IVEC4: {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
int32_t *gui = (int32_t *)data;
|
||||
if (p_array_size > 0) {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
int count = 4 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0; i < count; i += 4) {
|
||||
if (i < s) {
|
||||
gui[i] = r[i];
|
||||
gui[i + 1] = r[i + 1];
|
||||
gui[i + 2] = r[i + 2];
|
||||
gui[i + 3] = r[i + 3];
|
||||
} else {
|
||||
gui[i] = 0;
|
||||
gui[i + 1] = 0;
|
||||
gui[i + 2] = 0;
|
||||
gui[i + 3] = 0;
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
int count = 4 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0; i < count; i += 4) {
|
||||
if (i < s) {
|
||||
gui[i] = r[i];
|
||||
gui[i + 1] = r[i + 1];
|
||||
gui[i + 2] = r[i + 2];
|
||||
gui[i + 3] = r[i + 3];
|
||||
} else {
|
||||
gui[i] = 0;
|
||||
gui[i + 1] = 0;
|
||||
gui[i + 2] = 0;
|
||||
gui[i + 3] = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Vector4i v = value;
|
||||
gui[0] = v.x;
|
||||
gui[1] = v.y;
|
||||
gui[2] = v.z;
|
||||
gui[3] = v.w;
|
||||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_UINT: {
|
||||
|
|
@ -267,75 +288,96 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
|
|||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_UVEC2: {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
uint32_t *gui = (uint32_t *)data;
|
||||
if (p_array_size > 0) {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
int count = 2 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0, j = 0; i < count; i += 2, j += 4) {
|
||||
if (i < s) {
|
||||
gui[j] = r[i];
|
||||
gui[j + 1] = r[i + 1];
|
||||
} else {
|
||||
gui[j] = 0;
|
||||
gui[j + 1] = 0;
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
gui[j + 2] = 0; // ignored
|
||||
gui[j + 3] = 0; // ignored
|
||||
int count = 2 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0, j = 0; i < count; i += 2, j += 4) {
|
||||
if (i < s) {
|
||||
gui[j] = r[i];
|
||||
gui[j + 1] = r[i + 1];
|
||||
} else {
|
||||
gui[j] = 0;
|
||||
gui[j + 1] = 0;
|
||||
}
|
||||
gui[j + 2] = 0; // ignored
|
||||
gui[j + 3] = 0; // ignored
|
||||
}
|
||||
} else {
|
||||
Vector2i v = value;
|
||||
gui[0] = v.x;
|
||||
gui[1] = v.y;
|
||||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_UVEC3: {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
uint32_t *gui = (uint32_t *)data;
|
||||
if (p_array_size > 0) {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
int count = 3 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0, j = 0; i < count; i += 3, j += 4) {
|
||||
if (i < s) {
|
||||
gui[j] = r[i];
|
||||
gui[j + 1] = r[i + 1];
|
||||
gui[j + 2] = r[i + 2];
|
||||
} else {
|
||||
gui[j] = 0;
|
||||
gui[j + 1] = 0;
|
||||
gui[j + 2] = 0;
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
gui[j + 3] = 0; // ignored
|
||||
int count = 3 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0, j = 0; i < count; i += 3, j += 4) {
|
||||
if (i < s) {
|
||||
gui[j] = r[i];
|
||||
gui[j + 1] = r[i + 1];
|
||||
gui[j + 2] = r[i + 2];
|
||||
} else {
|
||||
gui[j] = 0;
|
||||
gui[j + 1] = 0;
|
||||
gui[j + 2] = 0;
|
||||
}
|
||||
gui[j + 3] = 0; // ignored
|
||||
}
|
||||
} else {
|
||||
Vector3i v = value;
|
||||
gui[0] = v.x;
|
||||
gui[1] = v.y;
|
||||
gui[2] = v.z;
|
||||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_UVEC4: {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
uint32_t *gui = (uint32_t *)data;
|
||||
if (p_array_size > 0) {
|
||||
Vector<int> iv = value;
|
||||
int s = iv.size();
|
||||
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
int count = 4 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (i < s) {
|
||||
gui[i] = r[i];
|
||||
gui[i + 1] = r[i + 1];
|
||||
gui[i + 2] = r[i + 2];
|
||||
gui[i + 3] = r[i + 3];
|
||||
} else {
|
||||
gui[i] = 0;
|
||||
gui[i + 1] = 0;
|
||||
gui[i + 2] = 0;
|
||||
gui[i + 3] = 0;
|
||||
if (p_array_size <= 0) {
|
||||
p_array_size = 1;
|
||||
}
|
||||
int count = 4 * p_array_size;
|
||||
|
||||
const int *r = iv.ptr();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (i < s) {
|
||||
gui[i] = r[i];
|
||||
gui[i + 1] = r[i + 1];
|
||||
gui[i + 2] = r[i + 2];
|
||||
gui[i + 3] = r[i + 3];
|
||||
} else {
|
||||
gui[i] = 0;
|
||||
gui[i + 1] = 0;
|
||||
gui[i + 2] = 0;
|
||||
gui[i + 3] = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Vector4i v = value;
|
||||
gui[0] = v.x;
|
||||
gui[1] = v.y;
|
||||
gui[2] = v.z;
|
||||
gui[3] = v.w;
|
||||
}
|
||||
} break;
|
||||
case ShaderLanguage::TYPE_FLOAT: {
|
||||
|
|
@ -514,13 +556,20 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
|
|||
gui[1] = v.y;
|
||||
gui[2] = v.z;
|
||||
gui[3] = v.w;
|
||||
} else {
|
||||
} else if (value.get_type() == Variant::PLANE) {
|
||||
Plane v = value;
|
||||
|
||||
gui[0] = v.normal.x;
|
||||
gui[1] = v.normal.y;
|
||||
gui[2] = v.normal.z;
|
||||
gui[3] = v.d;
|
||||
} else {
|
||||
Vector4 v = value;
|
||||
|
||||
gui[0] = v.x;
|
||||
gui[1] = v.y;
|
||||
gui[2] = v.z;
|
||||
gui[3] = v.w;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
|
@ -670,7 +719,7 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
|
|||
gui[i + 15] = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (value.get_type() == Variant::TRANSFORM3D) {
|
||||
Transform3D v = value;
|
||||
gui[0] = v.basis.rows[0][0];
|
||||
gui[1] = v.basis.rows[1][0];
|
||||
|
|
@ -691,6 +740,13 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
|
|||
gui[13] = v.origin.y;
|
||||
gui[14] = v.origin.z;
|
||||
gui[15] = 1;
|
||||
} else {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
#ifndef MATERIAL_STORAGE_RD_H
|
||||
#define MATERIAL_STORAGE_RD_H
|
||||
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "core/templates/self_list.h"
|
||||
|
|
@ -302,7 +302,7 @@ public:
|
|||
p_array[11] = p_mtx.origin.z;
|
||||
}
|
||||
|
||||
static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) {
|
||||
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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue