mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-19 22:24:23 +01:00
Removed CameraMatrix, and switched to Projection.
This commit is contained in:
parent
904c88c403
commit
8c2e76840c
@ -1,665 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* camera_matrix.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "camera_matrix.h"
|
||||
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/print_string.h"
|
||||
|
||||
void CameraMatrix::set_identity() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
matrix[i][j] = (i == j) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CameraMatrix::set_zero() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
matrix[i][j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Plane CameraMatrix::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;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CameraMatrix::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) {
|
||||
if (p_flip_fov) {
|
||||
p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
|
||||
}
|
||||
|
||||
real_t sine, cotangent, deltaZ;
|
||||
real_t radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
|
||||
|
||||
deltaZ = p_z_far - p_z_near;
|
||||
sine = Math::sin(radians);
|
||||
|
||||
if ((deltaZ == 0) || (sine == 0) || (p_aspect == 0)) {
|
||||
return;
|
||||
}
|
||||
cotangent = Math::cos(radians) / sine;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void CameraMatrix::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) {
|
||||
if (p_flip_fov) {
|
||||
p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
|
||||
}
|
||||
|
||||
real_t left, right, modeltranslation, ymax, xmax, frustumshift;
|
||||
|
||||
ymax = p_z_near * tan(p_fovy_degrees * Math_PI / 360.0f);
|
||||
xmax = ymax * p_aspect;
|
||||
frustumshift = (p_intraocular_dist / 2.0) * p_z_near / p_convergence_dist;
|
||||
|
||||
switch (p_eye) {
|
||||
case 1: { // left eye
|
||||
left = -xmax + frustumshift;
|
||||
right = xmax + frustumshift;
|
||||
modeltranslation = p_intraocular_dist / 2.0;
|
||||
}; break;
|
||||
case 2: { // right eye
|
||||
left = -xmax - frustumshift;
|
||||
right = xmax - frustumshift;
|
||||
modeltranslation = -p_intraocular_dist / 2.0;
|
||||
}; break;
|
||||
default: { // mono, should give the same result as set_perspective(p_fovy_degrees,p_aspect,p_z_near,p_z_far,p_flip_fov)
|
||||
left = -xmax;
|
||||
right = xmax;
|
||||
modeltranslation = 0.0;
|
||||
}; break;
|
||||
};
|
||||
|
||||
set_frustum(left, right, -ymax, ymax, p_z_near, p_z_far);
|
||||
|
||||
// translate matrix by (modeltranslation, 0.0, 0.0)
|
||||
CameraMatrix cm;
|
||||
cm.set_identity();
|
||||
cm.matrix[3][0] = modeltranslation;
|
||||
*this = *this * cm;
|
||||
}
|
||||
|
||||
void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far) {
|
||||
// we first calculate our base frustum on our values without taking our lens magnification into account.
|
||||
real_t f1 = (p_intraocular_dist * 0.5) / p_display_to_lens;
|
||||
real_t f2 = ((p_display_width - p_intraocular_dist) * 0.5) / p_display_to_lens;
|
||||
real_t f3 = (p_display_width / 4.0) / p_display_to_lens;
|
||||
|
||||
// now we apply our oversample factor to increase our FOV. how much we oversample is always a balance we strike between performance and how much
|
||||
// we're willing to sacrifice in FOV.
|
||||
real_t add = ((f1 + f2) * (p_oversample - 1.0)) / 2.0;
|
||||
f1 += add;
|
||||
f2 += add;
|
||||
f3 *= p_oversample;
|
||||
|
||||
// always apply KEEP_WIDTH aspect ratio
|
||||
f3 /= p_aspect;
|
||||
|
||||
switch (p_eye) {
|
||||
case 1: { // left eye
|
||||
set_frustum(-f2 * p_z_near, f1 * p_z_near, -f3 * p_z_near, f3 * p_z_near, p_z_near, p_z_far);
|
||||
}; break;
|
||||
case 2: { // right eye
|
||||
set_frustum(-f1 * p_z_near, f2 * p_z_near, -f3 * p_z_near, f3 * p_z_near, p_z_near, p_z_far);
|
||||
}; break;
|
||||
default: { // mono, does not apply here!
|
||||
}; break;
|
||||
};
|
||||
};
|
||||
|
||||
void CameraMatrix::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 / (p_right - p_left);
|
||||
matrix[3][0] = -((p_right + p_left) / (p_right - p_left));
|
||||
matrix[1][1] = 2 / (p_top - p_bottom);
|
||||
matrix[3][1] = -((p_top + p_bottom) / (p_top - p_bottom));
|
||||
matrix[2][2] = -2 / (p_zfar - p_znear);
|
||||
matrix[3][2] = -((p_zfar + p_znear) / (p_zfar - p_znear));
|
||||
matrix[3][3] = 1.0;
|
||||
}
|
||||
|
||||
void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) {
|
||||
if (!p_flip_fov) {
|
||||
p_size *= p_aspect;
|
||||
}
|
||||
|
||||
set_orthogonal(-p_size / 2, +p_size / 2, -p_size / p_aspect / 2, +p_size / p_aspect / 2, p_znear, p_zfar);
|
||||
}
|
||||
|
||||
void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
|
||||
ERR_FAIL_COND(p_right <= p_left);
|
||||
ERR_FAIL_COND(p_top <= p_bottom);
|
||||
ERR_FAIL_COND(p_far <= p_near);
|
||||
|
||||
real_t *te = &matrix[0][0];
|
||||
real_t x = 2 * p_near / (p_right - p_left);
|
||||
real_t y = 2 * p_near / (p_top - p_bottom);
|
||||
|
||||
real_t a = (p_right + p_left) / (p_right - p_left);
|
||||
real_t b = (p_top + p_bottom) / (p_top - p_bottom);
|
||||
real_t c = -(p_far + p_near) / (p_far - p_near);
|
||||
real_t d = -2 * p_far * p_near / (p_far - p_near);
|
||||
|
||||
te[0] = x;
|
||||
te[1] = 0;
|
||||
te[2] = 0;
|
||||
te[3] = 0;
|
||||
te[4] = 0;
|
||||
te[5] = y;
|
||||
te[6] = 0;
|
||||
te[7] = 0;
|
||||
te[8] = a;
|
||||
te[9] = b;
|
||||
te[10] = c;
|
||||
te[11] = -1;
|
||||
te[12] = 0;
|
||||
te[13] = 0;
|
||||
te[14] = d;
|
||||
te[15] = 0;
|
||||
}
|
||||
|
||||
void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov) {
|
||||
if (!p_flip_fov) {
|
||||
p_size *= p_aspect;
|
||||
}
|
||||
|
||||
set_frustum(-p_size / 2 + p_offset.x, +p_size / 2 + p_offset.x, -p_size / p_aspect / 2 + p_offset.y, +p_size / p_aspect / 2 + p_offset.y, p_near, p_far);
|
||||
}
|
||||
|
||||
real_t CameraMatrix::get_z_far() const {
|
||||
const real_t *matrix = (const real_t *)this->matrix;
|
||||
Plane new_plane = Plane(matrix[3] - matrix[2],
|
||||
matrix[7] - matrix[6],
|
||||
matrix[11] - matrix[10],
|
||||
matrix[15] - matrix[14]);
|
||||
|
||||
new_plane.normal = -new_plane.normal;
|
||||
new_plane.normalize();
|
||||
|
||||
return new_plane.d;
|
||||
}
|
||||
real_t CameraMatrix::get_z_near() const {
|
||||
const real_t *matrix = (const real_t *)this->matrix;
|
||||
Plane new_plane = Plane(matrix[3] + matrix[2],
|
||||
matrix[7] + matrix[6],
|
||||
matrix[11] + matrix[10],
|
||||
-matrix[15] - matrix[14]);
|
||||
|
||||
new_plane.normalize();
|
||||
return new_plane.d;
|
||||
}
|
||||
|
||||
Vector2 CameraMatrix::get_viewport_half_extents() const {
|
||||
const real_t *matrix = (const real_t *)this->matrix;
|
||||
///////--- Near Plane ---///////
|
||||
Plane near_plane = Plane(matrix[3] + matrix[2],
|
||||
matrix[7] + matrix[6],
|
||||
matrix[11] + matrix[10],
|
||||
-matrix[15] - matrix[14]);
|
||||
near_plane.normalize();
|
||||
|
||||
///////--- Right Plane ---///////
|
||||
Plane right_plane = Plane(matrix[3] - matrix[0],
|
||||
matrix[7] - matrix[4],
|
||||
matrix[11] - matrix[8],
|
||||
-matrix[15] + matrix[12]);
|
||||
right_plane.normalize();
|
||||
|
||||
Plane top_plane = Plane(matrix[3] - matrix[1],
|
||||
matrix[7] - matrix[5],
|
||||
matrix[11] - matrix[9],
|
||||
-matrix[15] + matrix[13]);
|
||||
top_plane.normalize();
|
||||
|
||||
Vector3 res;
|
||||
near_plane.intersect_3(right_plane, top_plane, &res);
|
||||
|
||||
return Vector2(res.x, res.y);
|
||||
}
|
||||
|
||||
bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const {
|
||||
Vector<Plane> planes = get_projection_planes(Transform());
|
||||
const Planes intersections[8][3] = {
|
||||
{ PLANE_FAR, PLANE_LEFT, PLANE_TOP },
|
||||
{ PLANE_FAR, PLANE_LEFT, PLANE_BOTTOM },
|
||||
{ PLANE_FAR, PLANE_RIGHT, PLANE_TOP },
|
||||
{ PLANE_FAR, PLANE_RIGHT, PLANE_BOTTOM },
|
||||
{ PLANE_NEAR, PLANE_LEFT, PLANE_TOP },
|
||||
{ PLANE_NEAR, PLANE_LEFT, PLANE_BOTTOM },
|
||||
{ PLANE_NEAR, PLANE_RIGHT, PLANE_TOP },
|
||||
{ PLANE_NEAR, PLANE_RIGHT, PLANE_BOTTOM },
|
||||
};
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
Vector3 point;
|
||||
bool res = planes[intersections[i][0]].intersect_3(planes[intersections[i][1]], planes[intersections[i][2]], &point);
|
||||
ERR_FAIL_COND_V(!res, false);
|
||||
p_8points[i] = p_transform.xform(point);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) const {
|
||||
/** Fast Plane Extraction from combined modelview/projection matrices.
|
||||
* References:
|
||||
* https://web.archive.org/web/20011221205252/http://www.markmorley.com/opengl/frustumculling.html
|
||||
* https://web.archive.org/web/20061020020112/http://www2.ravensoft.com/users/ggribb/plane%20extraction.pdf
|
||||
*/
|
||||
|
||||
Vector<Plane> planes;
|
||||
|
||||
const real_t *matrix = (const real_t *)this->matrix;
|
||||
|
||||
Plane new_plane;
|
||||
|
||||
///////--- Near Plane ---///////
|
||||
new_plane = Plane(matrix[3] + matrix[2],
|
||||
matrix[7] + matrix[6],
|
||||
matrix[11] + matrix[10],
|
||||
matrix[15] + matrix[14]);
|
||||
|
||||
new_plane.normal = -new_plane.normal;
|
||||
new_plane.normalize();
|
||||
|
||||
planes.push_back(p_transform.xform(new_plane));
|
||||
|
||||
///////--- Far Plane ---///////
|
||||
new_plane = Plane(matrix[3] - matrix[2],
|
||||
matrix[7] - matrix[6],
|
||||
matrix[11] - matrix[10],
|
||||
matrix[15] - matrix[14]);
|
||||
|
||||
new_plane.normal = -new_plane.normal;
|
||||
new_plane.normalize();
|
||||
|
||||
planes.push_back(p_transform.xform(new_plane));
|
||||
|
||||
///////--- Left Plane ---///////
|
||||
new_plane = Plane(matrix[3] + matrix[0],
|
||||
matrix[7] + matrix[4],
|
||||
matrix[11] + matrix[8],
|
||||
matrix[15] + matrix[12]);
|
||||
|
||||
new_plane.normal = -new_plane.normal;
|
||||
new_plane.normalize();
|
||||
|
||||
planes.push_back(p_transform.xform(new_plane));
|
||||
|
||||
///////--- Top Plane ---///////
|
||||
new_plane = Plane(matrix[3] - matrix[1],
|
||||
matrix[7] - matrix[5],
|
||||
matrix[11] - matrix[9],
|
||||
matrix[15] - matrix[13]);
|
||||
|
||||
new_plane.normal = -new_plane.normal;
|
||||
new_plane.normalize();
|
||||
|
||||
planes.push_back(p_transform.xform(new_plane));
|
||||
|
||||
///////--- Right Plane ---///////
|
||||
new_plane = Plane(matrix[3] - matrix[0],
|
||||
matrix[7] - matrix[4],
|
||||
matrix[11] - matrix[8],
|
||||
matrix[15] - matrix[12]);
|
||||
|
||||
new_plane.normal = -new_plane.normal;
|
||||
new_plane.normalize();
|
||||
|
||||
planes.push_back(p_transform.xform(new_plane));
|
||||
|
||||
///////--- Bottom Plane ---///////
|
||||
new_plane = Plane(matrix[3] + matrix[1],
|
||||
matrix[7] + matrix[5],
|
||||
matrix[11] + matrix[9],
|
||||
matrix[15] + matrix[13]);
|
||||
|
||||
new_plane.normal = -new_plane.normal;
|
||||
new_plane.normalize();
|
||||
|
||||
planes.push_back(p_transform.xform(new_plane));
|
||||
|
||||
return planes;
|
||||
}
|
||||
|
||||
CameraMatrix CameraMatrix::inverse() const {
|
||||
CameraMatrix cm = *this;
|
||||
cm.invert();
|
||||
return cm;
|
||||
}
|
||||
|
||||
void CameraMatrix::invert() {
|
||||
int i, j, k;
|
||||
int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */
|
||||
real_t pvt_val; /* Value of current pivot element */
|
||||
real_t hold; /* Temporary storage */
|
||||
real_t determinat; /* Determinant */
|
||||
|
||||
determinat = 1.0;
|
||||
for (k = 0; k < 4; k++) {
|
||||
/** Locate k'th pivot element **/
|
||||
pvt_val = matrix[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)) {
|
||||
pvt_i[k] = i;
|
||||
pvt_j[k] = j;
|
||||
pvt_val = matrix[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Product of pivots, gives determinant when finished **/
|
||||
determinat *= pvt_val;
|
||||
if (Math::abs(determinat) < (real_t)1e-7) {
|
||||
return; //(false); /** Matrix is singular (zero determinant). **/
|
||||
}
|
||||
|
||||
/** "Interchange" rows (with sign change stuff) **/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/** "Interchange" columns **/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/** Divide column by minus pivot value **/
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (i != k) {
|
||||
matrix[i][k] /= (-pvt_val);
|
||||
}
|
||||
}
|
||||
|
||||
/** Reduce the matrix **/
|
||||
for (i = 0; i < 4; i++) {
|
||||
hold = matrix[i][k];
|
||||
for (j = 0; j < 4; j++) {
|
||||
if (i != k && j != k) {
|
||||
matrix[i][j] += hold * matrix[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Divide row by pivot **/
|
||||
for (j = 0; j < 4; j++) {
|
||||
if (j != k) {
|
||||
matrix[k][j] /= pvt_val;
|
||||
}
|
||||
}
|
||||
|
||||
/** Replace pivot by reciprocal (at last we can touch it). **/
|
||||
matrix[k][k] = 1.0 / pvt_val;
|
||||
}
|
||||
|
||||
/* That was most of the work, one final pass of row/column interchange */
|
||||
/* to finish */
|
||||
for (k = 4 - 2; k >= 0; k--) { /* Don't need to work with 1 by 1 corner*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CameraMatrix::CameraMatrix() {
|
||||
set_identity();
|
||||
}
|
||||
|
||||
CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
|
||||
CameraMatrix new_matrix;
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
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];
|
||||
}
|
||||
new_matrix.matrix[j][i] = ab;
|
||||
}
|
||||
}
|
||||
|
||||
return new_matrix;
|
||||
}
|
||||
|
||||
void CameraMatrix::set_light_bias() {
|
||||
real_t *m = &matrix[0][0];
|
||||
|
||||
m[0] = 0.5;
|
||||
m[1] = 0.0;
|
||||
m[2] = 0.0;
|
||||
m[3] = 0.0;
|
||||
m[4] = 0.0;
|
||||
m[5] = 0.5;
|
||||
m[6] = 0.0;
|
||||
m[7] = 0.0;
|
||||
m[8] = 0.0;
|
||||
m[9] = 0.0;
|
||||
m[10] = 0.5;
|
||||
m[11] = 0.0;
|
||||
m[12] = 0.5;
|
||||
m[13] = 0.5;
|
||||
m[14] = 0.5;
|
||||
m[15] = 1.0;
|
||||
}
|
||||
|
||||
void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
|
||||
real_t *m = &matrix[0][0];
|
||||
|
||||
m[0] = p_rect.size.width;
|
||||
m[1] = 0.0;
|
||||
m[2] = 0.0;
|
||||
m[3] = 0.0;
|
||||
m[4] = 0.0;
|
||||
m[5] = p_rect.size.height;
|
||||
m[6] = 0.0;
|
||||
m[7] = 0.0;
|
||||
m[8] = 0.0;
|
||||
m[9] = 0.0;
|
||||
m[10] = 1.0;
|
||||
m[11] = 0.0;
|
||||
m[12] = p_rect.position.x;
|
||||
m[13] = p_rect.position.y;
|
||||
m[14] = 0.0;
|
||||
m[15] = 1.0;
|
||||
}
|
||||
|
||||
CameraMatrix::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]);
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
real_t CameraMatrix::get_aspect() const {
|
||||
Vector2 vp_he = get_viewport_half_extents();
|
||||
return vp_he.x / vp_he.y;
|
||||
}
|
||||
|
||||
int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
|
||||
Vector3 result = xform(Vector3(1, 0, -1));
|
||||
|
||||
return int((result.x * 0.5f + 0.5f) * p_for_pixel_width);
|
||||
}
|
||||
|
||||
bool CameraMatrix::is_orthogonal() const {
|
||||
return matrix[3][3] == 1.0;
|
||||
}
|
||||
|
||||
real_t CameraMatrix::get_fov() const {
|
||||
const real_t *matrix = (const real_t *)this->matrix;
|
||||
|
||||
Plane right_plane = Plane(matrix[3] - matrix[0],
|
||||
matrix[7] - matrix[4],
|
||||
matrix[11] - matrix[8],
|
||||
-matrix[15] + matrix[12]);
|
||||
right_plane.normalize();
|
||||
|
||||
if ((matrix[8] == 0) && (matrix[9] == 0)) {
|
||||
return Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x))) * 2;
|
||||
} else {
|
||||
// our frustum is asymmetrical need to calculate the left planes angle separately..
|
||||
Plane left_plane = Plane(matrix[3] + matrix[0],
|
||||
matrix[7] + matrix[4],
|
||||
matrix[11] + matrix[8],
|
||||
matrix[15] + matrix[12]);
|
||||
left_plane.normalize();
|
||||
|
||||
return Math::rad2deg(Math::acos(Math::abs(left_plane.normal.x))) + Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x)));
|
||||
}
|
||||
}
|
||||
|
||||
void CameraMatrix::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;
|
||||
}
|
||||
|
||||
void CameraMatrix::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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
matrix[0][3] = 0;
|
||||
matrix[1][3] = 0;
|
||||
matrix[2][3] = 0;
|
||||
matrix[3][3] = 1;
|
||||
}
|
||||
|
||||
CameraMatrix::operator Transform() const {
|
||||
Transform tr;
|
||||
const real_t *m = &matrix[0][0];
|
||||
|
||||
tr.basis.rows[0][0] = m[0];
|
||||
tr.basis.rows[1][0] = m[1];
|
||||
tr.basis.rows[2][0] = m[2];
|
||||
|
||||
tr.basis.rows[0][1] = m[4];
|
||||
tr.basis.rows[1][1] = m[5];
|
||||
tr.basis.rows[2][1] = m[6];
|
||||
|
||||
tr.basis.rows[0][2] = m[8];
|
||||
tr.basis.rows[1][2] = m[9];
|
||||
tr.basis.rows[2][2] = m[10];
|
||||
|
||||
tr.origin.x = m[12];
|
||||
tr.origin.y = m[13];
|
||||
tr.origin.z = m[14];
|
||||
|
||||
return tr;
|
||||
}
|
||||
|
||||
CameraMatrix::CameraMatrix(const Transform &p_transform) {
|
||||
const Transform &tr = p_transform;
|
||||
real_t *m = &matrix[0][0];
|
||||
|
||||
m[0] = tr.basis.rows[0][0];
|
||||
m[1] = tr.basis.rows[1][0];
|
||||
m[2] = tr.basis.rows[2][0];
|
||||
m[3] = 0.0;
|
||||
m[4] = tr.basis.rows[0][1];
|
||||
m[5] = tr.basis.rows[1][1];
|
||||
m[6] = tr.basis.rows[2][1];
|
||||
m[7] = 0.0;
|
||||
m[8] = tr.basis.rows[0][2];
|
||||
m[9] = tr.basis.rows[1][2];
|
||||
m[10] = tr.basis.rows[2][2];
|
||||
m[11] = 0.0;
|
||||
m[12] = tr.origin.x;
|
||||
m[13] = tr.origin.y;
|
||||
m[14] = tr.origin.z;
|
||||
m[15] = 1.0;
|
||||
}
|
||||
|
||||
CameraMatrix::~CameraMatrix() {
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
#ifndef CAMERA_MATRIX_H
|
||||
#define CAMERA_MATRIX_H
|
||||
/*************************************************************************/
|
||||
/* camera_matrix.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/math/rect2.h"
|
||||
#include "core/math/transform.h"
|
||||
|
||||
struct CameraMatrix {
|
||||
enum Planes {
|
||||
PLANE_NEAR,
|
||||
PLANE_FAR,
|
||||
PLANE_LEFT,
|
||||
PLANE_TOP,
|
||||
PLANE_RIGHT,
|
||||
PLANE_BOTTOM
|
||||
};
|
||||
|
||||
real_t matrix[4][4];
|
||||
|
||||
void set_identity();
|
||||
void set_zero();
|
||||
void set_light_bias();
|
||||
void set_light_atlas_rect(const Rect2 &p_rect);
|
||||
void 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 = false);
|
||||
void 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);
|
||||
void set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far);
|
||||
void 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);
|
||||
void set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov = false);
|
||||
void set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far);
|
||||
void set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false);
|
||||
|
||||
static real_t get_fovy(real_t p_fovx, real_t p_aspect) {
|
||||
return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0);
|
||||
}
|
||||
|
||||
real_t get_z_far() const;
|
||||
real_t get_z_near() const;
|
||||
real_t get_aspect() const;
|
||||
real_t get_fov() const;
|
||||
bool is_orthogonal() const;
|
||||
|
||||
Vector<Plane> get_projection_planes(const Transform &p_transform) const;
|
||||
|
||||
bool get_endpoints(const Transform &p_transform, Vector3 *p_8points) const;
|
||||
Vector2 get_viewport_half_extents() const;
|
||||
|
||||
void invert();
|
||||
CameraMatrix inverse() const;
|
||||
|
||||
CameraMatrix operator*(const CameraMatrix &p_matrix) const;
|
||||
|
||||
Plane xform4(const Plane &p_vec4) const;
|
||||
_FORCE_INLINE_ Vector3 xform(const Vector3 &p_vec3) const;
|
||||
|
||||
operator String() const;
|
||||
|
||||
void scale_translate_to_fit(const AABB &p_aabb);
|
||||
void make_scale(const Vector3 &p_scale);
|
||||
int get_pixels_per_meter(int p_for_pixel_width) const;
|
||||
operator Transform() const;
|
||||
|
||||
CameraMatrix();
|
||||
CameraMatrix(const Transform &p_transform);
|
||||
~CameraMatrix();
|
||||
};
|
||||
|
||||
Vector3 CameraMatrix::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];
|
||||
return ret / w;
|
||||
}
|
||||
|
||||
#endif
|
@ -30,7 +30,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/self_list.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "servers/visual/rasterizer.h"
|
||||
@ -84,7 +84,7 @@ public:
|
||||
|
||||
RID light_instance_create(RID p_light) { return RID(); }
|
||||
void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) {}
|
||||
void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0) {}
|
||||
void light_instance_set_shadow_transform(RID p_light_instance, const Projection &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0) {}
|
||||
void light_instance_mark_visible(RID p_light_instance) {}
|
||||
|
||||
RID reflection_atlas_create() { return RID(); }
|
||||
@ -99,7 +99,7 @@ public:
|
||||
bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) { return false; }
|
||||
bool reflection_probe_instance_postprocess_step(RID p_instance) { return true; }
|
||||
|
||||
void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {}
|
||||
void render_scene(const Transform &p_cam_transform, const Projection &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {}
|
||||
void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) {}
|
||||
|
||||
void set_scene_pass(uint64_t p_pass) {}
|
||||
@ -630,7 +630,7 @@ public:
|
||||
void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_transform){};
|
||||
void canvas_debug_viewport_shadows(Light *p_lights_with_shadow){};
|
||||
|
||||
void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {}
|
||||
void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, Projection *p_xform_cache) {}
|
||||
|
||||
void reset_canvas() {}
|
||||
|
||||
|
@ -757,7 +757,7 @@ void RasterizerCanvasBaseGLES2::_copy_screen(const Rect2 &p_rect) {
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {
|
||||
void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, Projection *p_xform_cache) {
|
||||
RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer);
|
||||
ERR_FAIL_COND(!cls);
|
||||
|
||||
@ -795,7 +795,7 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer,
|
||||
//light.basis.scale(Vector3(to_light.elements[0].length(),to_light.elements[1].length(),1));
|
||||
|
||||
//p_near=1;
|
||||
CameraMatrix projection;
|
||||
Projection projection;
|
||||
{
|
||||
real_t fov = 90;
|
||||
real_t nearp = p_near;
|
||||
@ -811,7 +811,7 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer,
|
||||
}
|
||||
|
||||
Vector3 cam_target = Basis(Vector3(0, 0, Math_PI * 2 * (i / 4.0))).xform(Vector3(0, 1, 0));
|
||||
projection = projection * CameraMatrix(Transform().looking_at(cam_target, Vector3(0, 0, -1)).affine_inverse());
|
||||
projection = projection * Projection(Transform().looking_at(cam_target, Vector3(0, 0, -1)).affine_inverse());
|
||||
|
||||
state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::PROJECTION_MATRIX, projection);
|
||||
state.canvas_shadow_shader.set_uniform(CanvasShadowShaderGLES2::LIGHT_MATRIX, light);
|
||||
|
@ -132,7 +132,7 @@ public:
|
||||
void draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample);
|
||||
|
||||
virtual void reset_canvas();
|
||||
virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache);
|
||||
virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, Projection *p_xform_cache);
|
||||
virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow);
|
||||
|
||||
RasterizerStorageGLES2::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map);
|
||||
|
@ -950,7 +950,7 @@ void RasterizerSceneGLES2::light_instance_set_transform(RID p_light_instance, co
|
||||
light_instance->transform = p_transform;
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES2::light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale) {
|
||||
void RasterizerSceneGLES2::light_instance_set_shadow_transform(RID p_light_instance, const Projection &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale) {
|
||||
LightInstance *light_instance = light_instance_owner.getornull(p_light_instance);
|
||||
ERR_FAIL_COND(!light_instance);
|
||||
|
||||
@ -1973,7 +1973,7 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado
|
||||
Vector3 direction = p_view_transform.basis.xform_inv(light->transform.basis.xform(Vector3(0, 0, -1))).normalized();
|
||||
state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction);
|
||||
|
||||
CameraMatrix matrices[4];
|
||||
Projection matrices[4];
|
||||
|
||||
if (!state.render_no_shadows && light_ptr->shadow && directional_shadow.depth) {
|
||||
int shadow_count = 0;
|
||||
@ -2024,13 +2024,13 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado
|
||||
|
||||
Transform modelview = (p_view_transform.inverse() * light->shadow_transform[k].transform).affine_inverse();
|
||||
|
||||
CameraMatrix bias;
|
||||
Projection bias;
|
||||
bias.set_light_bias();
|
||||
CameraMatrix rectm;
|
||||
Projection rectm;
|
||||
Rect2 atlas_rect = Rect2(float(x) / directional_shadow.size, float(y) / directional_shadow.size, float(width) / directional_shadow.size, float(height) / directional_shadow.size);
|
||||
rectm.set_light_atlas_rect(atlas_rect);
|
||||
|
||||
CameraMatrix shadow_mtx = rectm * bias * light->shadow_transform[k].camera * modelview;
|
||||
Projection shadow_mtx = rectm * bias * light->shadow_transform[k].camera * modelview;
|
||||
matrices[k] = shadow_mtx;
|
||||
|
||||
/*Color light_clamp;
|
||||
@ -2150,13 +2150,13 @@ void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shado
|
||||
|
||||
Transform modelview = (p_view_transform.inverse() * light->transform).inverse();
|
||||
|
||||
CameraMatrix bias;
|
||||
Projection bias;
|
||||
bias.set_light_bias();
|
||||
|
||||
CameraMatrix rectm;
|
||||
Projection rectm;
|
||||
rectm.set_light_atlas_rect(rect);
|
||||
|
||||
CameraMatrix shadow_matrix = rectm * bias * light->shadow_transform[0].camera * modelview;
|
||||
Projection shadow_matrix = rectm * bias * light->shadow_transform[0].camera * modelview;
|
||||
|
||||
state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_PIXEL_SIZE, Size2(1.0 / shadow_atlas->size, 1.0 / shadow_atlas->size));
|
||||
state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, shadow_matrix);
|
||||
@ -2217,7 +2217,7 @@ void RasterizerSceneGLES2::_setup_refprobes(ReflectionProbeInstance *p_refprobe1
|
||||
}
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, const int p_eye, RID p_shadow_atlas, Environment *p_env, GLuint p_base_env, float p_shadow_bias, float p_shadow_normal_bias, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow) {
|
||||
void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const Projection &p_projection, const int p_eye, RID p_shadow_atlas, Environment *p_env, GLuint p_base_env, float p_shadow_bias, float p_shadow_normal_bias, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow) {
|
||||
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
|
||||
|
||||
Vector2 viewport_size = state.viewport_size;
|
||||
@ -2244,7 +2244,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
|
||||
bool prev_octahedral_compression = false;
|
||||
|
||||
Transform view_transform_inverse = p_view_transform.inverse();
|
||||
CameraMatrix projection_inverse = p_projection.inverse();
|
||||
Projection projection_inverse = p_projection.inverse();
|
||||
|
||||
bool prev_base_pass = false;
|
||||
LightInstance *prev_light = nullptr;
|
||||
@ -2596,7 +2596,7 @@ void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements,
|
||||
state.scene_shader.set_conditional(SceneShaderGLES2::USE_DEPTH_PREPASS, false);
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation) {
|
||||
void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const Projection &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation) {
|
||||
ERR_FAIL_COND(!p_sky);
|
||||
|
||||
RasterizerStorageGLES2::Texture *tex = storage->texture_owner.getornull(p_sky->panorama);
|
||||
@ -2614,7 +2614,7 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
// Camera
|
||||
CameraMatrix camera;
|
||||
Projection camera;
|
||||
|
||||
if (p_custom_fov) {
|
||||
float near_plane = p_projection.get_z_near();
|
||||
@ -2705,7 +2705,7 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C
|
||||
storage->shaders.copy.set_conditional(CopyShaderGLES2::OUTPUT_LINEAR, false);
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p_cam_projection) {
|
||||
void RasterizerSceneGLES2::_post_process(Environment *env, const Projection &p_cam_projection) {
|
||||
//copy to front buffer
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
@ -3155,7 +3155,7 @@ void RasterizerSceneGLES2::_post_process(Environment *env, const CameraMatrix &p
|
||||
state.tonemap_shader.set_conditional(TonemapShaderGLES2::DISABLE_ALPHA, false);
|
||||
}
|
||||
|
||||
void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {
|
||||
void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const Projection &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {
|
||||
Transform cam_transform = p_cam_transform;
|
||||
|
||||
storage->info.render.object_count += p_cull_count;
|
||||
@ -3529,7 +3529,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
|
||||
float bias = 0;
|
||||
float normal_bias = 0;
|
||||
|
||||
CameraMatrix light_projection;
|
||||
Projection light_projection;
|
||||
Transform light_transform;
|
||||
|
||||
// TODO directional light
|
||||
|
@ -502,7 +502,7 @@ public:
|
||||
|
||||
struct LightInstance : public RID_Data {
|
||||
struct ShadowTransform {
|
||||
CameraMatrix camera;
|
||||
Projection camera;
|
||||
Transform transform;
|
||||
float farplane;
|
||||
float split;
|
||||
@ -541,7 +541,7 @@ public:
|
||||
|
||||
virtual RID light_instance_create(RID p_light);
|
||||
virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform);
|
||||
virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0);
|
||||
virtual void light_instance_set_shadow_transform(RID p_light_instance, const Projection &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0);
|
||||
virtual void light_instance_mark_visible(RID p_light_instance);
|
||||
virtual bool light_instances_can_render_shadow_cube() const { return storage->config.support_shadow_cubemaps; }
|
||||
|
||||
@ -729,7 +729,7 @@ public:
|
||||
void _fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_depth_pass, bool p_shadow_pass);
|
||||
void _render_render_list(RenderList::Element **p_elements, int p_element_count,
|
||||
const Transform &p_view_transform,
|
||||
const CameraMatrix &p_projection,
|
||||
const Projection &p_projection,
|
||||
const int p_eye,
|
||||
RID p_shadow_atlas,
|
||||
Environment *p_env,
|
||||
@ -740,7 +740,7 @@ public:
|
||||
bool p_alpha_pass,
|
||||
bool p_shadow);
|
||||
|
||||
void _draw_sky(RasterizerStorageGLES2::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation);
|
||||
void _draw_sky(RasterizerStorageGLES2::Sky *p_sky, const Projection &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy, const Basis &p_sky_orientation);
|
||||
|
||||
_FORCE_INLINE_ void _set_cull(bool p_front, bool p_disabled, bool p_reverse_cull);
|
||||
_FORCE_INLINE_ bool _setup_material(RasterizerStorageGLES2::Material *p_material, bool p_alpha_pass, Size2i p_skeleton_tex_size = Size2i(0, 0));
|
||||
@ -750,9 +750,9 @@ public:
|
||||
_FORCE_INLINE_ void _setup_refprobes(ReflectionProbeInstance *p_refprobe1, ReflectionProbeInstance *p_refprobe2, const Transform &p_view_transform, Environment *p_env);
|
||||
_FORCE_INLINE_ void _render_geometry(RenderList::Element *p_element);
|
||||
|
||||
void _post_process(Environment *env, const CameraMatrix &p_cam_projection);
|
||||
void _post_process(Environment *env, const Projection &p_cam_projection);
|
||||
|
||||
virtual void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
|
||||
virtual void render_scene(const Transform &p_cam_transform, const Projection &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
|
||||
virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count);
|
||||
virtual bool free(RID p_rid);
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
||||
|
||||
#include "core/hash_map.h"
|
||||
#include "core/map.h"
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/pair.h"
|
||||
#include "core/variant.h"
|
||||
#include "servers/visual/shader_language.h"
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/map.h"
|
||||
#include "core/math/basis.h"
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/math/geometry.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/math/plane.h"
|
||||
@ -656,7 +656,7 @@ void SpatialEditorViewport::_find_items_at_pos(const Point2 &p_pos, Vector<_RayR
|
||||
}
|
||||
|
||||
Vector3 SpatialEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) {
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
if (orthogonal) {
|
||||
cm.set_orthogonal(camera->get_size(), get_size().aspect(), get_znear() + p_vector3.z, get_zfar());
|
||||
} else {
|
||||
|
@ -357,7 +357,7 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2
|
||||
)
|
||||
|
||||
fd.write(
|
||||
"""_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const CameraMatrix& p_matrix) { _FU
|
||||
"""_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Projection& p_matrix) { _FU
|
||||
|
||||
GLfloat matrix[16];
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include "test_math.h"
|
||||
|
||||
#include "core/math/basis.h"
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/math/transform.h"
|
||||
#include "core/os/file_access.h"
|
||||
@ -356,7 +356,7 @@ public:
|
||||
};
|
||||
|
||||
void test_vec(Plane p_vec) {
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
cm.set_perspective(45, 1, 0, 100);
|
||||
Plane v0 = cm.xform4(p_vec);
|
||||
|
||||
|
@ -5225,7 +5225,7 @@ GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> state, Camera *p_ca
|
||||
Ref<GLTFCamera> c;
|
||||
c.instance();
|
||||
|
||||
if (p_camera->get_projection() == Camera::Projection::PROJECTION_PERSPECTIVE) {
|
||||
if (p_camera->get_projection() == Camera::PROJECTION_PERSPECTIVE) {
|
||||
c->set_perspective(true);
|
||||
c->set_fov_size(p_camera->get_fov());
|
||||
c->set_zfar(p_camera->get_zfar());
|
||||
|
@ -31,7 +31,7 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/math/aabb.h"
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/math/vector3.h"
|
||||
|
||||
#include "r128.h"
|
||||
@ -215,7 +215,7 @@ class Delaunay3D {
|
||||
return true;
|
||||
}
|
||||
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
|
||||
cm.matrix[0][0] = p_points[p_simplex.points[0]].x;
|
||||
cm.matrix[0][1] = p_points[p_simplex.points[1]].x;
|
||||
@ -240,7 +240,7 @@ class Delaunay3D {
|
||||
return ABS(camera_matrix_determinant(cm)) <= CMP_EPSILON;
|
||||
}
|
||||
|
||||
static float camera_matrix_determinant(const CameraMatrix &m) {
|
||||
static float camera_matrix_determinant(const Projection &m) {
|
||||
return m.matrix[0][3] * m.matrix[1][2] * m.matrix[2][1] * m.matrix[3][0] - m.matrix[0][2] * m.matrix[1][3] * m.matrix[2][1] * m.matrix[3][0] -
|
||||
m.matrix[0][3] * m.matrix[1][1] * m.matrix[2][2] * m.matrix[3][0] + m.matrix[0][1] * m.matrix[1][3] * m.matrix[2][2] * m.matrix[3][0] +
|
||||
m.matrix[0][2] * m.matrix[1][1] * m.matrix[2][3] * m.matrix[3][0] - m.matrix[0][1] * m.matrix[1][2] * m.matrix[2][3] * m.matrix[3][0] -
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#include "collision_object.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "scene/3d/spatial_velocity_tracker.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/resources/environment.h"
|
||||
@ -222,7 +222,7 @@ void Camera::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p
|
||||
update_gizmos();
|
||||
}
|
||||
|
||||
void Camera::set_projection(Camera::Projection p_mode) {
|
||||
void Camera::set_projection(Camera::ProjectionMode p_mode) {
|
||||
if (p_mode == PROJECTION_PERSPECTIVE || p_mode == PROJECTION_ORTHOGONAL || p_mode == PROJECTION_FRUSTUM) {
|
||||
mode = p_mode;
|
||||
_update_camera_mode();
|
||||
@ -292,7 +292,7 @@ Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const {
|
||||
if (mode == PROJECTION_ORTHOGONAL) {
|
||||
ray = Vector3(0, 0, -1);
|
||||
} else {
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
|
||||
Vector2 screen_he = cm.get_viewport_half_extents();
|
||||
ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_he.x, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_he.y, -near).normalized();
|
||||
@ -341,7 +341,7 @@ Vector<Vector3> Camera::get_near_plane_points() const {
|
||||
|
||||
Size2 viewport_size = get_viewport()->get_visible_rect().size;
|
||||
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
|
||||
if (mode == PROJECTION_ORTHOGONAL) {
|
||||
cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
|
||||
@ -365,7 +365,7 @@ Point2 Camera::unproject_position(const Vector3 &p_pos) const {
|
||||
|
||||
Size2 viewport_size = get_viewport()->get_visible_rect().size;
|
||||
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
|
||||
if (mode == PROJECTION_ORTHOGONAL) {
|
||||
cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
|
||||
@ -393,7 +393,7 @@ Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const {
|
||||
}
|
||||
Size2 viewport_size = get_viewport()->get_visible_rect().size;
|
||||
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
|
||||
if (mode == PROJECTION_ORTHOGONAL) {
|
||||
cm.set_orthogonal(size, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH);
|
||||
@ -567,7 +567,7 @@ float Camera::get_zfar() const {
|
||||
return far;
|
||||
}
|
||||
|
||||
Camera::Projection Camera::get_projection() const {
|
||||
Camera::ProjectionMode Camera::get_projection() const {
|
||||
return mode;
|
||||
}
|
||||
|
||||
@ -628,7 +628,7 @@ Vector<Plane> Camera::get_frustum() const {
|
||||
ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>());
|
||||
|
||||
Size2 viewport_size = get_viewport()->get_visible_rect().size;
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
if (mode == PROJECTION_PERSPECTIVE) {
|
||||
cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
|
||||
} else {
|
||||
|
@ -41,7 +41,7 @@ class Camera : public Spatial {
|
||||
GDCLASS(Camera, Spatial);
|
||||
|
||||
public:
|
||||
enum Projection {
|
||||
enum ProjectionMode {
|
||||
|
||||
PROJECTION_PERSPECTIVE,
|
||||
PROJECTION_ORTHOGONAL,
|
||||
@ -64,7 +64,7 @@ private:
|
||||
bool current;
|
||||
Viewport *viewport;
|
||||
|
||||
Projection mode;
|
||||
ProjectionMode mode;
|
||||
|
||||
float fov;
|
||||
float size;
|
||||
@ -112,7 +112,7 @@ public:
|
||||
void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far);
|
||||
void set_orthogonal(float p_size, float p_z_near, float p_z_far);
|
||||
void set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far);
|
||||
void set_projection(Camera::Projection p_mode);
|
||||
void set_projection(Camera::ProjectionMode p_mode);
|
||||
|
||||
void make_current();
|
||||
void clear_current(bool p_enable_next = true);
|
||||
@ -127,7 +127,7 @@ public:
|
||||
float get_znear() const;
|
||||
Vector2 get_frustum_offset() const;
|
||||
|
||||
Projection get_projection() const;
|
||||
ProjectionMode get_projection() const;
|
||||
|
||||
void set_fov(float p_fov);
|
||||
void set_size(float p_size);
|
||||
@ -175,7 +175,7 @@ public:
|
||||
~Camera();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(Camera::Projection);
|
||||
VARIANT_ENUM_CAST(Camera::ProjectionMode);
|
||||
VARIANT_ENUM_CAST(Camera::KeepAspect);
|
||||
VARIANT_ENUM_CAST(Camera::DopplerTracking);
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "world.h"
|
||||
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/math/octree.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "scene/3d/camera.h"
|
||||
|
@ -31,7 +31,7 @@
|
||||
/*************************************************************************/
|
||||
|
||||
class PortalRenderer;
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/math/geometry.h"
|
||||
#include "portal_types.h"
|
||||
|
||||
@ -77,7 +77,7 @@ class PortalOcclusionCuller {
|
||||
public:
|
||||
PortalOcclusionCuller();
|
||||
|
||||
void prepare_camera(const CameraMatrix &p_cam_matrix, const Vector3 &p_cam_dir) {
|
||||
void prepare_camera(const Projection &p_cam_matrix, const Vector3 &p_cam_dir) {
|
||||
_matrix_camera = p_cam_matrix;
|
||||
_pt_cam_dir = p_cam_dir;
|
||||
}
|
||||
@ -302,7 +302,7 @@ private:
|
||||
Vector3 _pt_camera;
|
||||
Vector3 _pt_cam_dir;
|
||||
|
||||
CameraMatrix _matrix_camera;
|
||||
Projection _matrix_camera;
|
||||
PortalRenderer *_portal_renderer = nullptr;
|
||||
|
||||
Clipper _clipper;
|
||||
|
@ -1118,7 +1118,7 @@ void PortalRenderer::rooms_update_gameplay_monitor(const Vector<Vector3> &p_came
|
||||
_gameplay_monitor.update_gameplay(*this, source_rooms, num_source_rooms);
|
||||
}
|
||||
|
||||
int PortalRenderer::cull_convex_implementation(const Vector3 &p_point, const Vector3 &p_cam_dir, const CameraMatrix &p_cam_matrix, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_result_max, uint32_t p_mask, int32_t &r_previous_room_id_hint) {
|
||||
int PortalRenderer::cull_convex_implementation(const Vector3 &p_point, const Vector3 &p_cam_dir, const Projection &p_cam_matrix, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_result_max, uint32_t p_mask, int32_t &r_previous_room_id_hint) {
|
||||
// start room
|
||||
int start_room_id = find_room_within(p_point, r_previous_room_id_hint);
|
||||
|
||||
@ -1132,7 +1132,7 @@ int PortalRenderer::cull_convex_implementation(const Vector3 &p_point, const Vec
|
||||
// set up the occlusion culler once off .. this is a prepare before the prepare is done PER room
|
||||
_tracer.get_occlusion_culler().prepare_camera(p_cam_matrix, p_cam_dir);
|
||||
|
||||
// planes must be in CameraMatrix order
|
||||
// planes must be in Projection order
|
||||
DEV_ASSERT(p_convex.size() == 6);
|
||||
|
||||
LocalVector<Plane> planes;
|
||||
|
@ -30,7 +30,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/math/geometry.h"
|
||||
#include "core/math/plane.h"
|
||||
#include "core/pooled_list.h"
|
||||
@ -197,11 +197,11 @@ public:
|
||||
Geometry::MeshData occlusion_debug_get_current_polys() const { return _tracer.get_occlusion_culler().debug_get_current_polys(); }
|
||||
|
||||
// note that this relies on a 'frustum' type cull, from a point, and that the planes are specified as in
|
||||
// CameraMatrix, i.e.
|
||||
// Projection, i.e.
|
||||
// order PLANE_NEAR,PLANE_FAR,PLANE_LEFT,PLANE_TOP,PLANE_RIGHT,PLANE_BOTTOM
|
||||
int cull_convex(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_result_max, uint32_t p_mask, int32_t &r_previous_room_id_hint) {
|
||||
int cull_convex(const Transform &p_cam_transform, const Projection &p_cam_projection, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_result_max, uint32_t p_mask, int32_t &r_previous_room_id_hint) {
|
||||
// combined camera matrix
|
||||
CameraMatrix cm = CameraMatrix(p_cam_transform.affine_inverse());
|
||||
Projection cm = Projection(p_cam_transform.affine_inverse());
|
||||
cm = p_cam_projection * cm;
|
||||
Vector3 point = p_cam_transform.origin;
|
||||
Vector3 cam_dir = -p_cam_transform.basis.get_axis(2).normalized();
|
||||
@ -213,20 +213,20 @@ public:
|
||||
return cull_convex_implementation(_override_camera_pos, cam_dir, cm, _override_camera_planes, p_result_array, p_result_max, p_mask, r_previous_room_id_hint);
|
||||
}
|
||||
|
||||
int cull_convex_implementation(const Vector3 &p_point, const Vector3 &p_cam_dir, const CameraMatrix &p_cam_matrix, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_result_max, uint32_t p_mask, int32_t &r_previous_room_id_hint);
|
||||
int cull_convex_implementation(const Vector3 &p_point, const Vector3 &p_cam_dir, const Projection &p_cam_matrix, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_result_max, uint32_t p_mask, int32_t &r_previous_room_id_hint);
|
||||
|
||||
bool occlusion_is_active() const { return _occluder_instance_pool.active_size() && use_occlusion_culling; }
|
||||
|
||||
// special function for occlusion culling only that does not use portals / rooms,
|
||||
// but allows using occluders with the main scene
|
||||
int occlusion_cull(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_num_results) {
|
||||
int occlusion_cull(const Transform &p_cam_transform, const Projection &p_cam_projection, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_num_results) {
|
||||
// inactive?
|
||||
if (!_occluder_instance_pool.active_size() || !use_occlusion_culling) {
|
||||
return p_num_results;
|
||||
}
|
||||
|
||||
// combined camera matrix
|
||||
CameraMatrix cm = CameraMatrix(p_cam_transform.affine_inverse());
|
||||
Projection cm = Projection(p_cam_transform.affine_inverse());
|
||||
cm = p_cam_projection * cm;
|
||||
Vector3 point = p_cam_transform.origin;
|
||||
Vector3 cam_dir = -p_cam_transform.basis.get_axis(2).normalized();
|
||||
|
@ -532,7 +532,7 @@ void PortalTracer::trace_recursive(const TraceParams &p_params, int p_depth, int
|
||||
} // for p through portals
|
||||
}
|
||||
|
||||
int PortalTracer::occlusion_cull(PortalRenderer &p_portal_renderer, const Vector3 &p_point, const Vector3 &p_cam_dir, const CameraMatrix &p_cam_matrix, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_num_results) {
|
||||
int PortalTracer::occlusion_cull(PortalRenderer &p_portal_renderer, const Vector3 &p_point, const Vector3 &p_cam_dir, const Projection &p_cam_matrix, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_num_results) {
|
||||
_occlusion_culler.prepare_camera(p_cam_matrix, p_cam_dir);
|
||||
|
||||
// silly conversion of vector to local vector
|
||||
|
@ -40,7 +40,7 @@
|
||||
//#define PORTAL_RENDERER_STORE_MOVING_RIDS
|
||||
#endif
|
||||
|
||||
struct CameraMatrix;
|
||||
struct Projection;
|
||||
class PortalRenderer;
|
||||
struct VSRoom;
|
||||
|
||||
@ -113,7 +113,7 @@ public:
|
||||
|
||||
// special function for occlusion culling only that does not use portals / rooms,
|
||||
// but allows using occluders with the main scene
|
||||
int occlusion_cull(PortalRenderer &p_portal_renderer, const Vector3 &p_point, const Vector3 &p_cam_dir, const CameraMatrix &p_cam_matrix, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_num_results);
|
||||
int occlusion_cull(PortalRenderer &p_portal_renderer, const Vector3 &p_point, const Vector3 &p_cam_dir, const Projection &p_cam_matrix, const Vector<Plane> &p_convex, VSInstance **p_result_array, int p_num_results);
|
||||
|
||||
PortalOcclusionCuller &get_occlusion_culler() { return _occlusion_culler; }
|
||||
const PortalOcclusionCuller &get_occlusion_culler() const { return _occlusion_culler; }
|
||||
|
@ -30,7 +30,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "core/math/camera_matrix.h"
|
||||
#include "core/math/projection.h"
|
||||
#include "core/math/transform_interpolator.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
@ -154,7 +154,7 @@ public:
|
||||
|
||||
virtual RID light_instance_create(RID p_light) = 0;
|
||||
virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) = 0;
|
||||
virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0) = 0;
|
||||
virtual void light_instance_set_shadow_transform(RID p_light_instance, const Projection &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0) = 0;
|
||||
virtual void light_instance_mark_visible(RID p_light_instance) = 0;
|
||||
virtual bool light_instances_can_render_shadow_cube() const { return true; }
|
||||
|
||||
@ -170,7 +170,7 @@ public:
|
||||
virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) = 0;
|
||||
virtual bool reflection_probe_instance_postprocess_step(RID p_instance) = 0;
|
||||
|
||||
virtual void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) = 0;
|
||||
virtual void render_scene(const Transform &p_cam_transform, const Projection &p_cam_projection, const int p_eye, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) = 0;
|
||||
virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) = 0;
|
||||
|
||||
virtual void set_scene_pass(uint64_t p_pass) = 0;
|
||||
@ -616,7 +616,7 @@ public:
|
||||
Rect2 rect_cache;
|
||||
Transform2D xform_cache;
|
||||
float radius_cache; //used for shadow far plane
|
||||
CameraMatrix shadow_matrix_cache;
|
||||
Projection shadow_matrix_cache;
|
||||
|
||||
Transform2D light_shader_xform;
|
||||
Vector2 light_shader_pos;
|
||||
@ -1094,7 +1094,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) = 0;
|
||||
virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, Projection *p_xform_cache) = 0;
|
||||
|
||||
virtual void reset_canvas() = 0;
|
||||
|
||||
|
@ -1701,11 +1701,11 @@ Vector<ObjectID> VisualServerScene::instances_cull_convex(const Vector<Plane> &p
|
||||
}
|
||||
|
||||
// thin wrapper to allow rooms / portals to take over culling if active
|
||||
int VisualServerScene::_cull_convex_from_point(Scenario *p_scenario, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const Vector<Plane> &p_convex, Instance **p_result_array, int p_result_max, int32_t &r_previous_room_id_hint, uint32_t p_mask) {
|
||||
int VisualServerScene::_cull_convex_from_point(Scenario *p_scenario, const Transform &p_cam_transform, const Projection &p_cam_projection, const Vector<Plane> &p_convex, Instance **p_result_array, int p_result_max, int32_t &r_previous_room_id_hint, uint32_t p_mask) {
|
||||
int res = -1;
|
||||
if (p_scenario->_portal_renderer.is_active()) {
|
||||
// Note that the portal renderer ASSUMES that the planes exactly match the convention in
|
||||
// CameraMatrix of enum Planes (6 planes, in order, near, far etc)
|
||||
// Projection of enum Planes (6 planes, in order, near, far etc)
|
||||
// If this is not the case, it should not be used.
|
||||
res = p_scenario->_portal_renderer.cull_convex(p_cam_transform, p_cam_projection, p_convex, (VSInstance **)p_result_array, p_result_max, p_mask, r_previous_room_id_hint);
|
||||
}
|
||||
@ -2058,7 +2058,7 @@ void VisualServerScene::_update_dirty_instance(Instance *p_instance) {
|
||||
p_instance->update_materials = false;
|
||||
}
|
||||
|
||||
bool VisualServerScene::_light_instance_update_shadow(Instance *p_instance, const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_shadow_atlas, Scenario *p_scenario) {
|
||||
bool VisualServerScene::_light_instance_update_shadow(Instance *p_instance, const Transform p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, RID p_shadow_atlas, Scenario *p_scenario) {
|
||||
InstanceLightData *light = static_cast<InstanceLightData *>(p_instance->base_data);
|
||||
|
||||
Transform light_transform = p_instance->transform;
|
||||
@ -2151,7 +2151,7 @@ bool VisualServerScene::_light_instance_update_shadow(Instance *p_instance, cons
|
||||
|
||||
for (int i = 0; i < splits; i++) {
|
||||
// setup a camera matrix for that range!
|
||||
CameraMatrix camera_matrix;
|
||||
Projection camera_matrix;
|
||||
|
||||
float aspect = p_cam_projection.get_aspect();
|
||||
|
||||
@ -2310,7 +2310,7 @@ bool VisualServerScene::_light_instance_update_shadow(Instance *p_instance, cons
|
||||
}
|
||||
|
||||
{
|
||||
CameraMatrix ortho_camera;
|
||||
Projection ortho_camera;
|
||||
real_t half_x = (x_max_cam - x_min_cam) * 0.5;
|
||||
real_t half_y = (y_max_cam - y_min_cam) * 0.5;
|
||||
|
||||
@ -2365,13 +2365,13 @@ bool VisualServerScene::_light_instance_update_shadow(Instance *p_instance, cons
|
||||
}
|
||||
}
|
||||
|
||||
VSG::scene_render->light_instance_set_shadow_transform(light->instance, CameraMatrix(), light_transform, radius, 0, i);
|
||||
VSG::scene_render->light_instance_set_shadow_transform(light->instance, Projection(), light_transform, radius, 0, i);
|
||||
VSG::scene_render->render_shadow(light->instance, p_shadow_atlas, i, (RasterizerScene::InstanceBase **)instance_shadow_cull_result, cull_count);
|
||||
}
|
||||
} else { //shadow cube
|
||||
|
||||
float radius = VSG::storage->light_get_param(p_instance->base, VS::LIGHT_PARAM_RANGE);
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
cm.set_perspective(90, 1, 0.01, radius);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
@ -2421,7 +2421,7 @@ bool VisualServerScene::_light_instance_update_shadow(Instance *p_instance, cons
|
||||
}
|
||||
|
||||
//restore the regular DP matrix
|
||||
VSG::scene_render->light_instance_set_shadow_transform(light->instance, CameraMatrix(), light_transform, radius, 0, 0);
|
||||
VSG::scene_render->light_instance_set_shadow_transform(light->instance, Projection(), light_transform, radius, 0, 0);
|
||||
}
|
||||
|
||||
} break;
|
||||
@ -2429,7 +2429,7 @@ bool VisualServerScene::_light_instance_update_shadow(Instance *p_instance, cons
|
||||
float radius = VSG::storage->light_get_param(p_instance->base, VS::LIGHT_PARAM_RANGE);
|
||||
float angle = VSG::storage->light_get_param(p_instance->base, VS::LIGHT_PARAM_SPOT_ANGLE);
|
||||
|
||||
CameraMatrix cm;
|
||||
Projection cm;
|
||||
cm.set_perspective(angle * 2.0, 1.0, 0.01, radius);
|
||||
|
||||
Vector<Plane> planes = cm.get_projection_planes(light_transform);
|
||||
@ -2468,7 +2468,7 @@ void VisualServerScene::render_camera(RID p_camera, RID p_scenario, Size2 p_view
|
||||
ERR_FAIL_COND(!camera);
|
||||
|
||||
/* STEP 1 - SETUP CAMERA */
|
||||
CameraMatrix camera_matrix;
|
||||
Projection camera_matrix;
|
||||
bool ortho = false;
|
||||
|
||||
switch (camera->type) {
|
||||
@ -2511,7 +2511,7 @@ void VisualServerScene::render_camera(RID p_camera, RID p_scenario, Size2 p_view
|
||||
#endif
|
||||
}
|
||||
|
||||
void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_force_environment, uint32_t p_visible_layers, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int32_t &r_previous_room_id_hint) {
|
||||
void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, RID p_force_environment, uint32_t p_visible_layers, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int32_t &r_previous_room_id_hint) {
|
||||
// Note, in stereo rendering:
|
||||
// - p_cam_transform will be a transform in the middle of our two eyes
|
||||
// - p_cam_projection is a wider frustrum that encompasses both eyes
|
||||
@ -2800,7 +2800,7 @@ void VisualServerScene::_prepare_scene(const Transform p_cam_transform, const Ca
|
||||
}
|
||||
}
|
||||
|
||||
void VisualServerScene::_render_scene(const Transform p_cam_transform, const CameraMatrix &p_cam_projection, const int p_eye, bool p_cam_orthogonal, RID p_force_environment, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {
|
||||
void VisualServerScene::_render_scene(const Transform p_cam_transform, const Projection &p_cam_projection, const int p_eye, bool p_cam_orthogonal, RID p_force_environment, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {
|
||||
Scenario *scenario = scenario_owner.getornull(p_scenario);
|
||||
|
||||
/* ENVIRONMENT */
|
||||
@ -2830,7 +2830,7 @@ void VisualServerScene::render_empty_scene(RID p_scenario, RID p_shadow_atlas) {
|
||||
} else {
|
||||
environment = scenario->fallback_environment;
|
||||
}
|
||||
VSG::scene_render->render_scene(Transform(), CameraMatrix(), 0, true, nullptr, 0, nullptr, 0, nullptr, 0, environment, p_shadow_atlas, scenario->reflection_atlas, RID(), 0);
|
||||
VSG::scene_render->render_scene(Transform(), Projection(), 0, true, nullptr, 0, nullptr, 0, nullptr, 0, environment, p_shadow_atlas, scenario->reflection_atlas, RID(), 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -687,7 +687,7 @@ public:
|
||||
virtual Vector<ObjectID> instances_cull_convex(const Vector<Plane> &p_convex, RID p_scenario = RID()) const;
|
||||
|
||||
// internal (uses portals when available)
|
||||
int _cull_convex_from_point(Scenario *p_scenario, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, const Vector<Plane> &p_convex, Instance **p_result_array, int p_result_max, int32_t &r_previous_room_id_hint, uint32_t p_mask = 0xFFFFFFFF);
|
||||
int _cull_convex_from_point(Scenario *p_scenario, const Transform &p_cam_transform, const Projection &p_cam_projection, const Vector<Plane> &p_convex, Instance **p_result_array, int p_result_max, int32_t &r_previous_room_id_hint, uint32_t p_mask = 0xFFFFFFFF);
|
||||
void _rooms_instance_update(Instance *p_instance, const AABB &p_aabb);
|
||||
|
||||
virtual void instance_geometry_set_flag(RID p_instance, VS::InstanceFlags p_flags, bool p_enabled);
|
||||
@ -702,10 +702,10 @@ public:
|
||||
_FORCE_INLINE_ void _update_instance_aabb(Instance *p_instance);
|
||||
_FORCE_INLINE_ void _update_dirty_instance(Instance *p_instance);
|
||||
|
||||
_FORCE_INLINE_ bool _light_instance_update_shadow(Instance *p_instance, const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_shadow_atlas, Scenario *p_scenario);
|
||||
_FORCE_INLINE_ bool _light_instance_update_shadow(Instance *p_instance, const Transform p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, RID p_shadow_atlas, Scenario *p_scenario);
|
||||
|
||||
void _prepare_scene(const Transform p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, RID p_force_environment, uint32_t p_visible_layers, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int32_t &r_previous_room_id_hint);
|
||||
void _render_scene(const Transform p_cam_transform, const CameraMatrix &p_cam_projection, const int p_eye, bool p_cam_orthogonal, RID p_force_environment, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
|
||||
void _prepare_scene(const Transform p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, RID p_force_environment, uint32_t p_visible_layers, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int32_t &r_previous_room_id_hint);
|
||||
void _render_scene(const Transform p_cam_transform, const Projection &p_cam_projection, const int p_eye, bool p_cam_orthogonal, RID p_force_environment, RID p_scenario, RID p_shadow_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
|
||||
void render_empty_scene(RID p_scenario, RID p_shadow_atlas);
|
||||
|
||||
void render_camera(RID p_camera, RID p_scenario, Size2 p_viewport_size, RID p_shadow_atlas);
|
||||
|
Loading…
Reference in New Issue
Block a user