Environment settings become scene entities (UE Skybox/SkyLight semantics)
Skybox/SkyLight are now Actor-carried components instead of resident global settings, matching UE where SkyAtmosphere/SkyLight/fog are Actors added from Place Actors and configured in Details. - New SkyboxComponent (active + envPath asset slot) and SkyLightComponent (active + ambientColor); first-active entity wins per frame - SceneRenderer collects env from components into FrameSceneData (DrawSkybox/envPath/ambient); Renderer performs delta sync - env reloads only when the resolved path changes, neutral fallback when empty or unloadable - App-side env plumbing removed: kEnvPaths table and getEnvIndex/ setEnvIndex callbacks deleted; StatsPanel keeps ClearColor + debug view, env params move to Details - Serializer: scene-level Settings stores ClearColor only; env components serialize per entity; legacy v1 scenes (Environment header + Settings.AmbientColor/DrawSkybox) auto-migrate into an Environment entity on load for visual parity - Inspector: Skybox/Sky Light sections with .hdr asset slot dropdown and Add Component entries; Outliner "+ Create" popup offers Empty/Light/Camera/Environment
This commit is contained in:
@@ -601,6 +601,31 @@ namespace Engine
|
||||
}
|
||||
const FrameSceneData& frame = m_SceneRenderer->Frame();
|
||||
|
||||
// 1.5 环境差量同步(UE 语义:环境是场景组件数据,渲染器被动跟随)。
|
||||
// 帧数据 envPath 与当前已绑定环境做比较,路径变化才重载/重绑
|
||||
//(LoadEnvironment 缓存命中零开销;失效路径一次失败即记,
|
||||
// 不逐帧重试,路径改回时自然恢复)
|
||||
if (frame.envPath != m_ActiveEnvPath)
|
||||
{
|
||||
m_ActiveEnvPath = frame.envPath;
|
||||
if (m_ActiveEnvPath.empty())
|
||||
{
|
||||
SetEnvironment(nullptr); // 回中性兜底
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto ref = assets.LoadEnvironment(m_ActiveEnvPath);
|
||||
SetEnvironment(ref.Valid() ? assets.GetEnvironment(ref)
|
||||
: nullptr);
|
||||
if (!ref.Valid())
|
||||
{
|
||||
ENGINE_WARN("Renderer: env '{}' failed to load, "
|
||||
"neutral fallback active",
|
||||
m_ActiveEnvPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 等本槽位 fence → 写 UBO/SSBO → reset(写-读竞争关闭)
|
||||
m_SyncManager->WaitFence(frameSlot);
|
||||
ReadGpuTimes(frameSlot); // fence 已等:上一轮该槽位的查询已就绪
|
||||
|
||||
@@ -312,11 +312,35 @@ namespace Engine
|
||||
ubo.proj[2][1] += jy * 2.0f / static_cast<f32>(targetExtent.height);
|
||||
}
|
||||
|
||||
ubo.ambientColor = scene.GetSettings().AmbientColor;
|
||||
// ---- 环境组件落帧(UE SkyLight/Skybox Actor 语义):场景环境
|
||||
// 是实体组件而非全局设置。多实例取第一个 active(entt
|
||||
// 视图序 = 组件创建序,首个命中稳定);无组件场景兜底 =
|
||||
// 无天空 + 旧 Settings 默认环境光(空场景清屏可渲染)----
|
||||
m_Frame.DrawSkybox = false;
|
||||
m_Frame.envPath.clear();
|
||||
ubo.ambientColor = glm::vec4{0.07f, 0.07f, 0.09f, 0.0f};
|
||||
for (auto&& [e, sb] :
|
||||
scene.GetRegistry().view<ECS::SkyboxComponent>().each())
|
||||
{
|
||||
if (sb.active)
|
||||
{
|
||||
m_Frame.DrawSkybox = true;
|
||||
m_Frame.envPath = sb.envPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (auto&& [e, sl] :
|
||||
scene.GetRegistry().view<ECS::SkyLightComponent>().each())
|
||||
{
|
||||
if (sl.active)
|
||||
{
|
||||
ubo.ambientColor = sl.ambientColor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 运行时开关/调试视图落帧(各 pass 与 frag 只读契约字段)----
|
||||
m_Frame.ClearColor = scene.GetSettings().ClearColor;
|
||||
m_Frame.DrawSkybox = scene.GetSettings().DrawSkybox;
|
||||
m_Frame.shadowsEnabled = m_ShadowsEnabled;
|
||||
m_Frame.taaEnabled = m_TAAEnabled;
|
||||
m_Frame.bloomEnabled = m_BloomEnabled;
|
||||
|
||||
Reference in New Issue
Block a user