refactor: Transform 字段封装 + dirty 标记(对齐 UE USceneComponent 真实现)
- 修正上一版"全量暴力重算":UE 实为 dirty 标记 + 惰性计算,前提是 字段私有(SetRelativeLocation 等 setter 标脏 + 子级传播) - TransformComponent:SRT 字段私有化,Set/Get/World()/IsDirty 访问器; Set* 变更才标脏;AddRotationY 便捷接口 - Scene::UpdateTransforms 只重算脏实体——静止实体零成本; 层级(父子)传播在脏标记基础上扩展 - 迁移 Camera/SceneRenderer/main.cpp 到封装 API
This commit is contained in:
@@ -185,7 +185,7 @@ namespace Engine
|
||||
ubo.lights[i].color = glm::vec4(0.0f);
|
||||
}
|
||||
ComputeCascades(shadowDir);
|
||||
ubo.cameraPos = glm::vec4(camTransform->position, 1.0f);
|
||||
ubo.cameraPos = glm::vec4(camTransform->GetPosition(), 1.0f);
|
||||
|
||||
// ---- 3. GPUDriven:单趟收集 + 多视图剔除 ----
|
||||
// 每个实例的包围球对 4 个视锥分别测试:
|
||||
@@ -218,22 +218,22 @@ namespace Engine
|
||||
// TAA velocity:本实例的上一帧世界矩阵(首帧/新实体 = 当前
|
||||
// 矩阵 → 速度为 0,不产生假运动)
|
||||
const u32 entKey = static_cast<u32>(entt::to_integral(entity));
|
||||
glm::mat4 prevWorld = t.world;
|
||||
glm::mat4 prevWorld = t.World();
|
||||
if (auto it = m_PrevWorlds.find(entKey); it != m_PrevWorlds.end()) {
|
||||
prevWorld = it->second;
|
||||
}
|
||||
m_CurWorlds.emplace(entKey, t.world);
|
||||
m_CurWorlds.emplace(entKey, t.World());
|
||||
|
||||
// 实例世界缩放(矩阵列向量最大长度,包围球半径随缩放)
|
||||
const f32 worldScale = glm::max(
|
||||
glm::length(glm::vec3(t.world[0])),
|
||||
glm::max(glm::length(glm::vec3(t.world[1])),
|
||||
glm::length(glm::vec3(t.world[2]))));
|
||||
glm::length(glm::vec3(t.World()[0])),
|
||||
glm::max(glm::length(glm::vec3(t.World()[1])),
|
||||
glm::length(glm::vec3(t.World()[2]))));
|
||||
|
||||
for (auto& mesh : model->GetMeshes()) {
|
||||
const auto& bounds = mesh->GetBounds();
|
||||
const glm::vec3 worldCenter =
|
||||
glm::vec3(t.world * glm::vec4(bounds.center, 1.0f));
|
||||
glm::vec3(t.World() * glm::vec4(bounds.center, 1.0f));
|
||||
const f32 worldRadius = bounds.radius * worldScale;
|
||||
|
||||
auto tryAppend = [&](ViewScratch& s, const Frustum& frustum) {
|
||||
@@ -252,7 +252,7 @@ namespace Engine
|
||||
}
|
||||
s.result.batches[it->second].count++;
|
||||
s.result.instanceCount++;
|
||||
s.worlds.push_back(t.world);
|
||||
s.worlds.push_back(t.World());
|
||||
s.prevWorlds.push_back(prevWorld);
|
||||
++totalInstances;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user