1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Several fixes to directional shadows, closes #10926

Added option to change directional light range mode, between optimized and stable. For Orthogonal, you might need to use optimized.
This commit is contained in:
Juan Linietsky
2017-09-07 18:00:47 -03:00
parent 1eeda0f32f
commit eedb39091a
13 changed files with 1044 additions and 962 deletions

View File

@@ -265,76 +265,28 @@ void CameraMatrix::get_viewport_size(real_t &r_width, real_t &r_height) const {
bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const {
const real_t *matrix = (const real_t *)this->matrix;
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},
};
///////--- 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();
for(int i=0;i<8;i++) {
///////--- Far Plane ---///////
Plane far_plane = Plane(matrix[2] - matrix[3],
matrix[6] - matrix[7],
matrix[10] - matrix[11],
matrix[15] - matrix[14]);
far_plane.normalize();
///////--- Right Plane ---///////
Plane right_plane = Plane(matrix[0] - matrix[3],
matrix[4] - matrix[7],
matrix[8] - matrix[11],
-matrix[15] + matrix[12]);
right_plane.normalize();
///////--- Top Plane ---///////
Plane top_plane = Plane(matrix[1] - matrix[3],
matrix[5] - matrix[7],
matrix[9] - matrix[11],
-matrix[15] + matrix[13]);
top_plane.normalize();
Vector3 near_endpoint_left, near_endpoint_right;
Vector3 far_endpoint_left, far_endpoint_right;
bool res = near_plane.intersect_3(right_plane, top_plane, &near_endpoint_right);
ERR_FAIL_COND_V(!res, false);
res = far_plane.intersect_3(right_plane, top_plane, &far_endpoint_right);
ERR_FAIL_COND_V(!res, false);
if ((matrix[8] == 0) && (matrix[9] == 0)) {
near_endpoint_left = near_endpoint_right;
near_endpoint_left.x = -near_endpoint_left.x;
far_endpoint_left = far_endpoint_right;
far_endpoint_left.x = -far_endpoint_left.x;
} else {
///////--- Left Plane ---///////
Plane left_plane = Plane(matrix[0] + matrix[3],
matrix[4] + matrix[7],
matrix[8] + matrix[11],
-matrix[15] - matrix[12]);
left_plane.normalize();
res = near_plane.intersect_3(left_plane, top_plane, &near_endpoint_left);
ERR_FAIL_COND_V(!res, false);
res = far_plane.intersect_3(left_plane, top_plane, &far_endpoint_left);
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);
}
p_8points[0] = p_transform.xform(Vector3(near_endpoint_right.x, near_endpoint_right.y, near_endpoint_right.z));
p_8points[1] = p_transform.xform(Vector3(near_endpoint_right.x, -near_endpoint_right.y, near_endpoint_right.z));
p_8points[2] = p_transform.xform(Vector3(near_endpoint_left.x, near_endpoint_left.y, near_endpoint_left.z));
p_8points[3] = p_transform.xform(Vector3(near_endpoint_left.x, -near_endpoint_left.y, near_endpoint_left.z));
p_8points[4] = p_transform.xform(Vector3(far_endpoint_right.x, far_endpoint_right.y, far_endpoint_right.z));
p_8points[5] = p_transform.xform(Vector3(far_endpoint_right.x, -far_endpoint_right.y, far_endpoint_right.z));
p_8points[6] = p_transform.xform(Vector3(far_endpoint_left.x, far_endpoint_left.y, far_endpoint_left.z));
p_8points[7] = p_transform.xform(Vector3(far_endpoint_left.x, -far_endpoint_left.y, far_endpoint_left.z));
return true;
}
Vector<Plane> CameraMatrix::get_projection_planes(const Transform &p_transform) const {
@@ -610,6 +562,12 @@ int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
return int((result.x * 0.5 + 0.5) * 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;