Skip to content

Commit 3183f4b

Browse files
luxiaodongkwbm
authored andcommitted
修复直接光照下阴影显示不全
1 parent a2a01cc commit 3183f4b

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

engine/source/runtime/core/math/math.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace Piccolo
163163
float C = -(right + left) * inv_width;
164164
float D = -(top + bottom) * inv_height;
165165
float q = -2 * inv_distance;
166-
float qn = qn = -(zfar + znear) * inv_distance;
166+
float qn = -(zfar + znear) * inv_distance;
167167

168168
// NB: This creates 'uniform' orthographic projection matrix,
169169
// which depth range [-1,1], right-handed rules
@@ -192,4 +192,45 @@ namespace Piccolo
192192
return proj_matrix;
193193
}
194194

195+
Matrix4x4
196+
Math::makeOrthographicProjectionMatrix01(float left, float right, float bottom, float top, float znear, float zfar)
197+
{
198+
float inv_width = 1.0f / (right - left);
199+
float inv_height = 1.0f / (top - bottom);
200+
float inv_distance = 1.0f / (zfar - znear);
201+
202+
float A = 2 * inv_width;
203+
float B = 2 * inv_height;
204+
float C = -(right + left) * inv_width;
205+
float D = -(top + bottom) * inv_height;
206+
float q = -1 * inv_distance;
207+
float qn = -znear * inv_distance;
208+
209+
// NB: This creates 'uniform' orthographic projection matrix,
210+
// which depth range [-1,1], right-handed rules
211+
//
212+
// [ A 0 0 C ]
213+
// [ 0 B 0 D ]
214+
// [ 0 0 q qn ]
215+
// [ 0 0 0 1 ]
216+
//
217+
// A = 2 * / (right - left)
218+
// B = 2 * / (top - bottom)
219+
// C = - (right + left) / (right - left)
220+
// D = - (top + bottom) / (top - bottom)
221+
// q = - 1 / (far - near)
222+
// qn = - near / (far - near)
223+
224+
Matrix4x4 proj_matrix = Matrix4x4::ZERO;
225+
proj_matrix[0][0] = A;
226+
proj_matrix[0][3] = C;
227+
proj_matrix[1][1] = B;
228+
proj_matrix[1][3] = D;
229+
proj_matrix[2][2] = q;
230+
proj_matrix[2][3] = qn;
231+
proj_matrix[3][3] = 1;
232+
233+
return proj_matrix;
234+
}
235+
195236
} // namespace Piccolo

engine/source/runtime/core/math/math.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ namespace Piccolo
265265

266266
static Matrix4x4
267267
makeOrthographicProjectionMatrix(float left, float right, float bottom, float top, float znear, float zfar);
268+
269+
static Matrix4x4
270+
makeOrthographicProjectionMatrix01(float left, float right, float bottom, float top, float znear, float zfar);
268271
};
269272

270273
// these functions could not be defined within the class definition of class

engine/source/runtime/function/render/passes/directional_light_pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ namespace Piccolo
527527
}
528528

529529
// Mesh
530-
if (m_vulkan_rhi->isPointLightShadowEnabled())
530+
// if (m_vulkan_rhi->isPointLightShadowEnabled())
531531
{
532532
if (m_vulkan_rhi->isDebugLabelEnabled())
533533
{

engine/source/runtime/function/render/render_helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ namespace Piccolo
334334

335335
BoundingBox frustum_bounding_box_light_view = BoundingBoxTransform(frustum_bounding_box, light_view);
336336
BoundingBox scene_bounding_box_light_view = BoundingBoxTransform(scene_bounding_box, light_view);
337-
light_proj = Math::makeOrthographicProjectionMatrix(
337+
light_proj = Math::makeOrthographicProjectionMatrix01(
338338
std::max(frustum_bounding_box_light_view.min_bound.x, scene_bounding_box_light_view.min_bound.x),
339339
std::min(frustum_bounding_box_light_view.max_bound.x, scene_bounding_box_light_view.max_bound.x),
340340
std::max(frustum_bounding_box_light_view.min_bound.y, scene_bounding_box_light_view.min_bound.y),

0 commit comments

Comments
 (0)