fix: 阴影光源错误绑定 FillLight + 截图 usage 警告 + nodiscard
- LightComponent 增加 castShadow 标志;灯收集排序键改为 castShadow 方向光 > 方向光 > 点光(此前稳定排序把收集序靠前的 FillLight 排到 lights[0],KeyLight 方向滑条自然不影响阴影) - TextureDesc 增加 extraUsage:HDRColor 声明 TRANSFER_SRC, 消除截图 copy 的 3 条 usage 不匹配运行时警告 - waitForFences nodiscard 返回值显式丢弃,消除编译警告
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
|
||||
namespace Engine
|
||||
{
|
||||
@@ -180,6 +179,7 @@ namespace Engine
|
||||
// 先收集到临时数组,方向光排前,再写入 UBO
|
||||
glm::vec3 shadowDir{0.0f, -1.0f, 0.0f}; // 无灯兜底:头顶正射
|
||||
LightData collected[kMaxLights];
|
||||
f32 shadowKey[kMaxLights]; // 排序键:0=castShadow 方向光 1=方向光 2=点光
|
||||
u32 collectedCount = 0;
|
||||
scene.Each<TransformComponent, LightComponent>(
|
||||
[&](Entity, TransformComponent& t, LightComponent& light) {
|
||||
@@ -190,6 +190,12 @@ namespace Engine
|
||||
dst.params = glm::vec4(
|
||||
light.type == LightComponent::Type::Point ? 1.0f : 0.0f,
|
||||
light.radius, 0.0f, 0.0f);
|
||||
// 排序键:castShadow 方向光最优先(CSM 阴影光源契约),其余按类型
|
||||
shadowKey[collectedCount - 1] =
|
||||
(light.type == LightComponent::Type::Directional &&
|
||||
light.castShadow) ? 0.0f
|
||||
: (light.type == LightComponent::Type::Directional ? 1.0f
|
||||
: 2.0f);
|
||||
|
||||
if (light.type == LightComponent::Type::Point) {
|
||||
dst.position = glm::vec4(t.GetPosition(), 1.0f);
|
||||
@@ -202,11 +208,20 @@ namespace Engine
|
||||
}
|
||||
});
|
||||
|
||||
// 方向光排前(稳定排序:同类保持收集序)→ lights[0] = CSM 光源
|
||||
std::stable_sort(collected, collected + collectedCount,
|
||||
[](const LightData& a, const LightData& b) {
|
||||
return a.params.x < b.params.x; // 0=方向光 < 1=点光
|
||||
});
|
||||
// 排序(稳定):castShadow 方向光 → 方向光 → 点光
|
||||
// 同时排序 shadowKey 保持键值对应
|
||||
for (u32 i = 1; i < collectedCount; ++i) { // 插入排序(n≤4)
|
||||
LightData ld = collected[i];
|
||||
f32 key = shadowKey[i];
|
||||
u32 j = i;
|
||||
while (j > 0 && shadowKey[j - 1] > key) {
|
||||
collected[j] = collected[j - 1];
|
||||
shadowKey[j] = shadowKey[j - 1];
|
||||
--j;
|
||||
}
|
||||
collected[j] = ld;
|
||||
shadowKey[j] = key;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < kMaxLights; ++i) {
|
||||
if (i < collectedCount) {
|
||||
|
||||
Reference in New Issue
Block a user